How to create a function which returns a value from a form (Views: 29)
Problem/Question/Abstract: I need a function to show a form and getting back a value, like InputBox or similar. How can I do this? Answer: type TMyForm {set positions and captions as you desire} Edit1: TEdit; ButtonOK: TBitBtn; {set Kind property to bkOK} ButtonCancel: TBitBtn; {set Kind property to bkCancel} private public end; {var MyForm:TMyForm; I do not use it, so I get rid of it} function GetMyValue: string; implementation function GetMyValue(DefaultValue: string): string; {not part of the TMyForm class} begin with TMyForm.Create(Application) do try result := TMyValue.Create; result := DefaultValue; Edit1.Text := DefaultValue; if ShowModal = mrOK then result := Edit1.Text; finally Release; end; end; |