I'm trying creating a TAction in runtime and insert in TActionClientItem, but it's give me an error at runtime (Invalid class typecast).
I'm using this way:
function TFunctions.AddMenuItem(aciParent: TActionClientItem): integer;
var
ClientItem: TActionClientItem;
ActionToAdd: TAction;
begin
ClientItem:= aciParent.items.add;
ClientItem.Action := ActionToAdd; // <- error
//
end;
Should mark the code block above as code so that it gets formatted properly (or at least as a preformatted block). Where is the "begin" statement? After the var block with the local variables declarations (you have two of those, ClientItem and ActionToAdd) there should be a "begin" statement and then your imperative commands, then have "end" statement to close the function declaration.
The error is from the parsing stage if "begin" is missing, but I'd expect it to be at ClientItem:= aciParent.items.add; (at the := point)
Obviously before "end" should also assign the "result" variable or can also return a result passing it as parameter to the "exit" statement if you need to have multiple exit points from your function. Use procedure instead of function if no result needed