Solved

Loading actions at runtime

Posted on 2006-07-06
6
270 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
  • 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Show Listview image from database (String field) 5 143
Browsing a TTreeView in Delphi 5 31
Get weeknumber and year from date 4 25
Firemonkey Queue list 1 25
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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