INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Closing forms

Closing forms

(OP)
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

RE: Closing forms

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

implementation

{$R *.dfm}

uses
  unit2;

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

unit2 code

CODE

implementation

{$R *.dfm}

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




RE: Closing forms

Should also add that I took Form2 out of the project's auto-create list.

RE: Closing forms

(OP)
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

RE: Closing forms

(OP)
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

RE: Closing forms

(OP)
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

RE: Closing forms

2
Try to run the following line in OnDestroy rather than run on OnClose:

CODE -->

Frm_ExtractCDRP := nil; 

Hope this helps.

RE: Closing forms

(OP)
Amazing...that did the trick..thanks a lot.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close