🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.oodesign
6 messages
6 total messages Started by Jose Manuel Tovar Tue, 22 Jun 2004 16:33
Delete and null a no modal form
#19
Author: Jose Manuel Tovar
Date: Tue, 22 Jun 2004 16:33
104 lines
2228 bytes
Hello everybody,



I have a doubt:



I have a main form (Form1) and when I press a button I create a new no modal
form (Form2). In order to destroy Form2 I use "caFree".



void __fastcall TForm1::btn_botonClick(TObject *Sender)

{

  Form2 = new TForm2(Application);

  Form2->Show();

}

//--------------------------------------------------------------------------
-



void __fastcall TForm2::FormClose(TObject *Sender,

      TCloseAction &Action)

{

  Action = caFree;

}

//--------------------------------------------------------------------------
-



(Form2 is a global variable)



And I suppose that this is equivalent to (talking about freeing memory):



delete Form2;





But I would need something like (talking about nullify the pointer):



Form2 = 0;



to do something like checking the existence of the form "if (Form2) .", etc.
and that is not done using "caFree".





Can I do?



__fastcall TForm2::~TForm2()

{

  Form2 = 0;

}

//--------------------------------------------------------------------------
-



I think this is possible but what happens with all the windows standard
controls (labels, combos, etc ) defined in Form2?, are they destroyed
automatically?



Or if this is not possible, how could I delete no modal forms and null them?



Thanks in advance,



Jos� Manuel Tovar
Re: Delete and null a no modal form
#20
Author: Hans Galema
Date: Tue, 22 Jun 2004 19:02
45 lines
2045 bytes
Jose Manuel Tovar wrote:

> I have a main form (Form1) and when I press a button I create a new no modal
> form (Form2). In order to destroy Form2 I use "caFree".

How many Form2's do you allow to exist simultanously ?

> void __fastcall TForm1::btn_botonClick(TObject *Sender)
> {
    // To allow only one Form2
     if ( ! Form2 )
	   Form2 = new TForm2(Application);
	// As Application is the Owner your
         // Form will be deleted by TApplication
	// at programm end

>   Form2->Show();
> }


