Solved

Changing text in dialog buttons

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

22 Experts available now in Live!

Get 1:1 Help Now