Solved

Change button captions for the InputQuery function?

Posted on 2014-09-24
9
542 Views
Last Modified: 2014-09-28
Hi, is it possible to change the default button captions in the InputQuery function to something custom, besides the default "OK" and "Cancel" ?

Thanks!
   Shawn

P.S: I'm using D7.
0
Comment
Question by:shawn857
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 40343326
No, it's not possible. You can probably easily find the code of InputQuery() in the dialogs unit, copy it, and make changes to suit it to your needs.
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40343479
There's a trick how you can do that:

- Place a custom message into the Windows message queue before calling InputQuery
- in the message procedure you can search the form of the InputQuery and change everything you want...

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure WMCustomMessage(var message: TMessage); message WM_USER + 1024;
  end;

var
  Form1: TForm1;
  ValueString: string;

const
   ACaption = 'Caption';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 PostMessage(Handle, WM_USER + 1024, 0, 0);
 ValueString:='123';
 InputQuery(ACaption, 'Prompt', ValueString);
end;

procedure TForm1.WMCustomMessage(var message: TMessage);
 var
   s,c: Integer;
 begin
   for s := 0 to pred(Screen.FormCount) do
     if Screen.Forms[s].Caption = ACaption then begin
       for c := 0 to pred(Screen.Forms[s].ControlCount) do begin
         if Screen.Forms[s].Controls[c] is TButton then begin
           if TButton(Screen.Forms[s].Controls[c]).ModalResult=mrOK then begin
             TButton(Screen.Forms[s].Controls[c]).Caption:='Yes';
           end;
           if TButton(Screen.Forms[s].Controls[c]).ModalResult=mrCancel then begin
             TButton(Screen.Forms[s].Controls[c]).Caption:='No';
           end;
         end;
       end;
     end;
 end;

end.

Open in new window

0
 

Author Comment

by:shawn857
ID: 40345384
Thank you Thommy! Is there also a way to change the size (ie. width) of each button in the InputQuery? The text string I wish to put in each button seems to be too long for the width of the default button.

Thanks!
    Shawn
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:shawn857
ID: 40345389
... and also, is there a way to increase the size of the InputQuery box itself?

Thanks!
   Shawn
0
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 40345416
Yes, you can change everything...

procedure TForm1.WMCustomMessage(var message: TMessage);
 var
   s: Integer;
   c: Integer;
 begin
   for s := 0 to pred(Screen.FormCount) do
     if Screen.Forms[s].Caption = ACaption then begin
       //change width of InputQuery Box
       Screen.Forms[s].Width:=600;
       for c := 0 to pred(Screen.Forms[s].ControlCount) do begin
         if Screen.Forms[s].Controls[c] is TButton then begin
           if TButton(Screen.Forms[s].Controls[c]).ModalResult=mrOK then begin
             //Change position and width of OK-Button
             TButton(Screen.Forms[s].Controls[c]).Left:=(600-2*200) div 3;
             TButton(Screen.Forms[s].Controls[c]).Width:=200;
             TButton(Screen.Forms[s].Controls[c]).Caption:='This is the new caption for "OK"';
           end;
           if TButton(Screen.Forms[s].Controls[c]).ModalResult=mrCancel then begin
             //Change position and width of CANCEL-Button
             TButton(Screen.Forms[s].Controls[c]).Left:=2*(600-2*150) div 3+150;
             TButton(Screen.Forms[s].Controls[c]).Width:=200;
             TButton(Screen.Forms[s].Controls[c]).Caption:='This is the new caption for "CANCEL"';
           end;
         end;
       end;
     end;
 end;

Open in new window

0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 40345469
At start it is fine to use built in functions like InputQuery - but on a long term - I suggest to bild own dialog form - which will do all you want - and you can reuse it in other form/applications.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 40345533
I agree with Sinisa
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 40347724
yeah build your own, you'll end up spending more time on customizing the standard than building your own
0
 

Author Closing Comment

by:shawn857
ID: 40348932
Works fine, thank you Thommy!

Cheers
    Shawn
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now