Solved

Change button captions for the InputQuery function?

Posted on 2014-09-24
9
498 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
 

Author Comment

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

Thanks!
   Shawn
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 25

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 36

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

18 Experts available now in Live!

Get 1:1 Help Now