Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing text in dialog buttons

Posted on 2002-03-05
5
Medium Priority
?
213 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
[X]
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
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 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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