Change InputQuery box size

5

The InputQuery is a message where we can inform a certain value, but changing the value of the variable passed as reference, see its structure:

//Função InputQuery 
function InputQuery(const ACaption, APrompt: string;
  var Value: string): Boolean;

I wanted to know if there is any way to decrease the size of the InputQuery message window?

    
asked by anonymous 27.04.2018 / 19:17

1 answer

7

This function does not have a overload that makes this available, the way is to make one.

I have several ready-made in my system for several formats, be it String, Extended, Integer, Dates etc ...

Here's an example:

function TFormTeste.InputValor(const aCaption: String; var aValor: String): Boolean;
var
  vForm  : TForm;
  vLabel : TLabel;
  vBtnOk : TBitBtn;
  vValor : TEdit;
begin
  Result  := False;
  vForm   := TForm.Create(Application);
  vLabel  := TLabel.Create(vForm);
  vBtnOk  := TBitBtn.Create(vForm);
  vValor  := TEdit.Create(vForm);

  with vForm do
  begin
    Name           := 'FormValor';
    Position       := poScreenCenter;
    BorderIcons    := [biSystemMenu];
    BorderStyle    := bsSingle;
    Caption        := aCaption;
    ClientHeight   := 70;
    ClientWidth    := 180;
    Color          := clBtnFace;
    OldCreateOrder := False;
    PixelsPerInch  := 96;
  end;

  with vLabel do
  begin
    Name    := 'vLabel';
    Parent  := vForm;
    Left    := 8;
    Top     := 16;
    Width   := 31;
    Height  := 13;
    Caption := 'Valor: ';
  end;

  with vValor do
  begin
    Name      := 'vValorEdit';
    Parent    := vForm;
    Left      := 52;
    Top       := 11;
    Width     := 120;
    Height    := 21;
    TabOrder  := 0;
  end;

  with vBtnOk do
  begin
    Name        := 'vBtnOk';
    Parent      := vForm;
    Caption     := 'Ok';
    Left        := vValor.Left;
    Top         := vValor.Top + vValor.Height + 5;
    Width       := vValor.Width;
    Height      := 21;
    ModalResult := mrOk;
  end;

  vForm.ShowModal;

  if(vForm.ModalResult = mrOk) and
    (vValor.Text <> '') then
  begin
    Result := True;
    aValor := vValor.Text;
  end;

  FreeAndNil(vForm);
end;

Use in the same way as the Official:

var
  vTeste : String;
begin
  if (InputValor('Informe um texto', vTeste) = True) then
    ShowMessage(vTeste);
    
27.04.2018 / 19:37