Hi All

Hi All
I have finally figured out a problem with my code
It was to do with using Application.CreateForm(TForm1, Form1);
 for creating forms
instead of using form1:tform1.create(self);
The former presented no problems with Delphi 2009 compiler, but with XE6, after calling that numerous times (and the form would be freed after being used), eventually you would end up with obscure access violations.
(but not on all pc's)
Just a note, when using the later, check you do not reference the form name in the oncreate...instead use self

hopefully this might help others from pulling their hair out
Brian

Comments

  1. Very true, and early access to a global singleton instance is a trick that sometimes helps with some creational patterns.
    For example, there is now just one instance of Windows 10 on my machine, and Delphi XE4 says: 'registered', under the same old user account name of course.
    The trick here was to click on 'Download Tool Now (64 bit)', which downloads a tiny exe - then choose to not create the media disk, but upgrade.
    The application of the trick is the fastest way to success!

    ReplyDelete
  2. If your form is a dialog box, it would be better to use this approach:

    class function TMyForm.Execute: Boolean;
    var
      F: TMyForm;
    begin
      F := TMyForm.Create(nil);
      try
        Result := IsPositiveResult(F.ShowModal);
      finally
        F.Free;
      end;
    end;

    You don't need any reference to a globally declared instance. When you need to execute the dialog, just call TMyForm.Execute, it will care for the correct form management.

    ReplyDelete
  3. The problem was that the instance variable was not yet valid (updated/assigned). Using self instead of the instance variable in FormCreate was a solution. Forcing the instance variable to be valid is another. The latter may prove usefull if you need to create and link dependencies as part of the form creation, at runtime.

    ReplyDelete

Post a Comment