By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,340 Members | 1,988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,340 IT Pros & Developers. It's quick & easy.

Problem with Pointers to a Form

P: 4
Hi Guys,
I am trying to call a function CodeA which is present in all the forms. Only One form exists at any time. Form1 is the MainForm, the others children.
If I execute case 0 (MainForm) all is OK.
If I execute case 1 or 2 then MainForm->CodeA is called instead of Form2->CodeA or Form3->CodeA.

What am I doing wrong?.

Expand|Select|Wrap|Line Numbers
  1.  
  2. void __fastcall TForm1::rgFormClick(TObject *Sender)
  3. {
  4. //    TForm1    *DynForm;            // declared globally
  5.  
  6.     if (DynForm != this)
  7.         DynForm->Close();
  8.     switch (rgForm->ItemIndex)
  9.     {
  10.         case    0:
  11.             DynForm = this;
  12.             break;
  13.  
  14.         case    1:
  15.             (TObject *) DynForm = Form2;
  16.             break;
  17.  
  18.         case    2:
  19.             (TObject *) DynForm = Form3;
  20.     }
  21.     DynForm->Show();   // works fine
  22.     DynForm->CodeA();            // <--------------- Problem child
  23.  
  24. }
  25.  
  26.  
Regards
John
Nov 17 '06 #1
Share this Question
Share on Google+
1 Reply


P: 4
Sorted it myself. For those that are interested.

void __fastcall TForm1::rgFormClick(TObject *Sender)
{

switch (rgForm->ItemIndex)
{
case 0:
if (DynForm)
DynForm->Hide();
(TForm1*) DynForm = dynamic_cast<TForm1*>(Form1);
break;

case 1:
if (DynForm)
if (LastIndex)
DynForm->Hide();
(TForm2*) DynForm = dynamic_cast<TForm2*>(Form2);
break;

case 2:
if (DynForm)
if (LastIndex)
DynForm->Hide();
(TForm3*) DynForm = dynamic_cast<TForm3*>(Form3);
break;
}
DynForm->Show();
DynForm->CodeA(); // <--------------- was the Problem child
LastIndex = rgForm->ItemIndex;
}
Nov 27 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.