Board index » delphi » Need help passing paramaters between two forms

Need help passing paramaters between two forms

Just out of curiousity, what properties are you talking about?  I would like
to know what you are talking about specifically.  Essentially by declaring
these "variables" within the public section of the modal form, you are
creating new properties to be accessed.  Unless you are talking about
existing properties, I dont see how you would implement your idea.  There
isnt anything pre-existing in the TForm object that would aid in the sending
and receiving of parameters... or are there?  Please give me more
specifics... I would like to know what you are talking about.

Steve Kothenbeutel
spo...@tetralogic.com

Quote
Shai'Dar <m.heerd...@wxs.nl> wrote in message

news:82ambo$11rd6$1@reader2.wxs.nl...
Quote
> Why use variables.
> I'm not that good in Delphi, but with 10 years of programming, I think you
> can
> better use Properies and store the values of the variables in them.
> It defaults to the same as using variables, but it's a hell of a lot
better
> implemented.

> (not that I'm implying your solution is bad).

> --
> Demons will rip out your soul
> Your flesh starts to rot from your bones
> Fear and Terror run wild
> when you speak my name
> m.heerd...@wxs.nl [Shai'Dar]
> Steven Kothenbeutel heeft geschreven in bericht
> <93324.563$nu.28...@newsread2.prod.itd.earthlink.net>...
> >Well, you do realize that you can refer back to the main form by its name
> in
> >Delphi?

> >Furthermore, you could just create some variable in the modal form to
hold
> >the passed parameters (colors) from the main form.  If it is always just
> >three colors, you could use an array declared within the public section
of
> >the modal form.

> >As for the button that the colors originated from, you could also define
a
> >variable in the modal form to hold the name of that button from the main
> >form.  This would be my way of doing it.

> >here are the declarations within the public section of the modal form:

> >public
> >     colors: array[1..3] of word;
> >     buttonname: string;

> >You would then assign values for these variables within the button
onclick
> >event handlers.

> >(1) you would assign the modal form's buttonname property:
> >modalform.buttonname := 'button1';
> >(2) you would assign the colors into the array: modalform.colors[0] :=
> >clwhite, etc....
> >(3) then you would bring up the modalform with the showmodal method.

> >I hope this helps you.  It may not be the best way to do it... but it is
> the
> >way I would do it.

> >Steve Kothenbeutel
> >spo...@tetralogic.com

 

Re:Need help passing paramaters between two forms


Well, It's like you said.
Declare your own properties in the public section.

--
Demons will rip out your soul
Your flesh starts to rot from your bones
Fear and Terror run wild
when you speak my name
m.heerd...@wxs.nl [Shai'Dar]
Steven Kothenbeutel heeft geschreven in bericht
<82c0uq$hc...@oak.prod.itd.earthlink.net>...

Quote
>Just out of curiousity, what properties are you talking about?  I would
like
>to know what you are talking about specifically.  Essentially by declaring
>these "variables" within the public section of the modal form, you are
>creating new properties to be accessed.  Unless you are talking about
>existing properties, I dont see how you would implement your idea.  There
>isnt anything pre-existing in the TForm object that would aid in the
sending
>and receiving of parameters... or are there?  Please give me more
>specifics... I would like to know what you are talking about.

>Steve Kothenbeutel
>spo...@tetralogic.com

>Shai'Dar <m.heerd...@wxs.nl> wrote in message
>news:82ambo$11rd6$1@reader2.wxs.nl...
>> Why use variables.
>> I'm not that good in Delphi, but with 10 years of programming, I think
you
>> can
>> better use Properies and store the values of the variables in them.
>> It defaults to the same as using variables, but it's a hell of a lot
>better
>> implemented.

>> (not that I'm implying your solution is bad).

>> --
>> Demons will rip out your soul
>> Your flesh starts to rot from your bones
>> Fear and Terror run wild
>> when you speak my name
>> m.heerd...@wxs.nl [Shai'Dar]
>> Steven Kothenbeutel heeft geschreven in bericht
>> <93324.563$nu.28...@newsread2.prod.itd.earthlink.net>...
>> >Well, you do realize that you can refer back to the main form by its
name
>> in
>> >Delphi?

>> >Furthermore, you could just create some variable in the modal form to
>hold
>> >the passed parameters (colors) from the main form.  If it is always just
>> >three colors, you could use an array declared within the public section
>of
>> >the modal form.

>> >As for the button that the colors originated from, you could also define
>a
>> >variable in the modal form to hold the name of that button from the main
>> >form.  This would be my way of doing it.

>> >here are the declarations within the public section of the modal form:

>> >public
>> >     colors: array[1..3] of word;
>> >     buttonname: string;

>> >You would then assign values for these variables within the button
>onclick
>> >event handlers.

>> >(1) you would assign the modal form's buttonname property:
>> >modalform.buttonname := 'button1';
>> >(2) you would assign the colors into the array: modalform.colors[0] :=
>> >clwhite, etc....
>> >(3) then you would bring up the modalform with the showmodal method.

>> >I hope this helps you.  It may not be the best way to do it... but it is
>> the
>> >way I would do it.

>> >Steve Kothenbeutel
>> >spo...@tetralogic.com

Re:Need help passing paramaters between two forms


Although it might seem easier to let your dialog form know about your main
form this isn't necessarily a good idea because you break the encapsulation
(it just tends too complicate the code later on when you make a change, it
also means you couldn't reuse the dialog for another project or form).

Something like the following would be better practice:
On your dialog create 3 private variables:
fRefColor1, fRefColor2,fRefColor3 of type tColor;
and 3 public, read-only properties: SelectedColor1, SelectedColor2,
SelectedColor3 which
return the selected colours:

(It might actually be better to use array properties and arrays for storage
since you could then change the number of colors fairly easily)

function GetColors(RefColor1, RefColor2, RefColor3:tColor):integer;
begin
  fRefColor1 := RefColor1;
 fRefColor2 := RefColor2;
 fRefColor3 := RefColor3;
result := ShowModal;
end;

You would also create 2 buttons on the dialog form:
  one with ModalResult set to mrOK and the other with ModalResult set to
mrCancel.

In your calling form:
procedure Button1Click(sender:tObject);
begin
  with MyColorDialogForm do
    if GetColors(Color1, Color2, Color3) = mrOK then
      begin
         Color1 := SelectedColor1;
        Color2 := SelectedColor2;
        Color3 := SelectedColor3;
      end;
end;

Marc Rohloff

Quote
Mark Edwards <medwa...@onramp.net> wrote in message

news:qe9h4s0sek902pemo3sjsr03g3l1ani6uq@4ax.com...

My project has two forms. The main form calls a modal form, in which I
select three colors.

I need to be able to pass three colors from the main form (for
comparison to the selected colors), and a reference to the button on
the main form that was clicked, so I know where the colors came from
on the main form.

Then I need to pass the three selected colors on the modal form back
to the main form so they can be appropriately changed.

I simply can't get my mind wrapped around how to approach this, and
could use some clues on how to proceed. Now watch it be something so
simple that I'll be embarrassed to have missed it (grin).

Thanks in advance.

Mark Edwards
------------
"...Besides, the other tobacco companies hate you and think you're ugly"
- message on the Brown & Williamson tobacco company consumer line

Other Threads