How can I download a Unicode file and load it in a TTreeView?
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.Crea开发者_运维技巧te(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?
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;
@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
精彩评论