[Lazarus] 0.9.26 released

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Oct 14 23:02:57 CEST 2008


On Tue, Oct 14, 2008 at 3:50 PM, Michael Van Canneyt
<michael at freepascal.org> 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/



More information about the Lazarus mailing list