2

I need to download a file of TreeView in Unicode using idHTTP (String := idHTTP.Get). After downloading, I need do something with the string and then put it in a TTreeView. I'm using Delphi 2010.

s:=form2.idhttp1.Get(Adres+'list.ttt');
....
StrStream:=TStringStream.Create(s,t encoding.Unicode);
form2.TreeView1.LoadFromStream(strstream);
StrStream.Free;

I cannot see Unicode in S or TreeView1. I only see Unicode in S if I try to download not list.ttt but list.html. What do I need to set in idHTTP or something else to work properly?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Michael
  • 475
  • 2
  • 9
  • 17
  • 4
    @Sorin, please refrain from having a person's *first* response on Stack Overflow to be a complaint about a minor formatting issue. You have enough reputation; you could have just fixed it yourself. Michael, welcome to Stack Overflow. – Rob Kennedy May 30 '11 at 03:21

2 Answers2

3

How to make it work with TIdHttp

Don't use a TStringStream, use a TMemoryStream so you don't get any re-encodings of the contents. Example:

var ResponseStream: TMemoryStream;
begin
  ResponseStream := TMemoryStream.Create;
  try
    H.Get(URL, ResponseStream);
    ResponseStream.Position := 0;
    Tree.LoadFromStream(ResponseStream);
  finally ResponseStream.Free;
  end;
end;
Community
  • 1
  • 1
Cosmin Prund
  • 25,498
  • 2
  • 60
  • 104
  • The question was about plain old TTreeView, not TBaseVirtualTree. – Rob Kennedy May 30 '11 at 07:34
  • Thanks @Rob, fixed (deleted 3/4 of the answer). – Cosmin Prund May 30 '11 at 07:47
  • Cosmin Prund, thank you very much, it works!!! You was write. If I tried to download a text file in any coding (1251,UTF-8 etc.) into a string, than load it into stringstream and then into TreeView I had wrong characters (already in a string), it is because of Indy writes a response specially. But with memory-stream it works!!! – Michael May 30 '11 at 07:47
1

@Michael - I gather that you do see data in S, but it is ansiString and not Unicode, correct? Are you sure your source 'list.ttt' is Unicode? Have you tried declaring s explicitely as a unicodeString or using the unicodeString function? Just some things to consider - not really an answer. HTH

Vector
  • 10,879
  • 12
  • 61
  • 101