View Issue Details

IDProjectCategoryView StatusLast Update
0019757LazarusLCLpublic2011-07-26 12:33
ReporterBart BroersmaAssigned ToMaxim Ganetsky 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWinMeOS VersionMS
Product Version0.9.31 (SVN)Product Buildr31473M 
Target Version0.9.31 (SVN)Fixed in Version0.9.31 (SVN) 
Summary0019757: Patch for CreateMessageDlg: caption now uses correctly translated resourcestring
DescriptionIf you use the CreateMessageDlg function and use TranslateUnitResourceStrings to translate the lclstrconsts resource strings, then the resulting dialog will still have English captions ('Error','Warning' etc.)

This is because the caption is set using a constant array of resourcestrings (introduced (by me) in r18142).
This array does not get updated if one uses TranslateUnitResourceSrings (from translation unit).

I changed the static array to a function call (see attached patch).
TagsNo tags attached.
Fixed in Revision31727, 31738, 31748
LazTarget-
WidgetsetGTK, GTK 2, Win32/Win64, WinCE, Carbon, Cocoa, QT, fpGUI
Attached Files
  • dialogs.msgdlgscaptions.diff (1,578 bytes)
    Index: lcl/dialogs.pp
    ===================================================================
    --- lcl/dialogs.pp	(revision 31484)
    +++ lcl/dialogs.pp	(working copy)
    @@ -569,9 +569,6 @@
         bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry,
         bkIgnore, bkAll, bkYesToAll, bkNoToAll);
     
    -  MsgDlgCaptions: Array[mtWarning..mtCustom] of String = (rsMtWarning, rsMtError,
    -        rsMtInformation, rsMtConfirmation, rsMtCustom);
    -
       DialogResName: array[idDialogWarning..idDialogConfirm] of String =
       (
     {idDialogWarning} 'dialog_warning',
    Index: lcl/include/promptdialog.inc
    ===================================================================
    --- lcl/include/promptdialog.inc	(revision 31484)
    +++ lcl/include/promptdialog.inc	(working copy)
    @@ -500,6 +500,17 @@
         end;
     end;
     
    +function MsgDlgCaptions(const DlgType: TMsgDlgType): String;
    +begin
    +  case DlgType of
    +    mtWarning: Result := rsMtWarning;
    +    mtError: Result := rsMtError;
    +    mtInformation: Result := rsMtInformation;
    +    mtConfirmation: Result := rsMtConfirmation;
    +    mtCustom: Result := rsMtCustom;
    +  end;
    +end;
    +
     function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons): TForm;
     var
       PDlg: TPromptDialog;
    @@ -508,7 +519,7 @@
       CancelValue, DefaultIndex, ButtonCount: Longint;
     begin
       if DlgType <> mtCustom then
    -    aCaption := MsgDlgCaptions[DlgType]
    +    aCaption := MsgDlgCaptions(DlgType)
       else
         aCaption := Application.Title;
       Btns := GetPromptUserButtons(Buttons, CancelValue, DefaultIndex, ButtonCount, False, mbOk);
    
  • dialogs.msgdlgscaptions.2.diff (1,181 bytes)
    Index: lcl/include/promptdialog.inc
    ===================================================================
    --- lcl/include/promptdialog.inc	(revision 31738)
    +++ lcl/include/promptdialog.inc	(working copy)
    @@ -501,28 +501,12 @@
     end;
     
     function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons): TForm;
    -
    -  function MsgDlgCaptions(const DlgType: TMsgDlgType): String;
    -  begin
    -    case DlgType of
    -      mtWarning: Result := rsMtWarning;
    -      mtError: Result := rsMtError;
    -      mtInformation: Result := rsMtInformation;
    -      mtConfirmation: Result := rsMtConfirmation;
    -      mtCustom: Result := rsMtCustom;
    -    end;
    -  end;
    -
     var
       PDlg: TPromptDialog;
       aCaption: String;
       Btns: PLongInt;
       CancelValue, DefaultIndex, ButtonCount: Longint;
     begin
    -  if DlgType <> mtCustom then
    -    aCaption := MsgDlgCaptions(DlgType)
    -  else
    -    aCaption := Application.Title;
       Btns := GetPromptUserButtons(Buttons, CancelValue, DefaultIndex, ButtonCount, False, mbOk);
       PDlg := TPromptDialog.CreateMessageDialog(aCaption, Msg, DialogIds[DlgType], Btns, ButtonCount, DefaultIndex);
       Result := TForm(PDlg);
    

