Solved

Creating a form - a function controls it!

Posted on 2000-05-02
10
214 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:baitz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2769484
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
 
LVL 10

Expert Comment

by:ECollin
ID: 2769491
did you set your from to "nil" ?
0
 
LVL 10

Expert Comment

by:ECollin
ID: 2769493
did you set your form to "nil" after the caFree ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:baitz
ID: 2769525
Thks a lot! The problem was a nill after cafree...
0
 

Author Comment

by:baitz
ID: 2769526
This question has a deletion request Pending
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2769658
This question no longer is pending deletion
0
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
ID: 2769660
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
 

Author Comment

by:baitz
ID: 2812207
Thank you, mike... Your answer are correct... I don't read it in my book!

You was a lot of fast!
0
 

Author Comment

by:baitz
ID: 2812214
And more: Only today I've entered here to transfer the points... Too late, but transfered!
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2813459
Okey, dokey :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to update exe applicatio from internet ? 6 92
Base1 Encode/Decode 3 86
Installshield for Embarcadero EX 10.1 Berlin 4 72
shape, triangle, dbctrlgrid 3 33
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question