[Reply] Hi Alistair,
There are two issues here, instantiation and visibility (and a little bit of OO theory). When you create an instance of a form (instantiation), you are creating an object in memory (The memory is allocated by the OS, ie Windows). The form class (rather like a recipe for a cake) contains the "design" of the form object. When you create the form object, this is like baking a cake "from the recipe". You can now eat it! Trying to eat the recipe does you no good, eg "memory access violation", because there was no memory allocated for that object yet. Now, a form object has a property called "visible". This determines whether the form can be seen on the screen (even if behind another windows form). The "Show" and "ShowModal" methods change this property. The "modal" parts determines how the form is accessed in your application (ie the form must be closed before any other forms in your app can be accessed). Note it does not prevent other applications being accessed in the meantime. Now, closing a form just hides the form, ie the visible property is set to false. However the form object still exists in memory, and can be "shown" and "closed" at will. Also the form properties can be set (eg color:=clBlue) when the form is not visible. Points of note: 1. In the form object there is a event called onClose. There is a parameter called "Action" (TCloseAction) which by default is set to caNone. This can be set to caFree, which will automatically destroy the form object when it is closed. This is handy where you are creating many instances of a form in your application. 2. When you free an object (eg myForm.free), Windows will deallocate the memory, however, the variable (myForm) will still point to that area of memory previously allocated. If at a later time you check to see if the form variable is valid, and use "if assigned(myForm)", then you will get a true result. This is because the 'free" does not invalidate the variable. You must set the form variable to nil as well, either by setting "myForm:=nil", or by using the "FreeAndNil(myForm)" method. HTH kr Gary | To : [EMAIL PROTECTED] | Hi all. This might not make sense but this is what I want to do. | In mainform: | SDWForm1 := TSDWForm1.Create(nil); | with SDWForm1 do | try | Result := ShowModal; | finally | Timer1.Enabled := true; | Timer2.Enabled := true; | end; | | Later, in mainform close: | FreeandNil(SDWform1); | | Notice, the form is not freed until mainform close. But in the help it says that: | 'ShowModal returns value to which the ModalResult property is set when it closes | the form.' | Does this mean a typical closure eg SDWForm1 is set to nil or what? | I need a modal form, but want to retain the variables etc. | >From trial and error it appears the form still retains as I can still access the | variables and properties after the form has completed its showmodal, however, | that might just be remnant pointers in memory; I hope not! | Thanks, | Alistair+ | | | | | _______________________________________________ | Delphi mailing list | [EMAIL PROTECTED] | http://ns3.123.co.nz/mailman/listinfo/delphi | ======================================================== Gary Benner - e-Engineer and Software Developer - [EMAIL PROTECTED] 123 Internet Ltd Lecturer in Information Technology - Waiariki Institute of Technology _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
