Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Form variable accessibility
Sat, Apr 28 2012 10:06 PMPermanent Link

Rick

Hi Tim.

It appears that there is no accessibility to the global form variable from
procedures called via the form's OnCreate event.

Consider the following code:

type

  TForm1 = class(TForm)
     procedure Form1Create(Sender: TObject);
  private
     { Private declarations }
     procedure CallMe;
  public
     { Public declarations }
  end;

var
  Form1: TForm1;

implementation

procedure TForm1.CallMe;
begin
Form1.Left:=50;
end;

procedure TForm1.Form1Create(Sender: TObject);
begin
CallMe;
end;


Note that the application is newly created and the main form is
auto-created.

When this is run the application fails and the following error message
appears in a popup:

Application Error
'unit1_form1' is null or not an object
Line: 12547

If I remove the Form1. qualifier from the Left property in the CallMe
procedure then the application runs correctly and the form is positioned as
specified.

--
Rick





Attachments: formvariable.jpg
Sun, Apr 29 2012 12:49 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Rick,

<< It appears that there is no accessibility to the global form variable
from procedures called via the form's OnCreate event. >>

That is correct - the form variable won't be assigned until the constructor
is complete.  You have to simply reference the form properties directly.

--
Tim Young
Elevate Software
www.elevatesoft.com
Sun, Apr 29 2012 9:39 PMPermanent Link

Rick

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message
news:3735738D-2E86-4F3C-B28A-CDD62459514A@news.elevatesoft.com...
>
> << It appears that there is no accessibility to the global form variable
> from procedures called via the form's OnCreate event. >>
>
> That is correct - the form variable won't be assigned until the
> constructor is complete.  You have to simply reference the form properties
> directly.
>
>

OK, I guess I was expecting it to function in a similar fashion to Delphi
where this type of construct is permitted. Probably because Delphi creates
the main form via Application.CreateForm rather than just a straight Create
like EWB.

I imagine that a lot of this will be covered in the documentation so I'll
try and not bother you any more until the product is released. Hard not to
be enthusiastic about it because it such a great tool - I really hope you do
very well out of it.

Thanks.

--
Rick

Thu, May 3 2012 9:01 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Rick,

<< OK, I guess I was expecting it to function in a similar fashion to Delphi
where this type of construct is permitted. Probably because Delphi creates
the main form via Application.CreateForm rather than just a straight Create
like EWB. >>

Yes, that is the crux of the issue - there isn't support for class types or
variable parameters in EWB.

<< I imagine that a lot of this will be covered in the documentation so I'll
try and not bother you any more until the product is released. Hard not to
be enthusiastic about it because it such a great tool - I really hope you do
very well out of it. >>

Thanks. Smile If you have something that looks like a bug, feel free to
ask/post.  It's really just the "how do I do this" type of thing that I
would prefer everyone to wait for the docs before asking.

Tim Young
Elevate Software
www.elevatesoft.com
Image