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
Solved

Change button captions for the InputQuery function?

Posted on 2014-09-24
9
563 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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