Mega Code Archive

 
Categories / Delphi / Examples
 

Componentcreate

>Task: create a set of standard dialog components for the our developers. >these comps should be actual components (not forms wrapped inside of >components). they need to have an execute method (among other things) and >work similar to the standard dialog components on the Dialogs tab for D5. >Question: how does one do this without resorting to wrapping a form inside >of a component ? I have a form which is being dynamically created within a class. I guess, for a component there should be no difference... Here is the stripped sample: TISFields = class(TObject) private SortForm: TForm; XMargin, YMargin: Integer; procedure ButtonOkClick(Sender: TObject); public constructor Create; destructor Destroy; override; function SortDialog: Boolean; end; constructor TISFields.Create; begin XMargin := 10; YMargin := 10; end; destructor TISFields.Destroy; begin inherited Destroy; end; function TISFields.SortDialog: Boolean; var aButton: TButton; begin SortForm := TForm.Create(Application); with SortForm do begin Name := 'formISSort'; Position := poScreenCenter; Caption := 'Select Fields for Sorting'; BorderStyle := bsDialog; BorderIcons := []; ClientHeight := 200; // Set it to what it should be in your case ClientWidth := 300; // end; // Do whatever you need to do and populate window with controls // similar to how Ok and Cancel buttons are created below aButton := TButton.Create(SortForm); with aButton do begin Parent := SortForm; Name := 'formISSortOKButton'; Caption := '&OK'; Default := True; Height := 21; Left := SortForm.ClientWidth - Width - XMargin; Top := SortForm.ClientHeight - Height - YMargin; ModalResult := mrOk; OnClick := ButtonOkClick; end; aButton := TButton.Create(SortForm); with aButton do begin Parent := SortForm; Name := 'formISSortCancelButton'; Caption := '&Cancel'; Cancel := True; Height := 21; Left := SortForm.ClientWidth - (Width + XMargin) * 2; Top := SortForm.ClientHeight - Height - YMargin; ModalResult := mrCancel; end; if SortForm.ShowModal = mrOk then Result := True else Result := False; // Clean up SortForm.Release; end; procedure TISFields.ButtonOkClick(Sender: TObject); begin // Do whatever you have to do end; Hope I didn't miss anything... If you need any more details, please let me know.