Board index » cppbuilder » Re: TMainMenu->OnClick = Bug ? Never reached...

Re: TMainMenu->OnClick = Bug ? Never reached...


2003-12-03 08:27:44 AM
cppbuilder23
"Oren \(Halvani.de\)" < XXXX@XXXXX.COM >wrote:
Quote
void __fastcall TfrmMRU::FormDestroy(TObject *Sender) {delete MruList;}
Never use OnCreate or OnDestroy.
www.bcbdev.com/articles/suggest.htm
Quote
why does the code not getting executed...?
Don't assign it to a MainMenu Item. Assign it to a sub item
instead.
~ JD
 
 

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

hi dear builders..
I found (I think so..) a very strange bug inside the TMainMenu..
the below code should be processed BUT it doesn't !!
/**********************************************************/
void __fastcall TForm1::cmdFileClick(TObject *Sender)
{
/* this function reads some values from the registry...if the values
exist
some items will appear below "File"...
MenuItem_Handler();
}
/**********************************************************/
while this works...(but not 100 %)
/**********************************************************/
void __fastcall TForm1::cmdFileClick(TObject *Sender)
{
ShowMessage("test !"); // the message box appears but the menu isn't
showing...
}
/**********************************************************/
cmdFile is the top item in the menu, I mean when you hit "File"
cmdFileClick(TObject *Sender) is getting calling..
So my question now, how can I assign a onEnter Event for the menu or is this
not possible..?
thanks for any help...
By the way I use BCB 3 on Win XP...
Oren
 

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
the below code should be processed BUT it doesn't !!
Please elaborate. Just saying "it doesn't work" says nothing at all about
the actual problem you are having. Please provide actual details. What
exactly are you trying to accomplish? What do you expect the code to do?
What is it actually doing instead?
Quote
how can I assign a onEnter Event for the menu or is this not possible..?
There is no such thing for menus. The OnClick is the closest you are going
to get. OnClick is called during a menu's initialization procedures when
you click on a particular menu, or just hover over the menu if it has a
submenu.
Gambit
 

{smallsort}

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

Quote
There is no such thing for menus. The OnClick is the closest you are
going
to get. OnClick is called during a menu's initialization procedures when
you click on a particular menu, or just hover over the menu if it has a
submenu.
thats the point Remy, it DOESN'T ! the OnClick Event or better the code that
I put inside will not get processsed..!!
here is a part of it..
/*****************************************************************/
#define Write reg->WriteString
#define Read reg->ReadString
#define hide Visible = false;
const int MruCount = 10;
const char* RegKey = "Software\\Halvani\\MRU";
void __fastcall TfrmMRU::FormDestroy(TObject *Sender) {delete MruList;}
void __fastcall TfrmMRU::MenuItem_Handler()
{
TRegistry* reg = new TRegistry; reg->OpenKey(RegKey, false);
MRU1->Caption = Read("MRU1"); MRU2->Caption = Read("MRU2");
MRU3->Caption = Read("MRU3"); MRU4->Caption = Read("MRU4");
MRU5->Caption = Read("MRU5"); MRU5->Caption = Read("MRU6");
MRU5->Caption = Read("MRU7"); MRU5->Caption = Read("MRU8");
MRU5->Caption = Read("MRU9"); MRU5->Caption = Read("MRU10");
if(Read("MRU1") == "") MRU1->hide; if(Read("MRU2") == "") MRU2->hide;
if(Read("MRU3") == "") MRU3->hide; if(Read("MRU4") == "") MRU4->hide;
if(Read("MRU5") == "") MRU5->hide; if(Read("MRU6") == "") MRU6->hide;
if(Read("MRU7") == "") MRU7->hide; if(Read("MRU8") == "") MRU8->hide;
if(Read("MRU9") == "") MRU9->hide; if(Read("MRU10") == "") MRU10->hide;
if(((Read("MRU1") == "") && (Read("MRU2") == "") && (Read("MRU3") == "")
&&
(Read("MRU4") == "") && (Read("MRU5") == "") && (Read("MRU6") == "")
&&
(Read("MRU7") == "") && (Read("MRU8") == "") && (Read("MRU9") == "")
&&
(Read("MRU10") == "")) || !reg->KeyExists(RegKey)) cmdDummy->Visible =
true;
else cmdDummy->Visible = false;
delete reg;
}
//HERE'S THE onClick Event...
void __fastcall TfrmMRU::cmdFileClick(TObject *Sender)
{
MenuItem_Handler();
}
/*************************************************************************/
hope you understand now my problem...why does the code not getting
executed...?
Oren
 

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
thats the point Remy, it DOESN'T ! the OnClick Event or better the code
that
I put inside will not get processsed..!!
I cannot reproduce what you claim. The OnClick event is always triggered
when I try it.
Quote
void __fastcall TfrmMRU::FormDestroy(TObject *Sender) {delete MruList;}
Do *not* use the OnDestroy event in C++. It is a Delphi remnant that is
unstable in C++ as it can be triggered after the destructor, which is
illegal in C++. Use the actual destructor instead.
Quote
MRU1->Caption = Read("MRU1"); MRU2->Caption = Read("MRU2");
<snip>
You are reading the same Registry values over and over throughoout your
function. I would suggest you cache the values to variables so that you are
not going back to the Registry every time. It is unnecessary.
Gambit
 

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

OK..now I got:
__fastcall TfrmMRU::TfrmMRU(TComponent* Owner):~TForm(Owner){delete
MruList;}
but it doesn't work...the compiler says: "identifier expected" what do I
forgot...?
Oren
 

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
__fastcall TfrmMRU::TfrmMRU(TComponent* Owner):~TForm(Owner){delete
MruList;}
That is not valid syntax. The destructor is its own separate method. It is
not part of the constructor at all, which you are trying to make it be. It
should be this instead:
// this is a constructor
__fastcall TfrmMRU::TfrmMRU(TComponent* Owner)
: TForm(Owner)
{
}
// this is a destructor
__fastcall TfrmMRU::~TfrmMRU()
{
delete MruList;
}
Don't forget to add the destructor's declaration to the "public" section of
the header file.
Gambit
 

Re:Re: TMainMenu->OnClick = Bug ? Never reached...

thanks Remy :-)
Quote
// this is a destructor
__fastcall TfrmMRU::~TfrmMRU()
{
delete MruList;
}