Author: Tomas Rutkauskas
I need a function to show a form and getting back a value, like InputBox or
similar. How can I do this?
Answer:
1 type2 TMyForm {set positions and captions as you desire}3 Edit1: TEdit;
4 ButtonOK: TBitBtn; {set Kind property to bkOK}5 ButtonCancel: TBitBtn; {set Kind property to bkCancel}6 private7 public8 end;
9 10 {var MyForm:TMyForm; I do not use it, so I get rid of it}11 12 function GetMyValue: string;
13 14 implementation15 16 function GetMyValue(DefaultValue: string): string;
17 {not part of the TMyForm class}18 begin19 with TMyForm.Create(Application) do20 try21 result := TMyValue.Create;
22 result := DefaultValue;
23 Edit1.Text := DefaultValue;
24 if ShowModal = mrOK then25 result := Edit1.Text;
26 finally27 Release;
28 end;
29 end;