Hat die Datei ein Byte-Order-Mark?
Zeige bitte mal, wie du Utf8ToAnsi() anwendest.
Nachtrag:
Delphi-Quellcode:
type
string4 = string[4];
function SkipBOM(s: TStream; const bom: string4): Boolean;
var
sBom: string4;
begin
s.Position := 0;
SetString(sBom, PChar(@sBom[1]), s.Read(sBom[1], Length(bom)));
Result := sBom = bom;
if not Result then
s.Position := 0
end;
procedure LoadFromUtf8File(s: TStrings; fn: TFileName);
var
i: Integer;
fs: TFileStream;
begin
fs := TFileStream.Create(fn, fmOpenRead or fmShareDenyWrite);
try
SkipBOM(fs, #$EF#$BB#$BF);
s.LoadFromStream(fs);
for i := 0 to Pred(s.Count) do
s[i] := Utf8ToAnsi(s[i]);
finally
fs.Free;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
LoadFromUtf8File(Memo.Lines, ParamStr(1));
end;