Solved

Change button captions for the InputQuery function?

Posted on 2014-09-24
9
521 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

21 Experts available now in Live!

Get 1:1 Help Now