Solved

Changing text in dialog buttons

Posted on 2002-03-05
5
177 Views
Last Modified: 2010-04-05
I'm using the  function MessageDlg in a multilingual application - how can I change the text in the button (like it is possible for ShortMonthNames[1])

Possibly some variable that can be set.
0
Comment
Question by:ymailhot
5 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6843066
why not use Application.MessageBox() as the text
for its buttons is defined at run time based on the regional settings of the users computer.this would be better than MessageDlg()

otherwise i suppose you could use stringtables in the resource file and get user to "set" the language at install time and hold it in a .ini or registry key.then you can check it at runtime to see what language to load from your resources.

also you may be aware there are some components available for multilanguage apps,maybe they are of use.
www.torry.net etc have some..
0
 

Expert Comment

by:ePing
ID: 6843095
MessageBox(0, 'Hello World', 'Title', MB_OK + MB_ICONINFORMATION);
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6844395
You could do it like this:

function MessageDlg(const Msg, ButtonText : string;  DlgType : TMsgDlgType;
  Buttons : TMsgDlgButtons; HelpCtx : Longint) : Integer;
var
  I : Integer;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
  begin
    try
      HelpContext := HelpCtx;
      for I := 0 to ComponentCount - 1 do
      begin
        if (Components[I] is TButton) then
          TButton(Components[I]).Caption := ButtonText;
      end;
    Result := ShowModal ;
    finally
      Free ;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Messagedlg('hello', 'Test Button', mtInformation, [mbOk], 0);
end;

Cheers,

Alan
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 200 total points
ID: 6844447
You would use the above example like:

Messagedlg('Test...', ShortMonthNames[1], mtInformation, [mbOk], 0);

This would change all the buttons in the message though. If you would like to change several buttons then I would do something like below:

procedure TForm1.Button1Click(Sender: TObject);
var
  I : Integer;
begin
  with CreateMessageDialog('hello', mtInformation, [mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbHelp]) do
  begin
    try
      HelpContext := 0;
      for I := 0 to ComponentCount - 1 do
      begin
        if (Components[I] is TButton) then
        begin
          if Components[I].Name = 'Yes' then
            TButton(Components[I]).Caption := ShortMonthNames[1];
          if Components[I].Name = 'No' then
            TButton(Components[I]).Caption := ShortMonthNames[2];
          if Components[I].Name = 'OK' then
            TButton(Components[I]).Caption := ShortMonthNames[3];
          if Components[I].Name = 'Cancel' then
            TButton(Components[I]).Caption := ShortMonthNames[4];
          if Components[I].Name = 'Abort' then
            TButton(Components[I]).Caption := ShortMonthNames[5];
          if Components[I].Name = 'Retry' then
            TButton(Components[I]).Caption := ShortMonthNames[6];
          if Components[I].Name = 'Ignore' then
            TButton(Components[I]).Caption := ShortMonthNames[7];
          if Components[I].Name = 'All' then
            TButton(Components[I]).Caption := ShortMonthNames[8];
          if Components[I].Name = 'Help' then
            TButton(Components[I]).Caption := ShortMonthNames[9];
        end;
      end;
      ShowModal;
    finally
      Free;
    end;
  end;
end;
0
 

Author Comment

by:ymailhot
ID: 6844747
That should work, thank you
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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