?
Solved

Change button captions for the InputQuery function?

Posted on 2014-09-24
9
Medium Priority
?
636 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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 27

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 38

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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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