Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Auto-creation of forms
Thu, Sep 24 2015 7:37 AMPermanent Link

Matthew Jones

In EWB1, the project source looks like this for an auto-created form:

  frmFeedback:=TfrmFeedback.Create(Application);

In EWB2, the same form auto-created is like this:

  Application.CreateForm(TfrmFeedback);

Is there some magic that is supposed to assign the global variable for
referencing it, or is that just not done any more?

It isn't serious, and I've added
       if not assigned(frmFeedback) then
           frmFeedback := TfrmFeedback.Create(Application);
before the acccess, but it is worth knowing if this is by design now.

--

Matthew Jones
Thu, Sep 24 2015 12:17 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Is there some magic that is supposed to assign the global variable for referencing it, or is that just not done any more? >>

Yes, it's added by the persistence layer in EWB 2.x:

In WebForms unit:

function TFormControl.LoadProperty(AReader: TReader): Boolean;
var
  TempPropertyName: String;
  TempName: String;
begin
  Result:=False;
  { Be sure to skip over the creation of the root form control
    and the setting of its name !!! }
  if (AReader.Level=0) then
     begin
     TempPropertyName:=AReader.GetPropertyName;
     if (TempPropertyName <> '') then
        begin
        if SameText(TempPropertyName,PERSISTENT_LOAD_CLASSNAME)  then
           begin
           Result:=True;
           AReader.SkipPropertyName;
           AReader.SkipPropertySeparator;
           AReader.SkipPropertyValue;
           end
        else if SameText(TempPropertyName,PERSISTENT_LOAD_NAME) then
           begin
           Result:=True;
           AReader.SkipPropertyName;
           AReader.SkipPropertySeparator;
           TempName:=AReader.ReadString;
           SetProperty(TempPropertyName,TempName);
           SetInstance(TempName,Self,True); <<<<<<<<<< Here
           end
        else
           Result:=inherited LoadProperty(AReader);
        end;
     end
  else
     Result:=inherited LoadProperty(AReader);
end;

SetInstance is an auto-magical runtime method of the base TObject class that handles this.  Plus, it does all of this before the OnCreate event is triggered for a form, so no more having to worry about that little issue from EWB 1.x.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Sep 24 2015 12:48 PMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> SetInstance is an auto-magical runtime method of the base TObject
> class that handles this.

Hmm, presumably if I manually edit the form I can break this then? I
did change the name in the wbf file though. Hmm, wonder why it wasn't
working. Or, perhaps it was actually, as I found another issue that was
the cause of what I was actually looking at. Ignore me on this then -
I'll go with the magic and my bug.

(Actually my bug was that I was testing for something being a TForm,
and of course it is a TDialog. I'm in two minds as to whether there
should be more hierarchy in the framework, so all "forms" have some
common ancestor, but who needs to be that fancy really?)

--

Matthew Jones
Thu, Sep 24 2015 1:02 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Hmm, presumably if I manually edit the form I can break this then? >>

It depends, what are you editing ?

<< (Actually my bug was that I was testing for something being a TForm, and of course it is a TDialog. I'm in two minds as to whether there should be more hierarchy in the framework, so all "forms" have some common ancestor, but who needs to be that fancy really?) >>

There *is* a common ancestor:

http://www.elevatesoft.com/manual?action=viewcomp&id=ewb2&comp=TFormControl

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Sep 24 2015 1:20 PMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> There is a common ancestor:
>
>
http://www.elevatesoft.com/manual?action=viewcomp&id=ewb2&comp=TFormControl

Ah, right, I guess I went past that in my trip through the help.
"Control" didn't give me the right impression, but I suppose a form is
really a control too. Thanks!

--

Matthew Jones
Image