Activities

2011-07-17 15:33

 

dialogs.msgdlgscaptions.diff (1,578 bytes)
Index: lcl/dialogs.pp
===================================================================
--- lcl/dialogs.pp	(revision 31484)
+++ lcl/dialogs.pp	(working copy)
@@ -569,9 +569,6 @@
     bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry,
     bkIgnore, bkAll, bkYesToAll, bkNoToAll);
 
-  MsgDlgCaptions: Array[mtWarning..mtCustom] of String = (rsMtWarning, rsMtError,
-        rsMtInformation, rsMtConfirmation, rsMtCustom);
-
   DialogResName: array[idDialogWarning..idDialogConfirm] of String =
   (
 {idDialogWarning} 'dialog_warning',
Index: lcl/include/promptdialog.inc
===================================================================
--- lcl/include/promptdialog.inc	(revision 31484)
+++ lcl/include/promptdialog.inc	(working copy)
@@ -500,6 +500,17 @@
     end;
 end;
 
+function MsgDlgCaptions(const DlgType: TMsgDlgType): String;
+begin
+  case DlgType of
+    mtWarning: Result := rsMtWarning;
+    mtError: Result := rsMtError;
+    mtInformation: Result := rsMtInformation;
+    mtConfirmation: Result := rsMtConfirmation;
+    mtCustom: Result := rsMtCustom;
+  end;
+end;
+
 function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons): TForm;
 var
   PDlg: TPromptDialog;
@@ -508,7 +519,7 @@
   CancelValue, DefaultIndex, ButtonCount: Longint;
 begin
   if DlgType <> mtCustom then
-    aCaption := MsgDlgCaptions[DlgType]
+    aCaption := MsgDlgCaptions(DlgType)
   else
     aCaption := Application.Title;
   Btns := GetPromptUserButtons(Buttons, CancelValue, DefaultIndex, ButtonCount, False, mbOk);

Maxim Ganetsky

2011-07-17 20:07

developer   ~0050034

Last edited: 2011-07-17 20:08

I made a more simple fix, which avoids adding extra function. Thanks for the hint.

Please test and close if ok.

Bart Broersma

2011-07-18 00:23

developer   ~0050035

Last edited: 2011-07-18 00:38

The modified patch does not work.

Consider this code, after I have called TranslateUnitResourceStrings()

  Dlg := CreateMessageDialog('rsMtError = "'+ rsMtError + '"', mtError, [mbYes]);
  try
    Dlg.ShowModal;
  finally
    Dlg.Free
  end;

The message correctly displays rsMtError = "Fout" , but the caption still is Error.
I'll attach 2 screenshots.

File CreateMessageDialog_1.png: your modification to my patch (wrong caption).
File CreateMessageDialog_2.png: my original patch (correct caption).

The compiler "assigns" the values for the (local) static array at compiletime with the _value_ of the resource strings at that moment, not with a reference to their respective values.

Please apply the original patch.

2011-07-18 00:23

 

2011-07-18 00:23

 

Maxim Ganetsky

2011-07-18 21:47

developer   ~0050045

Sorry, applied.

Bart Broersma

2011-07-19 12:26

developer   ~0050055

Reminder sent to: Maxim Ganetsky

No need to appologize.

Further investigation shows that the patch can even be simpler.
The setting of the dialog title already occrs in:
TPromptDialog.CreateMessageDialog

which calls
GetDialogCaption(), which has this explicit comment:
{** Return the localized or not title of dialog}


So it seems my function was just duplicate code.
The correct solution seems to be to remove the first 4 lines in the CreateMessageDialog() function body alltogether...

I'll attach a new diff.

Now it's my time to say: "sorry for all the confusion".

2011-07-19 12:27

 

