Board index » cppbuilder » Re: DYNAMIC COMPONENT ACCESS

Re: DYNAMIC COMPONENT ACCESS


2007-11-28 10:31:15 PM
cppbuilder62
"Marshall" < XXXX@XXXXX.COM >wrote:
Quote

void __fastcall TfrmPILSPPConfig::tbSiteExit(TObject *Sender)
{
//how do I access the dynamic component tbRefSiteName[i] that triggered
this event.
}
That is what the Sender parameter is for:
TEdit *pEdit = static_cast<TEdit*>( Sender );
// pEdit is the same as tbRefSiteName[i]
~ JD
 
 

Re:Re: DYNAMIC COMPONENT ACCESS

Good Morning All,
I need a little help in accessing a dynamically created component in an
event handler. For example, I create an array of dynamic components:
for (int i = 0; i < MAX_REF_SITES; i++)
{
tbRefSiteName[i] = new TEdit(gbSites);
tbRefSiteName[i]->Parent = gbSites;
tbRefSiteName[i]->Top = 32 + 24 * i;
tbRefSiteName[i]->Left = 36;
tbRefSiteName[i]->Width = 81;
tbRefSiteName[i]->Hint = "Four (4) character abbreviation for the
reference Site";
tbRefSiteName[i]->ShowHint = TRUE;
tbRefSiteName[i]->MaxLength = 4;
tbRefSiteName[i]->OnExit = tbSiteExit;
}
then in the event handler OnExit = tbSiteExit:
void __fastcall TfrmPILSPPConfig::tbSiteExit(TObject *Sender)
{
//how do I access the dynamic component tbRefSiteName[i] that triggered
this event.
}
As the comment says, I need to access the dynamically created TEdit named
tbRefSiteName[i] that triggered the event. One of things I must do is to
make the TEXT field uppercase, as an example.
Thanks in advance,
Marshall
 

Re:Re: DYNAMIC COMPONENT ACCESS

"Marshall" < XXXX@XXXXX.COM >wrote in message
Quote
void __fastcall TfrmPILSPPConfig::tbSiteExit(TObject *Sender)
{
//how do I access the dynamic component tbRefSiteName[i] that triggered
this event.
}
That is what the Sender parameter is for. It is a pointer to the object
that is triggering the event. Simply cast it to the appropriate type (in
this case, TEdit) and access it as needed, ie:
void __fastcall TfrmPILSPPConfig::tbSiteExit(TObject *Sender)
{
TEdit *pEdit = static_cast<TEdit*>(Sender);
pEdit->Text = pEdit->Text.UpperCase();
}
Gambit
 

{smallsort}

Re:Re: DYNAMIC COMPONENT ACCESS

Hi Marshall
Marshall says:
Quote
Good Morning All,

then in the event handler OnExit = tbSiteExit:

void __fastcall TfrmPILSPPConfig::tbSiteExit(TObject *Sender)
{
//how do I access the dynamic component tbRefSiteName[i] that triggered
this event.
}
As Remy or JD says or You can set the Tag on each
Edit
tbRefSiteName[i]->Tag = i+10;
TEdit *Chosen = dynamic_cast<TEdit*>(Sender);
if(!Chosen)return;
switch(Chosen->Tag)
{
case 10: ;break;
case 11: ;break;
case 12: ;break;
.....
} //end switch
Kind regards
Asger