Board index » delphi » How to set object properties on a different form

How to set object properties on a different form

I have the following problem that has bugged me for days, so I finally
decided I need help.

My project consists of a form 'MainForm' and the corresponding unit
'MainUnit'. On 'MainForm' is a button named 'SettingsButton'. If you click
this button a new form is created called 'SettingsForm' using the ShowModal
method. 'SettingsForm' has a corresponding unit called 'SettingsUnit'. On
'SettingsForm' there is a EditBox named 'DataBox'.
I want 'DataBox' to be filled with text from a variable that got its default
value in the MainUnit. The user can then change the data in 'DataBox' and
after closing 'SettingsForm' I want to read the data in the 'MainUnit' for
further processing.

To accomplish this I have included 'SettingsUnit' in 'MainUnit's uses clause
(in the interface part). This way I can read the 'DataBox.text' property
from 'MainUnit' without any problem. But if I try to store the value of a
variable from 'MainUnit' in the 'DataBox.text' property I get an unknown
identifier error. If I add 'MainUnit' to the 'SettingsUnit's uses clause
(implementation part - to avoid circular references) I get a general
protection error.

Please help

RButter...@skynet.be

 

Re:How to set object properties on a different form


Ron,

what you are trying to do has two solutions.

1) in your uses-clause of MainForm, you put in SettingsForm, and beneath the
implementation-section of your SettingsForm you add Uses MainForm.

In this way you have access to both the units.

2) Preferred: you could use a calling function (or procedure) in your
SettingsForm. In this calling function you pass your parameter with the var
statement. When you call the function from your MainForm you pass your
variable as a parameter of your settings-calling function.

In this way, your code remains re-usable for other applications.

I can send you an example of this, if you like. It is a little bit more
complicated than the first suggestion, but when you get used to it, it is
very easy.

Sincerely,

Fred Jansma.

Quote
Ron Butterman wrote in message <6sf4bh$29...@news1.skynet.be>...
>I have the following problem that has bugged me for days, so I finally
>decided I need help.

>My project consists of a form 'MainForm' and the corresponding unit
>'MainUnit'. On 'MainForm' is a button named 'SettingsButton'. If you click
>this button a new form is created called 'SettingsForm' using the ShowModal
>method. 'SettingsForm' has a corresponding unit called 'SettingsUnit'. On
>'SettingsForm' there is a EditBox named 'DataBox'.
>I want 'DataBox' to be filled with text from a variable that got its
default
>value in the MainUnit. The user can then change the data in 'DataBox' and
>after closing 'SettingsForm' I want to read the data in the 'MainUnit' for
>further processing.

Other Threads