Board index » delphi » forms controling each others objects!

forms controling each others objects!

Please help. I have a main form and from this you can open an 'options'
form. I want this options form to be able to control objects on the main
form ie make labels visible etc. I have declared the forms units in the
implementation part of both units with the 'uses' statement. However,
when I then write a line of code to to change an object's (in the main
form's) properties it says 'unknown identifier'. What am I doing wrong?

Cheers
Pete

 

Re:forms controling each others objects!


hi

if your not you should  create a unit to hold only Global variables.

If you already are then you're possibly delcaring a variable that needs another
file for reference.

E.G

Stdctrls,extctrls,dialogs,forms,classes..etc

These have to be in your uses statement if
you're using any of their features.

Look in the help file for your declarations to see what unit it uses

hope this helps

Re:forms controling each others objects!


In article <36E95740.E0CAF...@{*word*269}.net>, peter.mulfo...@{*word*269}.net says...

Quote

>Please help. I have a main form and from this you can open an 'options'
>form. I want this options form to be able to control objects on the main
>form ie make labels visible etc. I have declared the forms units in the
>implementation part of both units with the 'uses' statement. However,
>when I then write a line of code to to change an object's (in the main
>form's) properties it says 'unknown identifier'. What am I doing wrong?

I suspect you did not include the unit name of the main form when trying to
change objects from another unit.

Example say you have a form MainForm in unit MainUnit, and you open an options
form, OptionsForm, to control objects in MainForm. In OptionsForm you can click
a button to make a label (Label1) on MainForm invisible:

implementation;

uses MainUnit;

TOptionsForm.Button1Click(sender : TObject);
begin
  MainUnit.MainForm.Label1.Visible := false;
end;

--
Christo Crause
Thermal Separations Research
University of Stellenbosch
South Africa

Re:forms controling each others objects!


You must supply a sample...
I can only guess you're trying to use the components of Form1 directly. You
must use a complete object reference. If Form1 has Label1, in Form2 you
can't write "label1.caption:='foo'" because Label1 is not declared in Form2
! Adding Unit1 (Form1) in Unit2 (Form) gives you only access to public
variables and objets, so to Form1.
Thus, you must must write Form1.Label1.caption := 'foo'.
This is an OOP understanding problem.

|Please help. I have a main form and from this you can open an 'options'
|form. I want this options form to be able to control objects on the main
|form ie make labels visible etc. I have declared the forms units in the
|implementation part of both units with the 'uses' statement. However,
|when I then write a line of code to to change an object's (in the main
|form's) properties it says 'unknown identifier'. What am I doing wrong?
|
|Cheers
|Pete
|

Other Threads