3

I have a TActionManager in my application, where all the actions are defined. I need to obtain a list of all its actions; currently, using its Actions property I can obtain the "path" for the action (GetNamePath) but I also want to obtain its caption.

Is it possible to obtain all actions from an action manager?

Leonardo Herrera
  • 8,388
  • 5
  • 36
  • 66

1 Answers1

5

The Actions[] property returns a TContainedAction which is a low-level base class. You'll need to up-cast that to an appropriate derived class. For example, if your action manager contains TAction instances then you can do this:

for i := 0 to ActionManager1.ActionCount-1 do begin
  Writeln((ActionManager1.Actions[i] as TAction).Caption);
end;

If you are deriving custom actions from TCustomAction, then use that in your cast.

Obviously you might want to use is to check for the actual runtime type of the action and avoid a runtime cast error.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Ack - I thought I tried this and got some compile time admonishing, but probably I was doing something else wrong. Of course it works. Thank you very much. – Leonardo Herrera Oct 06 '12 at 16:39