2014-07-14 86 views
0

如果你想讓一個單元顯示一個按鈕,下面的代碼就可以在Delphi XE5中使用。但是在Delphi XE6中它並不是。如何在grid cell firemonkey 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
  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. 
    
相關問題