var
ok:string;
fc,i: Integer;
bytes : array of byte;
begin
写入:
fs := TFileStream.Create('car.dat', fmCreate);
ok:='This is it';
ok:=StrToHex(ok);
fc:=Length(ok); //此时ok值为:54686973206973206974
fs.Write(ok,fc);
fs.Destroy;
读取:
fs := TFileStream.Create('car.dat', fmOpenRead);
fc:=fs.Size;
SetLength(bytes,fc);
fs.Read(bytes[0],fc);
i:=0; //此时bytes的值为:(8, 225, 10, 1, 24, 255, 18, 0, 5, 210, 80, 0, 32, 255, 18, 0, 150, 213, 80, 0)
while i<fc do begin
ok:=ok+PChar(@bytes[i]);
inc(i);
end;
ok:=HexToStr(ok); //此时ok的值为:#8'?'#1#$18#$FF#$12'?'#1#$18#$FF#$12#$A#1#$18#$FF#$12#1#$18#$FF#$12#$18#$FF#$12#$FF#$12#$12#5'襊襊P '#$FF#$12#$FF#$12#$12'栒P誔P'
//并不是54686973206973206974
bytes:=nil;
ok:='';
fs.Destroy;
为什么bytes怎么才能正确转换成string?