Michael Van Canneyt wrote 8 lines
> 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/