Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Win 32 Controls/TTreeView    [ Add a report in this area ]  
Report #:  67220   Status: Closed
TreeView doesn't load Unicode files
Project:  Delphi Build #:  12.0.3170.1698
Version:    12.1 Submitted By:   Bob Swart
Report Type:  Crash / Data loss / Total failure Date Reported:  9/26/2008 8:32:30 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   265532
Resolution: Fixed (Resolution Comments) Resolved in Build: : 14.0.3513.24210
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: 26
Description
The TTreeview is unable to load itself from Unicode files. You can have nodes with Unicode Text, and save this correctly. But when you load them, they will be loaded as ASCII which shows garbage in the treeview of course.

Cause: TTreeView LoadFromFile, implemented as TCustomTreeView.LoadFromFile has no Encoding parameter and calls TCustomTreeView.LoadFromStream which in turn calls TTreeStrings.LoadTreeFromStream, again passing no Encoding.

LoadTreeFromStream uses a List.LoadFromStream, passing no Encoding (this is the place where an Encoding could be passed).
Steps to Reproduce:
Proposed solution (see also the Workaround for complete details):

  const Encoding: TEncoding = nil

Add Encoding parameter to the following routines in ComCtrls.pas:

TCustomTreeView.LoadFromFile (lines 1520 and 11414)
Call LoadFromStream (line 11420)

TCustomTreeView.LoadFromStream (lines 1521 and 11426)
Call LoadTreeFromStream (line 11430)
TTreeStrings.LoadTreeFromStream (lines 10015)

The LoadFromFile would pass it to LoadFromStream which would pass it to LoadTreeFromStream which could then pass it on to the List.LoadFromStream (line 10027).


I'm not sure if the same is also needed for the SaveToFile, since that seems to work fine.
Workarounds
Copy ComCtrls.pas to your project directory and modify line 1520-1521 as follows:

    procedure LoadFromFile(const FileName: string; const Encoding: TEncoding = nil);
    procedure LoadFromStream(Stream: TStream; const Encoding: TEncoding = nil);

Line 9872 as follows:

    procedure LoadTreeFromStream(Stream: TStream; const Encoding: TEncoding = nil);

Line 10015 as follows:

procedure TTreeStrings.LoadTreeFromStream(Stream: TStream; const Encoding: TEncoding = nil);

Line 10027 as follows:

      List.LoadFromStream(Stream, Encoding); // BS

Line 11414 as follows:

procedure TCustomTreeView.LoadFromFile(const FileName: string; const Encoding: TEncoding = nil);

Line 11420 as follows:

    LoadFromStream(Stream, Encoding); // BS

Line 11426 as follows:

procedure TCustomTreeView.LoadFromStream(Stream: TStream; const Encoding: TEncoding = nil);

Line 11430 as follows:

      LoadTreeFromStream(Stream, Encoding); // BS

And recompile ComCtrls.pas in order to fix the problem for your projects.
Attachment
None
Comments

Markus Humm at 9/27/2008 4:03:27 AM -
Marked as "needs attention"

Tomohiro Takahashi at 9/27/2008 5:29:27 AM -
QC#66810 is related to this report.

amos szust at 5/22/2009 4:29:21 AM -
Hi Tomohiro-san :)

i noticed several QC reports that even have a patch as code that were not integrated into any update of D2009, any special reason for that?

i already have special patch file for classes and for comctrls and i was wondering when will i be able to remove them from my project and use D2009 original ones

thanks
(sorry for the duplication of this reply)

amos szust at 5/16/2009 10:16:17 AM -
how come this patch was not applied into update 1 or 2 of D2009?
thanks

amos szust at 5/22/2009 4:28:45 AM -
Hi Tomohiro-san :)

i noticed several QC reports that even have a patch as code that were not integrated into any update of D2009, any special reason for that?

i already have special patch file for classes and for comctrls and i was wondering when will i be able to remove them from my project and use D2009 original ones

thanks

Server Response from: ETNACODE01