Solved

Changing text in dialog buttons

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

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

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…
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

20 Experts available now in Live!

Get 1:1 Help Now