2009. február 1., vasárnap

Create a TAction and its OnExecute event at runtime


Problem/Question/Abstract:

How to create a TAction and its OnExecute event at runtime

Answer:

{ ... }
type
  TForm1 = class(TForm)
    ActionList1: TActionList;
    procedure FormCreate(Sender: TObject);
  private
    Action1, Action2: TAction;
    procedure Test(Sender: TObject);
  end;

procedure TForm1.Test(Sender: TObject);
begin
  Caption := IntToStr(Actionlist1.ActionCount);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Action1 := TAction.Create(Actionlist1);
  Action1.Actionlist := Actionlist1;
  Action1.OnExecute := Test;
  Form1.OnClick := Action1.OnExecute;
end;

Nincsenek megjegyzések:

Megjegyzés küldése