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