For instance, you open a dialog box to allow the user to set a few parameters
I discuss several ways to do this under Application Parameters, data can also be passed via a database.
This page addresses directly reading and writing data from one form to another. CustomDialogBoxes.html provides several ways to directly read and write data from one form to another in MS Access and other VisualBasic based languages. In particular, the Form.Tag technique is applicable to most windows languages.
Delphi 5.0
If all the parameters are stored in an ini-class, you could just pass a pointer to that class and let the second form handle reading and writing the parameters. A callback method might still be used to tell the original form that new parameters are available.
You could pass a single integer parameter via the form's Tag
parameter.
This is a convenient way to indicate which button was pressed on
a
Modal Forms
This example (based on the Delphi 5 help - TCustomForm.ShowModal example) shows how to
procedure TForm1.Button1Click(Sender: TObject); begin MyDialogBox1.Edit1.Text := LocalVariable; // Initialize a field in the dialog bax if MyDialogBox1.ShowModal = mrOK then begin LocalVariable := MyDialogBox1.Edit1.Text; // Get data from the form end; end;In your dialog box, attatch this code to your buttons.
procedure TMyDialogBox.OKButtonClick(Sender: TObject); begin ModalResult := mrOK; end; procedure TMyDialogBox.CancelButtonClick(Sender: TObject); begin ModalResult := mrCancel; end;Remeber, simply setting ModalResult hides the dialog box and returns execution to the calling form.
Callback Example
type TStringCallback = procedure(const S: string) of object; TNamedShapes_UIForm = class(TForm) CrystalForms_UIRadioGroup: TRadioGroup; Close_UIButton: TButton; procedure Close_UIButtonClick(Sender: TObject); procedure CrystalForms_UIRadioGroupClick(Sender: TObject); private { Private declarations } FShowCrystal: TStringCallback; public { Public declarations } property ShowCrystal: TStringCallback read FShowCrystal write FShowCrystal ; end; implementation procedure TNamedShapes_UIForm.Close_UIButtonClick(Sender: TObject); begin hide; end; procedure TNamedShapes_UIForm.CrystalForms_UIRadioGroupClick( Sender: TObject); var temp:string; begin case CrystalForms_UIRadioGroup.ItemIndex of 0: temp := '100 1'; 1: temp := '111 1'; 2: temp := '110 1'; 3: temp := '120 1'; 4: temp := '122 1'; 5: temp := '112 1'; 6: temp := '123 1'; end; if Assigned(FShowCrystal) then // always test before calling a callback FShowCrystal(temp); end;In the main form, this sets the callback and displays the form.
NamedShapes_UIForm.ShowCrystal := DisplayIndices;// Set callback NamedShapes_UIForm.Show;Author: Robert Clemenzi - clemenzi@cpcug.org