Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top