How to close TCalculatorDialog programmaticaly? lazarus / 8-Other ---------------------------------------------------------------------- vrull · 2008-06-20 21:24 It may sound strange, but neither CalculatorDialog1.Close nor CalculatorDialog1.ModalResult := mrOK works. I am confused. ---------------------------------------------------------------------- vrull · 2008-06-22 04:04 Found the following solution: the dialog has the only child component - unnamed form, so one has to close this form. Code: [Select] procedure TFormEntry.CalculatorDialog1CalcKey(Sender: TObject; var Key: char); var   nKey : integer;   Form : TCustomForm; begin   with Sender as TCalculatorDialog do     begin       nKey := Ord(Key);       if (nKey = Tag) and (nKey in [61, 67]) then         begin           Form := FindDialogForm(Sender as TCalculatorDialog);           if Form <> nil then             if nKey = 61 then  Form.ModalResult := mrOk             else Form.ModalResult := mrCancel;         end;       Tag := nKey;     end; end; The aim of the above code is to close the dialog if either Return (ModalResult := mrOk) or Escape pressed twice. First press performs the default action (they are converted to "=" for Return or to "C" for Escape internally). The Key code is stored in the dialog's Tag property. This is how to find the form (just in case that there is something else in the dialog): Code: [Select] function TFormEntry.FindDialogForm(aDialog : TCommonDialog) : TCustomForm; var   i : integer; begin   Result := nil;   with aDialog do     for i := 0 to ComponentCount - 1 do       if Components[i] is TCustomForm then Result := TCustomForm(Components[i]); end;