Re: [Lazarus] Where is form instance being NIL'ed
On Tue, 14 Oct 2008, Graeme Geldenhuys wrote: Hi, When a new form is created using Application.CreateForm(), the form's global instance variable is passed in as well. Now if that form's CloseAction = caFree, where is that instance variable assigned nil after it was freed? It is not, unless you set it to nil in the BeforeDestroy event. Using that variable is a very bad idea anyway. Michael. ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where is form instance being NIL'ed
Zitat von Graeme Geldenhuys [EMAIL PROTECTED]: Hi, When a new form is created using Application.CreateForm(), the form's global instance variable is passed in as well. Now if that form's CloseAction = caFree, where is that instance variable assigned nil after it was freed? In fpGUI, the form is freed, but the global instance variable is still pointing to a now non-existing form. I need that instance variable to be nil. Any help you guys can offer? The variable pointer is not stored, so can not be set to nil by the LCL. Afaik it is the same with the VCL. Why not set it to nil in TForm.Destroy? Mattias ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where is form instance being NIL'ed
Graeme Geldenhuys wrote: On Tue, Oct 14, 2008 at 4:20 PM, Mattias Gärtner [EMAIL PROTECTED] wrote: The variable pointer is not stored, so can not be set to nil by the LCL. Afaik it is the same with the VCL. Why not set it to nil in TForm.Destroy? That ties the class to a external instance variable. I thought there might be a more elegant way of handling this. But if there isn't, then that's what I'll have to do. :) Is that the recommended method of handling non-modal forms in Delphi as well? In Delphi I manage nonmodal forms myself in the mainform (and set them to in in Form.onDestroy). I don't use those global ones and remove them. Marc ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where is form instance being NIL'ed
On Tue, Oct 14, 2008 at 3:50 PM, Michael Van Canneyt [EMAIL PROTECTED] wrote: When a new form is created using Application.CreateForm(), the form's global instance variable is passed in as well. Now if that form's CloseAction = caFree, where is that instance variable assigned nil after it was freed? It is not, unless you set it to nil in the BeforeDestroy event. Using that variable is a very bad idea anyway. I hate those global form variables as well, but how else do you handle non-modal forms? For example. I create a non-modal TaxCodeListing form. The user used the main form's menu to get to TaxCodeList. If the form already exists, it should bring it to the front and not create another instance. To do that, if check if the global form variable = nil or not. After the first create and even if the user actually closed the form (not just sitting in the background), that global form variable in now always nil. So when the user selects the menu option to view the TaxCodeList form a little later. The apps sees that the global form variable nil and tries to call .ActivateWindow() and I get a lovely exception error. :-( function DisplayTaxCodeList: Boolean; begin Result := False; if not Assigned(TaxCodeListForm) then fpgApplication.CreateForm(TTaxCodeListForm, TaxCodeListForm) else TaxCodeListForm.ActivateWindow; TaxCodeListForm.Show; Result := True; end; Any better suggestions for managing non-modal forms? Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus