Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing forms 2

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I have a button that creates a new form. I use:
if Frm_ExtractCDRP = nil then
Frm_ExtractCDRP := TFrm_ExtractCDRP.Create(application)
else showmessage('not closed');

Now when i close my form, i have this statement in the onclose event:
showmessage('close');
Action := CaFree;
Frm_ExtractCDRP := nil;

The problem is that i see the close message when i close the Frm_ExtractCDRP form. So i assume that it is now close but when i click back on the button to re generate the form again, i get the message "Not Closed"

So i have to assume that it is not really fully closed.
What am i doing wrong?

Thanks for any input..
Peter
 
I did a test project and it works for me (D6). I can continuously click the button on Form1, and then close Form2 by clicking it's X in the top right.

unit1 code
Code:
[b]implementation[/b]

[navy][i]{$R *.dfm}[/i][/navy]

[b]uses[/b]
  unit2;

[b]procedure[/b] TForm1.Button1Click(Sender: TObject);
[b]begin[/b]
  [b]if[/b] form2 = [b]nil[/b] [b]then[/b]
  [b]begin[/b]
    form2 := TForm2.Create(Application);
    form2.Show;
  [b]end[/b]
  [b]else[/b]
    ShowMessage([teal]'not closed'[/teal]);
[b]end[/b];

unit2 code
Code:
[b]implementation[/b]

[navy][i]{$R *.dfm}[/i][/navy]

[b]procedure[/b] TForm2.FormClose(Sender: TObject; [b]var[/b] Action: TCloseAction);
[b]begin[/b]
  showmessage([teal]'closing'[/teal]);
  Action := caFree;
  form2 := [b]nil[/b];
[b]end[/b];




 
Should also add that I took Form2 out of the project's auto-create list.
 
Well, the only difference is that i do not have the form2.show. i never show the form. i have commands in the form create eventso when i create the form, it triggers the oncreate event. then the form closes by itself. when i try to re create the form, it does not work as it looks like it is still created so the on create event is not triggered again.

If you think about something else, let me know...i am lost.
P
 
to imex:
extractCDRP.pas is declared in the uses portion of the main unit where i call
if Frm_ExtractCDRP = nil then
Frm_ExtractCDRP := TFrm_ExtractCDRP.Create(application)
else showmessage('not closed');

It is not declared in the auto create form list.
The name of the unit is extractCDRP.pas.

I have a feeling that i am not doing something correctly i guess.
In my project tree, i have umain.pas and extractcdrp.pas.

In umain, i have the uses extractcdrp.pas;

Hope that will help.
Thanks.
P
 
I do not think so. I use the close command at the end of my oncreate event. The showmessage('close') statement located in the onclose event is indeed triggered so i assume that the onclose event has been processed.
What do you think?
P
 
Try to run the following line in OnDestroy rather than run on OnClose:

Code:
Frm_ExtractCDRP := nil;

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top