 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Armando Guest
|
Posted: Thu Sep 07, 2006 7:12 pm Post subject: dynamic_cast of TMenuItem into TControl |
|
|
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
if(dynamic_cast<TMenuItem*> Container->Control[i])
{
//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?
Thanks,
AVILLAS |
|
| Back to top |
|
 |
Armando Guest
|
Posted: Fri Sep 08, 2006 11:14 pm Post subject: Re: dynamic_cast of TMenuItem into TControl |
|
|
Sorry,
TControl into TMenuItem
AVILLAS |
|
| Back to top |
|
 |
Armando Guest
|
Posted: Sat Sep 09, 2006 1:40 am Post subject: Re: dynamic_cast of TMenuItem into TControl |
|
|
Hi,
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
ShowModal(itm->Name);
} |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|