Solved

Loading actions at runtime

Posted on 2006-07-06
6
271 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:dkeene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17053539
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;

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17053542
No need to create the ActionList, however. I forgot to take that out before I posted.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 100 total points
ID: 17053553
A little better:

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

Assisted Solution

by:atul_parmar
atul_parmar earned 100 total points
ID: 17056749
>> I am building a component that uses prewritten actions. I searched but was unable to find a way to load actions at runtime.

var
  i : integer;
  AcList : TActionList;
begin
  // search for prewritten actionlist
  for i := 0 to Self.Owner.ComponentCount - 1 do
    if Components[i] is TActionList then
      AcList := TActionList(Components[i]);
  // if found then asscociate
  If Assigned(AcList) then
    MyButton.Action := AcList.Actions[0];
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question