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

问题描述 投票:0回答:1

如果您希望单元格显示按钮,则以下内容适用于Delphi XE5。但是在Delphi XE6中却没有。

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中完成上述工作?

grid cell firemonkey delphi-xe6
1个回答
1
投票
  1. 您的SpeedButton没有文本,因此在您使用鼠标进入按钮之前不会显示任何内容
  2. 如果您创建将此对象插入网格的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.
© www.soinside.com 2019 - 2024. All rights reserved.