Board index » cppbuilder » dynamic_cast of TMenuItem into TControl

dynamic_cast of TMenuItem into TControl

2006-09-07 10:12:36 PM
I want to iterate through all menu items on my form, but what seemed to
be a regular task, turned out to be impossible: I tried the following
Container is a parameter passed to the function of the type TWinControl
for(int i = 0; i < Container->ControlCount; i++)
//if the following is true its supposed to be a MenuItem
//Here we do whatever...
I might have slipped from the symantics here and there, but I think
this is enough to get the idea of what I want to do.
This code works for any other controls, such as TLabel, TEdit, TPanel,
TSpeedButton, TButton etc., but when it comes to TMenuItem or even
TMainMenu, I get the message: "cannot cast TControl to TMenuItem" or
"cannot cast TControl to TMainMenu"
I have two questions:
1 - Why is this not possible?
2 - How can I achieve this anyway?

Re:dynamic_cast of TMenuItem into TControl

TControl into TMenuItem

Re:dynamic_cast of TMenuItem into TControl

I got a solution, but I do not use casting nothing to solve the
problem, which still means that I would like an answer to the questions
asked earlier.
But the solution to iterate through the MainMenu is the following:
TMenuItem * itm;
for(int i = 1; i <= MainMenu1->Items->Count; i++)
itm = MainMenu1->FindItem(i, fkCommand);
//Now I have a pointer (itm) to the specific MenuItems