Change Inputquery Box Size

Asked

Viewed 801 times

6

The InputQuery is a message where we can enter 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 was wondering if there’s any way to shrink the message window InputQuery?

Foto

1 answer

8


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

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

Following 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);
  • 1

    Oops! That’s good... I’ll test...

  • It’s getting good so I can get the size I want. Thank you!

  • Solving the problem, mark the answer as correct, this helps future researchers.

  • 1

    If you put another button ex: Cancel as you do to click cancel all?

  • 1

    Create a button = done with OK, and on ModalResult := mrCancel, ai you test at the time of assigning the variable if the Modalresult was an Ok

  • I did it only that it’s working like OK

  • I think it’s on account of if (vValor.Text <> '') then&#xA; begin&#xA; Result := True;&#xA; aValor := vValor.Text;&#xA; end;

  • before the if (vValor.Text <> '') place: if ModalResult = MrOk then...

  • won’t, Modalresult always stays = 0

  • I edited the answer, is that you were not pointing to the Form, ai Result is always 0.

  • Thanks! It was really good

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.