| View previous topic :: View next topic |
| Author |
Message |
Rashid Guest
|
Posted: Fri Jan 16, 2004 8:33 am Post subject: Variables to form |
|
|
hi
i got a standard application; a main form calling other several forms.
the thing is i need to pass somekind of variables from the main form to the
other forms.
using a global variable in the calling form seems to solve the problem
but the child form needs to know which is the form calling it.
this is bec a single form can be called by more than 1 form.
thus the only practical way is to pass parameters to the form.
but how do i modify a created forms to accept these variables?
rashid
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Fri Jan 16, 2004 10:22 am Post subject: Re: Variables to form |
|
|
On Fri, 16 Jan 2004 16:33:56 +0800, "Rashid" <mra (AT) pacific (DOT) net.sg>
wrote:
| Quote: | hi
i got a standard application; a main form calling other several forms.
the thing is i need to pass somekind of variables from the main form to the
other forms.
using a global variable in the calling form seems to solve the problem
but the child form needs to know which is the form calling it.
this is bec a single form can be called by more than 1 form.
thus the only practical way is to pass parameters to the form.
but how do i modify a created forms to accept these variables?
rashid
|
I suggest that you think about supplying your Child Forms with Events
that the Parent sets up
- so the Child Forms can ask the Parent for data without knowing
anything about it
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Fri Jan 16, 2004 7:53 pm Post subject: Re: Variables to form |
|
|
"Rashid" <mra (AT) pacific (DOT) net.sg> wrote
| Quote: | i got a standard application; a main form calling other several forms.
the thing is i need to pass somekind of variables from the main form
to the other forms.
using a global variable in the calling form seems to solve the problem
but the child form needs to know which is the form calling it. this is
bec a single form can be called by more than 1 form. thus the only
practical way is to pass parameters to the form. but how do i modify
a created forms to accept these variables?
|
You say that a form "calls" another form. Add a parameter to that call.
Mimicking how events are commonly done, you might add one named "Sender"
at the beginning. (There may be _no_ parameters to the call now. That
doesn't mean you can't add any.)
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Fri Jan 16, 2004 10:56 pm Post subject: Re: Variables to form |
|
|
"Rashid" <mra (AT) pacific (DOT) net.sg> wrote
| Quote: | hi
i got a standard application; a main form calling other several forms.
the thing is i need to pass somekind of variables from the main form to
the
other forms.
using a global variable in the calling form seems to solve the problem
but the child form needs to know which is the form calling it.
this is bec a single form can be called by more than 1 form.
thus the only practical way is to pass parameters to the form.
but how do i modify a created forms to accept these variables?
rashid
|
Presuming the 'child' forms are being created by the caller, as opposed to
being created automatically, try something like
Type
tChildForm = class (tForm)
. . .
private
fWhoCalledMe : tForm;
public
class function NewForm (byWho : tForm) : tChildForm;
. . .
end;
class function tChildForm.NewForm (byWho : tForm) : tChildForm;
begin
result := tChildForm.Create (Application);
result.fWhoCalledMe := byWho;
result.Show;
end;
or something like
Type
tChildForm = class (tForm)
. . .
private
fWhoMadeMe : tForm;
public
constructor CreateEx (aOwner : tComponent; byWho : tForm);
. . .
end;
constructor tChildForm.CreateEx (aOwner : tComponent; byWho : tForm);
begin
Create (aOwner);
fWhoMadeMe := byWho;
end;
|
|
| Back to top |
|
 |
Richard Haven Guest
|
Posted: Fri Feb 06, 2004 3:24 pm Post subject: Re: Variables to form |
|
|
Or just create a new property of the child form and have the Parent (or
anyone else) set it.
For example, put a CustomerID property on a form. The mutator ("setter")
will do a search in a table to synchronize the data-aware controls on
that form. The property's accessor ("getter") just returns the value
from the DataSet or the linked control.
Remember: "Forms are classes too"
Cheers
Bruce Roberts wrote:
| Quote: | "Rashid" <mra (AT) pacific (DOT) net.sg> wrote in message
news:bu868t$rrs$1 (AT) reader01 (DOT) singnet.com.sg...
hi
i got a standard application; a main form calling other several forms.
the thing is i need to pass somekind of variables from the main form to
the
other forms.
using a global variable in the calling form seems to solve the problem
but the child form needs to know which is the form calling it.
this is bec a single form can be called by more than 1 form.
thus the only practical way is to pass parameters to the form.
but how do i modify a created forms to accept these variables?
rashid
Presuming the 'child' forms are being created by the caller, as opposed to
being created automatically, try something like
Type
tChildForm = class (tForm)
. . .
private
fWhoCalledMe : tForm;
public
class function NewForm (byWho : tForm) : tChildForm;
. . .
end;
class function tChildForm.NewForm (byWho : tForm) : tChildForm;
begin
result := tChildForm.Create (Application);
result.fWhoCalledMe := byWho;
result.Show;
end;
or something like
Type
tChildForm = class (tForm)
. . .
private
fWhoMadeMe : tForm;
public
constructor CreateEx (aOwner : tComponent; byWho : tForm);
. . .
end;
constructor tChildForm.CreateEx (aOwner : tComponent; byWho : tForm);
begin
Create (aOwner);
fWhoMadeMe := byWho;
end;
|
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Fri Feb 06, 2004 8:05 pm Post subject: Re: Variables to form |
|
|
"Richard Haven" <RichardH (AT) SPAMFREEsantacruzsoftware (DOT) com> wrote
[...]
| Quote: | For example, put a CustomerID property on a form.[...]
Remember: "Forms are classes too"
|
I am getting visions now of a new VCL component, the TProperty.
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
|