Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OnClick event handler

2 views
Skip to first unread message

JackM

unread,
Sep 3, 2008, 1:26:55 PM9/3/08
to jlmc...@rockwellcollins.com
Question:
How do I access an "OnClick" event handler for a dynamically create
menu option?
I have a TMenuItem "Display1" and have dynamically added subMenu items
"Victory x, Victory y, and Victory z" as submenu items under Display1.
Where do I find the event handler "OnClick" to use when the user
clicks one of the submenu items?

//////////////////////////////////////////////////////////////////////////////////////////////
//This part of the code is working:
//to dynamically add submenu items
//Victory x, Victory x, and Victory z, to "Display1":

// step one
// "Display1" was declared earlier using the Tools pallet and Object
inspector
// the declaration of "Display1" looks like this --> TMenuItem
*Display1;

// step two
TMenuItem *Itemx = new TMenuItem( Display1 );
TMenuItem *Itemy = new TMenuItem( Display1 );
TMenuItem *Itemz = new TMenuItem( Display1 );

// step three
Itemx->Caption="Victory x";
Itemy->Caption="Victory y";
Itemz->Caption="Victory z";


// step four
// included for clarity but not needed because Display1 is part of
MainMenu.
// MainMenu is declared as TMainMenu *MainMenu1;

// step five
// menu items added under menu item Display1 as subMenu items

Display1->Add(Itemx);
Display1->Add(Itemy);
Display1->Add(Itemz);

/////////////////////////////////////////////////////////////////////////////////////////
I greatly appreciate any hints.
Thank you,
Jack McDaniel 760 438 9255

John Kettle

unread,
Sep 3, 2008, 8:09:58 PM9/3/08
to
In message
<f05bc4ca-aa1a-468d...@m36g2000hse.googlegroups.com>,
JackM <jlmc...@rockwellcollins.com> writes
need to create the event handler at the same time you dynamically create
the items following snippet to get you going ItemxOnClickHandler can be
any name you like to make up obviously two more needed for y and z only
shown one for x here.

void __fastcall TMainMenu1::showmenuClick(TObject *Sender)
{


TMenuItem *Itemx = new TMenuItem( Display1 );

Itemx->OnClick=ItemxOnClickHandler; // assign as the event handler

TMenuItem *Itemy = new TMenuItem( Display1 );
TMenuItem *Itemz = new TMenuItem( Display1 );

Itemx->Caption="Victory x";
Itemy->Caption="Victory y";
Itemz->Caption="Victory z";

Display1->Add(Itemx);
Display1->Add(Itemy);
Display1->Add(Itemz);
}

void __fastcall TMainMenu1::ItemxOnClickHandler(TObject *Sender)
{
//do something
Edit1->Text="itemx clicked";
}

and in the header file obviously add in public

public: // User declarations

void __fastcall ItemxOnClickHandler(TObject *Sender);


--
John Kettle

0 new messages