如果您希望单元格显示按钮,则以下适用于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中完成上述工作?
答案 0 :(得分:1)
如果您创建将此对象插入网格的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.