Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Accessing components on another form
Mon, Feb 13 2012 7:31 PMPermanent Link

Paul Coshott

Avatar

Hi All,

Until embeddable forms are implemented, I thought I would simply position a
form (with no border) over a panel on the main form, by setting the left,
top, width and height to match the panel on the main form.
So I tried :

frmContact.Left := frmMain.panBody.Left;

but I get an error on panBody. Can anyone tell me how I can do this? I also
couldn't reference the Left property of the Main form either.

frmContact.Left := frmMain.Left;

gets an error on the second Left.

Thanks for any help,

Cheers,
Paul
Mon, Feb 13 2012 7:54 PMPermanent Link

Raul

Team Elevate Team Elevate

Paul,

I don't think the form components are publicly accessible (Tim might need to look into) like they are in Delphi.

Easiest workaround i can think of is to create a new public function or property for the class and then use it instead - since it's class function it can retrieve and set.

Assuming you want to keep the logic as is you could add a new public function to frmMain called something like "functionGetLeft():integer" and then all it does is "result:=panBody.left;";

Alternative is to create a public function in frmContact called maybe AlignToParent(Left,Right:integer) and then call that from frmMain with the appropriate parameters and call the show only after it (or as part of the function itself).

Raul


<<
"Paul Coshott" wrote:

Hi All,

Until embeddable forms are implemented, I thought I would simply position a
form (with no border) over a panel on the main form, by setting the left,
top, width and height to match the panel on the main form.
So I tried :

frmContact.Left := frmMain.panBody.Left;

but I get an error on panBody. Can anyone tell me how I can do this? I also
couldn't reference the Left property of the Main form either.

frmContact.Left := frmMain.Left;

gets an error on the second Left.

Thanks for any help,

Cheers,
Paul
>>
Mon, Feb 13 2012 9:04 PMPermanent Link

Paul Coshott

Avatar

Hi Raul,

thanks for the answer, but i must be thinking delphi too much. I can't get
this to compile. Could you show me the function and the line to call it?

Thanks heaps,
Paul


"Raul" wrote in message
news:D62EFCC6-36A5-43A0-94E6-03C0F096EAC9@news.elevatesoft.com...

Paul,

I don't think the form components are publicly accessible (Tim might need to
look into) like they are in Delphi.

Easiest workaround i can think of is to create a new public function or
property for the class and then use it instead - since it's class function
it can retrieve and set.

Assuming you want to keep the logic as is you could add a new public
function to frmMain called something like "functionGetLeft():integer" and
then all it does is "result:=panBody.left;";

Alternative is to create a public function in frmContact called maybe
AlignToParent(Left,Right:integer) and then call that from frmMain with the
appropriate parameters and call the show only after it (or as part of the
function itself).

Raul


<<
"Paul Coshott" wrote:

Hi All,

Until embeddable forms are implemented, I thought I would simply position a
form (with no border) over a panel on the main form, by setting the left,
top, width and height to match the panel on the main form.
So I tried :

frmContact.Left := frmMain.panBody.Left;

but I get an error on panBody. Can anyone tell me how I can do this? I also
couldn't reference the Left property of the Main form either.

frmContact.Left := frmMain.Left;

gets an error on the second Left.

Thanks for any help,

Cheers,
Paul
>>
Mon, Feb 13 2012 9:15 PMPermanent Link

Raul

Team Elevate Team Elevate

Paul,

Looks like GetLeft is used internally so you can't user (or need to override it at least) so here is a trivial sample:

in your frmMain define a new function with public visibility:

public
 function myLeft():integer;

and for implementation

function TMainForm.myLeft():integer;
begin
  result := frmMain.left;
end;


then in your other form just use :

 frmContactLeft := frmMain.myLeft();


See if this works

Raul



<<
"Paul Coshott" wrote:

Hi Raul,

thanks for the answer, but i must be thinking delphi too much. I can't get
this to compile. Could you show me the function and the line to call it?

Thanks heaps,
Paul
>>
Tue, Feb 14 2012 12:16 AMPermanent Link

Paul Coshott

Avatar

Hi Raul,

your code is basically exactly what I tried. In my main form :

//-------------------------------------------------------
  TafMain = class(TForm)
     pHeader: TPanel;
     pFooter: TPanel;
     pBody: TPanel;
     Label1: TLabel;
     ...
     ...
     bApplication: TButton;
     Label16: TLabel;
     procedure bContactClick(Sender: TObject);
  private
     { Private declarations }
  public
     { Public declarations }
     function pBodyLeft() : integer;
  end;

var
  afMain: TafMain;

implementation

function TafMain.pBodyLeft() : integer;
begin
  Result := pBody.Left;
end;
//-------------------------------------------------------

And in the contact form :

//-------------------------------------------------------
var
  fContact: TfContact;

implementation

uses Main;

procedure TfContact.fContactShow(Sender: TObject);
begin
 fContact.Left := afMain.pBodyLeft();
end;
//-------------------------------------------------------

The error I get is :
[Error] Contact.wbs (38,27): There is no function or procedure declaration
that matches the pBodyLeft() reference.

Any ideas? Maybe there is a problem with the scope?

Cheers,
Paul




"Raul" wrote in message
news:798C0AAB-7CCF-44F8-A494-265D65D250FD@news.elevatesoft.com...

Paul,

Looks like GetLeft is used internally so you can't user (or need to override
it at least) so here is a trivial sample:

in your frmMain define a new function with public visibility:

public
 function myLeft():integer;

and for implementation

function TMainForm.myLeft():integer;
begin
  result := frmMain.left;
end;


then in your other form just use :

 frmContactLeft := frmMain.myLeft();


See if this works

Raul



<<
"Paul Coshott" wrote:

Hi Raul,

thanks for the answer, but i must be thinking delphi too much. I can't get
this to compile. Could you show me the function and the line to call it?

Thanks heaps,
Paul
>>
Tue, Feb 14 2012 12:10 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Paul,

<< thanks for the answer, but i must be thinking delphi too much. I can't
get this to compile. Could you show me the function and the line to call it?
>>

Per email - sending me your project.  I'll post an update here as to what
the issue is, but I've tried the same thing here and it works fine.

--
Tim Young
Elevate Software
www.elevatesoft.com
Tue, Feb 14 2012 12:15 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Raul,

<< I don't think the form components are publicly accessible (Tim might need
to look into) like they are in Delphi. >>

That is correct - they are assumed to be "form private" in EWB, which is the
same as "private" for scope purposes.  The whole point is to try and bring
some discipline to some of the more lax scoping rules in Delphi's Object
Pascal.  IMO, there's *way* too much access to the private scope of an
object in Delphi.  Of course, it really all depends upon how this plays out
with *real* applications, so it is possible that this may change in the
future, especially if binding across forms is implemented in the design-time
environment (think data modules, etc.).

--
Tim Young
Elevate Software
www.elevatesoft.com
Image