dialogs.msgdlgscaptions.2.diff (1,181 bytes)
Index: lcl/include/promptdialog.inc
===================================================================
--- lcl/include/promptdialog.inc	(revision 31738)
+++ lcl/include/promptdialog.inc	(working copy)
@@ -501,28 +501,12 @@
 end;
 
 function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons): TForm;
-
-  function MsgDlgCaptions(const DlgType: TMsgDlgType): String;
-  begin
-    case DlgType of
-      mtWarning: Result := rsMtWarning;
-      mtError: Result := rsMtError;
-      mtInformation: Result := rsMtInformation;
-      mtConfirmation: Result := rsMtConfirmation;
-      mtCustom: Result := rsMtCustom;
-    end;
-  end;
-
 var
   PDlg: TPromptDialog;
   aCaption: String;
   Btns: PLongInt;
   CancelValue, DefaultIndex, ButtonCount: Longint;
 begin
-  if DlgType <> mtCustom then
-    aCaption := MsgDlgCaptions(DlgType)
-  else
-    aCaption := Application.Title;
   Btns := GetPromptUserButtons(Buttons, CancelValue, DefaultIndex, ButtonCount, False, mbOk);
   PDlg := TPromptDialog.CreateMessageDialog(aCaption, Msg, DialogIds[DlgType], Btns, ButtonCount, DefaultIndex);
   Result := TForm(PDlg);

Maxim Ganetsky

2011-07-19 22:14

developer   ~0050061

Applied, thanks.

Issue History

Date Modified Username Field Change
2011-07-17 15:33 Bart Broersma New Issue
2011-07-17 15:33 Bart Broersma Status new => assigned
2011-07-17 15:33 Bart Broersma Assigned To => Bart Broersma
2011-07-17 15:33 Bart Broersma File Added: dialogs.msgdlgscaptions.diff
2011-07-17 15:33 Bart Broersma LazTarget => -
2011-07-17 15:33 Bart Broersma Widgetset => GTK, GTK 2, Win32/Win64, WinCE, Carbon, Cocoa, QT, fpGUI
2011-07-17 18:50 Maxim Ganetsky Assigned To Bart Broersma => Maxim Ganetsky
2011-07-17 20:07 Maxim Ganetsky Fixed in Revision => 31727
2011-07-17 20:07 Maxim Ganetsky Status assigned => resolved
2011-07-17 20:07 Maxim Ganetsky Fixed in Version => 0.9.31 (SVN)
2011-07-17 20:07 Maxim Ganetsky Resolution open => fixed
2011-07-17 20:07 Maxim Ganetsky Note Added: 0050034
2011-07-17 20:08 Maxim Ganetsky Note Edited: 0050034
2011-07-18 00:23 Bart Broersma Status resolved => assigned
2011-07-18 00:23 Bart Broersma Resolution fixed => reopened
2011-07-18 00:23 Bart Broersma Note Added: 0050035
2011-07-18 00:23 Bart Broersma File Added: CreateMessageDialog_1.png
2011-07-18 00:23 Bart Broersma File Added: CreateMessageDialog_2.png
2011-07-18 00:38 Bart Broersma Note Edited: 0050035
2011-07-18 21:47 Maxim Ganetsky Fixed in Revision 31727 => 31727, 31738
2011-07-18 21:47 Maxim Ganetsky Status assigned => resolved
2011-07-18 21:47 Maxim Ganetsky Resolution reopened => fixed
2011-07-18 21:47 Maxim Ganetsky Note Added: 0050045
2011-07-19 12:26 Bart Broersma Note Added: 0050055
2011-07-19 12:26 Bart Broersma Status resolved => assigned
2011-07-19 12:26 Bart Broersma Resolution fixed => reopened
2011-07-19 12:27 Bart Broersma File Added: dialogs.msgdlgscaptions.2.diff
2011-07-19 22:14 Maxim Ganetsky Fixed in Revision 31727, 31738 => 31727, 31738, 31748
2011-07-19 22:14 Maxim Ganetsky Status assigned => resolved
2011-07-19 22:14 Maxim Ganetsky Resolution reopened => fixed
2011-07-19 22:14 Maxim Ganetsky Note Added: 0050061
2011-07-26 12:33 Bart Broersma Status resolved => closed