【发布时间】:2016-07-27 10:38:26
【问题描述】:
我知道在 Delphi 7 中,AnsiString 类型为 1 个字节,但在 Delphi 2010 中,UnicodeString 类型为 2 个字节。
以下代码适用于 Delphi 7
var
FS: TFileStream;
BinarySize: integer;
FreeAvailable, TotalSpace: int64;
fname: string;
StringAsBytes: array of Byte;
begin
..............
FS := TFileStream.Create(drive+'\'+fname+'.BIN', fmOpenReadWrite or fmShareDenyWrite);
try
BinarySize := (Length(fname) + 1) * SizeOf(Char);
SetLength(StringAsBytes, BinarySize);
Move(fname[1], StringAsBytes[0], BinarySize);
FS.Position:=172903;
FS.WriteBuffer(StringAsBytes[0], Length(StringAsBytes));
FS.Position:=173111;
FS.WriteBuffer(StringAsBytes[0], Length(StringAsBytes));
FS.Position:=173235;
FS.WriteBuffer(StringAsBytes[0], Length(StringAsBytes));
FS.Position:=173683;
FS.WriteBuffer(StringAsBytes[0], Length(StringAsBytes));
FS.Position:=173695;
FS.WriteBuffer(StringAsBytes[0], Length(StringAsBytes));
finally
FS.Free;
end;
end;
但它不适用于 Delphi 2010。请帮助!
【问题讨论】:
-
你知道为什么它不起作用。那里有很多资源。你有没有努力去理解这一点?
-
我也用过这个
StringAsBytes:=TEncoding.ASCII.GetBytes(fname);我查了HEX代码,一切都很好,但实际上是不对的 -
如果不对,也不是万事大吉。
-
十六进制代码似乎是正确的,但文件没有工作。我不知道为什么