InputBox function

Future<String> InputBox(
  1. String ACaption,
  2. String APrompt,
  3. String ADefault
)

Implementation

Future<String> InputBox(String ACaption, String APrompt, String ADefault) async
{
  var form = TForm(Screen.FocusedForm==null? Application : Screen.FocusedForm);
  form.BorderStyle = TBorderStyle.Dialog;
  form.Position = TPosition.OwnerFormCenter;
  form.Caption = ACaption;
  form.Width = 300;

  int top = 10;
  int width = form.ClientWidth-10;
  var label = TLabel(form)
    ..SetBounds(5, top, width, null)
    ..Caption = APrompt
    ..Parent = form;

  top+=label.Height+2;

  var edit = TEdit(form);
  edit
    ..SetBounds(5, top, width, null)
    ..Text = ADefault
    ..Parent = form;

  top+=edit.Height + 20;

  int btnLeft = (width-160)~/2;
  var btnOk = TButton(form)
    ..Caption = '${ SysLocaleDialogs.result(TModalResult.Ok) }'
    ..SetBounds(btnLeft, top, 80, null)
    ..ModalResult = TModalResult.Ok
    ..Parent = form;

  TButton(form)
    ..Caption = '${ SysLocaleDialogs.result(TModalResult.Cancel) }'
    ..SetBounds(btnLeft+90, top, 80, null)
    ..ModalResult = TModalResult.Cancel
    ..Parent = form;

  top+=btnOk.Height + 10;

  form.ClientHeight = top;

  if(await form.ShowModal() == TModalResult.Ok)
    ADefault = edit.Text;
  return ADefault;
}