Solved

Changing text in dialog buttons

Posted on 2002-03-05
5
178 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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