Link to home
Start Free TrialLog in
Avatar of dkeene
dkeene

asked on

Loading actions at runtime

Hi, All
I am building a component that uses prewritten actions. I searched but was unable to find a way to load actions at runtime. Can anyone post a simple example? I have already created a toolbar with buttons and images created at runtime. Thanks

Doug
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

You must be talking about TActions?

Well, first, create your TActionList, then create a TAction for every action you want.
You MUST have an OnExecute method built to handle your actions, I would suggest
having one and assigning it to each of the TActions you create, then determine using the
Sender, what action to take when the OnExecute fires.

Then you want to assign the TAction that was created to the Action property of the
ToolbarBtn that you are creating.

Not that hard to do...

Here, I have two TButtons on a form and building actions for each.

var
  i: Integer;
begin
  for i := 1 to 2 do
  begin
    MyAction := TAction.Create(Self);
    MyAction.OnExecute := Action1Execute;
    MyAction.Enabled := True;
    MyAction.Caption := TButton(FindComponent('Button'+IntToStr(i))).Caption;
    TButton(FindComponent('Button'+IntToStr(i))).Action :=MyAction;
  end;

No need to create the ActionList, however. I forgot to take that out before I posted.
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial