View Issue Details

IDProjectCategoryView StatusLast Update
0004273JEDI VCL00 JVCL Componentspublic2007-10-25 11:22
ReporterbheAssigned ToAHUser 
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version 
Summary0004273: Invalid Assign in JvGnugettext TranslateStrings
DescriptionTranslateStrings uses a temporary string list (for optimization?).
This can lead to problem with inherited classes of TStrings if they
do some magic in their Assign implementation.

See the following link for example:
Additional InformationA workaround could be a safety check which performce the optimization only for the base classes.

procedure TGnuGettextInstance.TranslateStrings(sl: TStrings; const TextDomain: string);
  Line: AnsiString;
  i: Integer;
  TempList: TStringList;
  if sl.Count > 0 then
      if(sl.ClassType = TStrings)or(sl.ClassType = TStringList)then
        TempList := TStringList.Create;
          for i := 0 to TempList.Count - 1 do
            Line := TempList.Strings[i];
            if Line <> '' then
              TempList.Strings[i] := dgettext(TextDomain, Line);
     end else
       for i := 0 to sl.Count - 1 do
         Line := sl.Strings[i];
         if Line <> '' then
           sl.Strings[i] := dgettext(TextDomain, Line);

I am not sure if the usage of TempList is really an optimization, indeed i think Begin/End-Update should be enough here.
So the second - currently commented - version should be sufficient.
TagsNo tags attached.



2007-10-23 11:23

developer   ~0013991

Last edited: 2007-10-23 11:24

The subversion history for this function says "Previous code didn't work with sorted stringlists".

> This can lead to problem with inherited classes of TStrings
> if they do some magic in their Assign implementation.

I would say that this is a problem of the derived TStrings class that implements the Assign method the wrong way which not only has an impact on JvGnuGettext but also on the RTL/VCL.


2007-10-24 03:19

reporter   ~0013994

How can a derived class in general perform a complete Assign if it just get its base type as object to assign? Means TempList cannot hold all info sl might have. Blaming is easy but does not help. IMO Gettext should be as smart as possible to work in most cases.

Sorted lists can not processed very well. E.g. if someone holds an index to a specific item translation wont work in any way!
A solution without Assign would be checking the Sorted flag an call Sort() after translation.


2007-10-24 13:36

developer   ~0013995

Last edited: 2007-10-24 13:45

> Means TempList cannot hold all info sl might have.

Good point.

Can you confirm that this if-statement also works:

      if (sl.ClassType = TStrings) or (sl.ClassType = TStringList) or
         (sl.ClassName = 'TMemoStrings') or (sl.ClassName = 'TComboBoxStrings') or
         (sl.ClassName = 'TListBoxStrings') then


2007-10-25 09:03

reporter   ~0013997

     if(sl.ClassType = TStrings) or (sl.ClassType = TStringList)or
       (sl.ClassName = 'TMemoStrings') or (sl.ClassName = 'TComboBoxStrings') or
       (sl.ClassName = 'TListBoxStrings') then

works trouble-free.

Issue History

Date Modified Username Field Change
2007-10-23 08:43 bhe New Issue
2007-10-23 11:23 AHUser Note Added: 0013991
2007-10-23 11:23 AHUser Status new => feedback
2007-10-23 11:24 AHUser Note Edited: 0013991
2007-10-24 03:19 bhe Note Added: 0013994
2007-10-24 13:36 AHUser Note Added: 0013995
2007-10-24 13:45 AHUser Note Edited: 0013995
2007-10-25 09:03 bhe Note Added: 0013997
2007-10-25 11:21 AHUser Status feedback => resolved
2007-10-25 11:21 AHUser Resolution open => fixed
2007-10-25 11:21 AHUser Assigned To => AHUser