BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dynamic_cast of TMenuItem into TControl

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language)
View previous topic :: View next topic  
Author Message
Armando
Guest





PostPosted: Thu Sep 07, 2006 7:12 pm    Post subject: dynamic_cast of TMenuItem into TControl Reply with quote



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





PostPosted: Fri Sep 08, 2006 11:14 pm    Post subject: Re: dynamic_cast of TMenuItem into TControl Reply with quote



Sorry,

TControl into TMenuItem

AVILLAS
Back to top
Armando
Guest





PostPosted: Sat Sep 09, 2006 1:40 am    Post subject: Re: dynamic_cast of TMenuItem into TControl Reply with quote



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
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group
.