Solved

Loading actions at runtime

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now