> void __fastcall TForm2::FormClose(TObject *Sender,
>       TCloseAction &Action)
> {
>   Action = caFree;
    // Ok

> __fastcall TForm2::~TForm2()
> {
>   Form2 = 0;

That is ok, provided you keep the caFree;

> I think this is possible but what happens with all the windows standard
> controls (labels, combos, etc ) defined in Form2?, are they destroyed
> automatically?

Yes. If the Form is destroyed the componets are destroyed too.

> Thanks in advance,

??

What kind of whitelineproducer do you happen to use ?

Hans.
Re: Delete and null a no modal form
#21
Author: Jose Manuel Tovar
Date: Wed, 23 Jun 2004 07:44
84 lines
2877 bytes
Hello Hans,

Thank for your quick response.


"Hans Galema" <dontusethis@dontusethis.nl> escribi� en el mensaje
news:40d8820d@newsgroups.borland.com...
> Jose Manuel Tovar wrote:
>
> > I have a main form (Form1) and when I press a button I create a new no
modal
> > form (Form2). In order to destroy Form2 I use "caFree".
>
> How many Form2's do you allow to exist simultanously ?

I have only one Form2 but I think that if I need more than one I only have
to define a new global variable where to store the objet, isn't it?

>
> > void __fastcall TForm1::btn_botonClick(TObject *Sender)
> > {
>     // To allow only one Form2
>      if ( ! Form2 )
>    Form2 = new TForm2(Application);
> // As Application is the Owner your
>          // Form will be deleted by TApplication
> // at programm end
>

How can I delete completely Form2 when the Form2 is closed by the user? I
mean that I would like to free the memory used by the form when the user
closes Form2.

I have to say that Form1 is always open so I'm afraid that using:



Form2 = new TForm2(Form1);



it is not the solution...



> >   Form2->Show();
> > }
>
>
> > void __fastcall TForm2::FormClose(TObject *Sender,
> >       TCloseAction &Action)
> > {
> >   Action = caFree;
>     // Ok
>
> > __fastcall TForm2::~TForm2()
> > {
> >   Form2 = 0;
>
> That is ok, provided you keep the caFree;
>
> > I think this is possible but what happens with all the windows standard
> > controls (labels, combos, etc ) defined in Form2?, are they destroyed
> > automatically?
>
> Yes. If the Form is destroyed the componets are destroyed too.
>
> > Thanks in advance,
>
> ??
>
> What kind of whitelineproducer do you happen to use ?
>

:)
The whitelineproducer is the famous MS Word with the invaluable
collaboration of the copy/paste command
.)

> Hans.

Thank you one more time.

Jose Manuel
Re: Delete and null a no modal form
#22
Author: Hans Galema
Date: Wed, 23 Jun 2004 19:44
38 lines
2043 bytes
Jose Manuel Tovar wrote:

> I have only one Form2 but I think that if I need more than one I only have
> to define a new global variable where to store the objet, isn't it?

That is possible yes. But your problem after that is to null that pointer
in the form is destroyed.

> How can I delete completely Form2 when the Form2 is closed by the user? I
> mean that I would like to free the memory used by the form when the user
> closes Form2.

In general placing the statement

	Action = caFree;

in the OnClose() eventhandler of that form.
But your pointer will not zero then.

>>>void __fastcall TForm2::FormClose(TObject *Sender,
>>>      TCloseAction &Action)
>>>{
>>>  Action = caFree;

Well you have that already.

>>>__fastcall TForm2::~TForm2()
>>>{
>>>  Form2 = 0;
>>
>>That is ok, provided you keep the caFree;

If you could make an extra parameter for TForm2 that points
to your pointer than the form can place a null at destruction.

Please trim quotes when replying.

Hans.
Re: Delete and null a no modal form
#23
Author: Jose Manuel Tovar
Date: Thu, 24 Jun 2004 14:30
42 lines
2270 bytes
"Hans Galema" <dontusethis@dontusethis.nl> escribi� en el mensaje
news:40d9dd53@newsgroups.borland.com...
> Jose Manuel Tovar wrote:
>
> > How can I delete completely Form2 when the Form2 is closed by the user?
I
> > mean that I would like to free the memory used by the form when the user
> > closes Form2.
>
> In general placing the statement
>
> Action = caFree;
>
> in the OnClose() eventhandler of that form.
> But your pointer will not zero then.
>
> >>>void __fastcall TForm2::FormClose(TObject *Sender,
> >>>      TCloseAction &Action)
> >>>{
> >>>  Action = caFree;
>
> Well you have that already.
>
> >>>__fastcall TForm2::~TForm2()
> >>>{
> >>>  Form2 = 0;
> >>
> >>That is ok, provided you keep the caFree;
>
> If you could make an extra parameter for TForm2 that points
> to your pointer than the form can place a null at destruction.
>

I'm afrais that I don't understand what you try to say. Why I need a
parameter that points to TForm2 if I can access to Form2 (the global
variable that points to TFrom2) in the TForm2 destructor and null it?

Could you give me short code example where I can see how to do what you
proposed?

Thaks for your patience.
Re: Delete and null a no modal form
#24
Author: Hans Galema
Date: Thu, 24 Jun 2004 20:57
40 lines
2251 bytes
Jose Manuel Tovar wrote:

> I'm afrais that I don't understand what you try to say. Why I need a
> parameter that points to TForm2 if I can access to Form2 (the global
> variable that points to TFrom2) in the TForm2 destructor and null it?

You only need that if you open more instances of TForm2:

 >> I have only one Form2 but I think that if I need more than one I only have
 >> to define a new global variable where to store the objet, isn't it?

So then an instance has to know which pointer to null.

> Could you give me short code example where I can see how to do what you
> proposed?

Before doing that I would like you to understand that if you have

global:
TForm2 *Form2A;
TForm2 *Form2B;

and

	Form2A = new TForm2 ( this );
	Form2B = new TForm2 ( this );

That every instance of TForm2 has to know its global pointer
in order to be able to null it.

You can do that with an extra parameter, but it would be
possible without too in the following way in the TForm2::OnClose():

	if ( Form2A == this ) Form2A = NULL;
	if ( Form2B == this ) Form2B = NULL;


Please do not quote entire posts.

Hans.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads