View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0004273 | JEDI VCL | 00 JVCL Components | public | 2007-10-23 08:43 | 2007-10-25 11:22 |
Reporter | bhe | Assigned To | AHUser | ||
Priority | normal | Severity | crash | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | Daily / GIT | ||||
Target Version | Fixed in Version | ||||
Summary | 0004273: Invalid Assign in JvGnugettext TranslateStrings | ||||
Description | TranslateStrings 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: http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=A636 | ||||
Additional Information | A workaround could be a safety check which performce the optimization only for the base classes. procedure TGnuGettextInstance.TranslateStrings(sl: TStrings; const TextDomain: string); var Line: AnsiString; i: Integer; TempList: TStringList; begin if sl.Count > 0 then begin sl.BeginUpdate; try if(sl.ClassType = TStrings)or(sl.ClassType = TStringList)then begin TempList := TStringList.Create; try TempList.Assign(sl); for i := 0 to TempList.Count - 1 do begin Line := TempList.Strings[i]; if Line <> '' then TempList.Strings[i] := dgettext(TextDomain, Line); end; sl.Assign(TempList); finally TempList.Free; end; end else begin for i := 0 to sl.Count - 1 do begin Line := sl.Strings[i]; if Line <> '' then sl.Strings[i] := dgettext(TextDomain, Line); end; end; finally sl.EndUpdate; end; end; end; 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. | ||||
Tags | No tags attached. | ||||
|
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. |
|
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. |
|
> 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 |
|
Yes, if(sl.ClassType = TStrings) or (sl.ClassType = TStringList)or (sl.ClassName = 'TMemoStrings') or (sl.ClassName = 'TComboBoxStrings') or (sl.ClassName = 'TListBoxStrings') then works trouble-free. |
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 |