Board index » cppbuilder » Form1->Show()

Form1->Show()

Hello,
 I have a number of Forms with a button on them which I open a form called
MainForm.
Can I pass the opening Form name as a variable to MainForm.

i.e. within each Form
 TObject *formname="Form1";

 TObject *formname="Form2";

.
.
etc.

within MainForm something like,

extern TObject *formname;
formname->Show();                file://Shows the form which opened MainForm

Thanks in advance.
Regards Digby Millikan.

 

Re:Form1->Show()


Hi, Digby!

Quote
Digby Millikan wrote:
>  I have a number of Forms with a button on them which I open a form called
> MainForm.
> Can I pass the opening Form name as a variable to MainForm.

> i.e. within each Form
>  TObject *formname="Form1";

>  TObject *formname="Form2";

> .
> .
> etc.

> within MainForm something like,

> extern TObject *formname;
> formname->Show();                file://Shows the form which opened MainForm

Could you be more specific, what are you going to do? From your explanation it's
not clear (at minimum for me).

--
Visit my page : http://sergss.newmail.ru/
BCB components : http://sergss.newmail.ru/BCB_eng.htm
| )))))
|
|___
|ooo|
|ooo|
|ooo|
|___|
Sergei.

Re:Form1->Show()


Sergei,
 From mainform I wish to perform VCL functions on the From which opened
MainForm.
This could be any number of Forms which opened MainForm. Hence within
MainForm I
need the name of the Form which opened MainForm. Hence either
Form1,Form2,Form3,
Form4 or Form5 could open MainForm. Then in MainForm I wish to open the Form
so
my statement would have to one of
 Form1->Show();
 Form2->Show();
 Form3->Show();
 Form4->Show(); or
 Form5->Show();

but if in MainForm I knew the name of the form as a variable I could open
the form e.g.

in Form1

OnButtonClick{
 AnsiString form=Form1;
 MainForm->Show();
 Form1->Close();

Quote
}

in Form2

OnButtonClick{
 AnsiString form=Form2;
 MainForm->Show();
 Form2->Close();

Quote
}

etc to Form5

in MainForm

extern form;
..
.
OnCloseMainForm{
 form->Show();

Quote
}

Hence I need a variable form, How can I do this.
Regards Digby Millikan.

Quote
"Sergei Sorokin" <ser...@ncc.nnov.ru> wrote in message

news:39CB33E0.729775A5@ncc.nnov.ru...
Quote
> Hi, Digby!

> Digby Millikan wrote:

> >  I have a number of Forms with a button on them which I open a form
called
> > MainForm.
> > Can I pass the opening Form name as a variable to MainForm.

> > i.e. within each Form
> >  TObject *formname="Form1";

> >  TObject *formname="Form2";

> > .
> > .
> > etc.

> > within MainForm something like,

> > extern TObject *formname;
> > formname->Show();                file://Shows the form which opened
MainForm

> Could you be more specific, what are you going to do? From your
explanation it's
> not clear (at minimum for me).

> --
> Visit my page : http://sergss.newmail.ru/
> BCB components : http://sergss.newmail.ru/BCB_eng.htm
> | )))))
> |
> |___
> |ooo|
> |ooo|
> |ooo|
> |___|
> Sergei.

Re:Form1->Show()


Hi:

   You want MainForm to "know" which form called it so you can reopen
that calling form later?

   You could pass the name of the calling form to mainform, save that
and use a series for if's to call it back.

Re:Form1->Show()


Thanks Robert,
 How can I pass the name, can I assign the name to a variable?
Digby.

Re:Form1->Show()


Ok thanks Robert,
 I'll assign the name to an AnsiString and pass that way, then use if
statements.
Thankyou!

Re:Form1->Show()


Quote
"Digby Millikan" <dig...@one.net.au> wrote in message news:39cb4490_1@dnews...
> Thanks Robert,
>  How can I pass the name, can I assign the name to a variable?
> Digby.

Give your MainForm a new Show method:

int __fastcall MainForm::Show( TForm *Shower)
{
AnsiString ShowerName = Shower->Name ;
// etc.
return Show() ;

Quote
}

And call it with something like:

MainForm->Show( this) ;

You could use this method to just pass the form's name (as an AnsiString
parameter), if that's really all you need. But passing a pointer to the form
itself is more flexible.

  Max.

Re:Form1->Show()


Hi, Digby!

Quote
>  From mainform I wish to perform VCL functions on the From which opened
> MainForm.
> This could be any number of Forms which opened MainForm. Hence within
> MainForm I
> need the name of the Form which opened MainForm. Hence either
> Form1,Form2,Form3,
> Form4 or Form5 could open MainForm. Then in MainForm I wish to open the Form
> so
> my statement would have to one of
>  Form1->Show();
>  Form2->Show();

First of all, I have a problem to reply to you answer to me. That's why I'm
answering here.

Then, this task is not difficult. But you don't need the name of any form, just
use pointers.
In order to complete it:

1. Include header file from MainForm to Form1's .cpp file and Form1 header file
to MainForm's .cpp file.

2. Define in MainForm header new private member:
TForm* OtherForm;

3. Just after creating of MainForm by new operator or, if it's autocreated form,
just before calling MainForm->Show() do the next:
MainForm->OtherForm=this; // in Form1's code

4.
A. If you are going to use standard Form's methods (like Show) just call it from
MainForm's code, from any place:
OtherForm->Show(); // as an example

B. If it will be user-defined method, add some more lines to your MainForm's
code:
TForm1* NewForm=dynamic_cast<TMainForm*>(OtherForm);

NewForm->Show(); // also possible
NewForm->UserDefineMethod(); // your own method

That's all.

--
Visit my page : http://sergss.newmail.ru/
BCB components : http://sergss.newmail.ru/BCB_eng.htm
| )))))
|
|___
|ooo|
|ooo|
|ooo|
|___|
Sergei.

Re:Form1->Show()


Hi:

   You can do it all sorts of ways. Pointers I have not had luck with. I
use it to send data back to a calling form.

   Just set up an enum with some dummy names, pass the name and use a
switch. The you can show the calling form or set data in the calling
form.

   For example, if I want to add an e-mail address to a form, exit the
e-mail with data causes the address book to open up adds it there where
you can modify, sets e-mail name etc. then when you close the address
book, before closing, it insert the data in appropriate DBEdits on the
calling form. I have about 5 different forms which can open the address
book and each passes its identity so when the address book closes it
inserts the data in the calling forms DBEdit.

                                                           Best regards

Re:Form1->Show()


Thankyou!
Regards D.Millikan

Re:Form1->Show()


Why not get the pointer to the caller form and then call it's show-
method?

class TMainForm
{

int __fastcall MainForm::Show( TForm *Shower)
{
  mCallerForm = Shower->Name ; // save pointer to calling form
  return Show() ;  // call inherited method

Quote
}

void __fastcall TKoMainForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
        mCallerForm->Show();

Quote
}

private:
    Tform* mCallerForm; // The calling form

Quote
}

In article <39cb4e38_1@dnews>, you say...
Quote
> Give your MainForm a new Show method:

> int __fastcall MainForm::Show( TForm *Shower)
> {
> AnsiString ShowerName = Shower->Name ;
> // etc.
> return Show() ;
> }

> And call it with something like:

> MainForm->Show( this) ;

> You could use this method to just pass the form's name (as an AnsiString
> parameter), if that's really all you need. But passing a pointer to the form
> itself is more flexible.

>   Max.

Other Threads