DELPHI7加载UNICODE编码格式的TXT显示为乱码的解决方法

DELPHI7的STRING默认是ANSI编码,加载UNICODE编码格式的TXT显示为乱码,解决方法如下:

procedure TForm1.Button1Click(Sender: TObject);
var
F:TFileStream;
S:WideString;
I:Integer;
FileName:string;
begin
FileName := ExtractFilePath(Application.ExeName)+'20151214003.txt';
F:=TFileStream.Create(FileName,fmOpenRead);
I:=F.Size;
SetLength(S,I div 2);
F.Read(S[1],I);
F.Free;
Delete(S,1,1);
Memo1.Text:=S;
end;

posted @ 2015-12-21 08:29  delphi中间件  阅读(4204)  评论(0编辑  收藏  举报