Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何在网格单元格中插入按钮?_Delphi_Firemonkey_Delphi Xe6 - Fatal编程技术网

Delphi 如何在网格单元格中插入按钮?

Delphi 如何在网格单元格中插入按钮?,delphi,firemonkey,delphi-xe6,Delphi,Firemonkey,Delphi Xe6,如果您希望单元格显示按钮,则以下内容在Delphi XE5中适用。 然而,在DelphiXe6中,它不是 Type TSimpleLinkCell = class(TTextCell) protected FButton: TSpeedButton; procedure ButtonClick(Sender: TObject); public constructor Create(AOwner: TComponent); r

如果您希望单元格显示按钮,则以下内容在Delphi XE5中适用。 然而,在DelphiXe6中,它不是

Type
    TSimpleLinkCell = class(TTextCell)
    protected
        FButton: TSpeedButton;
        procedure ButtonClick(Sender: TObject);
    public
        constructor Create(AOwner: TComponent); reintroduce;
    end;

constructor TSimpleLinkCell.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    Self.TextAlign := TTextAlign.taLeading;
    FButton := TSpeedButton.Create(Self);
    FButton.Parent := Self;
    FButton.Height := 16;
    FButton.Width := 16;
    FButton.Align := TAlignLayout.alRight;
    FButton.OnClick := ButtonClick;
end;
如何在Delphi XE6中实现上述功能

  • 您的SpeedButton没有文本,因此在您用鼠标进入按钮之前不会显示任何内容
  • 如果将此对象插入到网格中的TColumn类型设置为,它将正常工作。下面是代码的完整工作示例(在XE4上测试):


  • 我已经测试了你的答案,它是有效的。你能说这是正确的回答吗?请
    unit Unit5;
    
    interface
    
    uses
      System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
      System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
      FMX.StdCtrls, FMX.Layouts, FMX.Grid;
    
    type
      TSimpleLinkCell = class(TTextCell)
      protected
          FButton: TSpeedButton;
          procedure ButtonClick(Sender: TObject);
       public
          constructor Create(AOwner: TComponent); reintroduce;
      end;
    
      TButtonColumn=class(TColumn)
      protected
        function CreateCellControl: TStyledControl;override;
      end;
    
      TForm5 = class(TForm)
        Grid1: TGrid;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form5: TForm5;
    
    implementation
    {$R *.fmx}
    
    constructor TSimpleLinkCell.Create(AOwner: TComponent);
    begin
        inherited Create(AOwner);
        Self.TextAlign := TTextAlign.taLeading;
        FButton := TSpeedButton.Create(Self);
        FButton.Parent := Self;
        FButton.Height := 16;
        FButton.Width := 16;
        FButton.Align := TAlignLayout.alRight;
        FButton.OnClick := ButtonClick;
    //    FButton.Text:='Button';
    end;
    
    procedure TSimpleLinkCell.ButtonClick(Sender: TObject);
    begin
      ShowMessage('The button is clicked!');
    end;
    
    function TButtonColumn.CreateCellControl: TStyledControl;
    var
      cell:TSimpleLinkCell;
    begin
      cell:=TSimpleLinkCell.Create(Self);
      Result:=cell;
    end;
    
    procedure TForm5.FormCreate(Sender: TObject);
    begin
      Grid1.AddObject(TButtonColumn.Create(Grid1));
    end;
    
    end.