Creating a form - a function controls it!

I want to do a function. I'll control my form creation (my application will show only one form, non-modal)...

Here is the code:

function abreform(instancia: tcomponentClass; var Reference): boolean;
begin
   abreform := false;
   if not Assigned(tform(reference)) then
      begin
      application.CreateForm(instancia, Reference);
      abreform := true;
      end  
   else
      messagedlg('The form is opened', mtinformation, [mbok], 0);
end;

The problem is after the first form creation... The function don't restart the variable and returns 'Form is opened'... I've closed the respective form, and I did the caFree command...

Can you help me?!?

Thanks a lot!

Best regards,

Ricardo Baitz
baitzAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
LischkeConnect With a Mentor Commented:
Fine that I solved your problem. You should now accept one of my comments as answer and not just delete the question. This is not fair!

To make your decision easier I post an answer so you just need to accept.

Ciao, Mike
0
 
LischkeCommented:
Hi Ricardo,

this is the typical case where newbies have their problems with. Delphi does not automatically reset a reference variable to nil when the reference it points to is destroyed.

There's no harm (usually) when you set a forms reference variable to nil in the forms OnClose event. With Delphi 5 there's function FreeAndNil but you must not use this function within an event of the particular class as it frees the class for you are still executing code. But you can save assing nil to the reference variable.

Ciao, Mike
0
 
ECollinCommented:
did you set your from to "nil" ?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
ECollinCommented:
did you set your form to "nil" after the caFree ?
0
 
baitzAuthor Commented:
Thks a lot! The problem was a nill after cafree...
0
 
baitzAuthor Commented:
This question has a deletion request Pending
0
 
LischkeCommented:
This question no longer is pending deletion
0
 
baitzAuthor Commented:
Thank you, mike... Your answer are correct... I don't read it in my book!

You was a lot of fast!
0
 
baitzAuthor Commented:
And more: Only today I've entered here to transfer the points... Too late, but transfered!
0
 
LischkeCommented:
Okey, dokey :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.