我试图创建一个函数/方法,该函数/方法应该写入一个标头填充零的文件
header := StringOfChar(char(0), 11*offsetSize);
但是当我检查创建的文件时,它具有以下值(十六进制):
C026A200160000000100000006000000264C656B63650000B2000000B04D45005C1EA200306CA20000000000
我希望输出文件应该包含
0000 0000 0000 0000 0000 0000
然后我也尝试用它来填充它,chr(1)
结果是相似的:
C026A200160000000100000006000000264C656B63650000B2000000B04D45005C1EA200306CA20000000000
(看起来一样)。
当我在 Delphi 7 中进行调试时,我会在标题填充零时观察它:
#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
当我填充它时,chr(1)
它包含...
#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1
所以我的问题是,为什么会这样?输出文件包含错误数据,我做错了什么?
unit Dictionary_io;
interface
uses
Classes, Windows, SysUtils, Dialogs;
const
offsetTableEntriesCount = 10;
type
TCountType = dword;
TOffsetType = dword;
TTextType = ANSIString;
const
testItemsCount = 1;
type
Dictionary = class
private
fsInput, fsOutput: TFileStream;
fileName: string;
msOffsets: TMemoryStream;
offsetSize: TOffsetType;
ofsTableEntries: TCountType;
lng: integer;
itemsCount: byte;
header: TTextType;
public
constructor Create;
procedure dicRewrite;
end;
implementation
constructor Dictionary.Create;
begin
offsetSize := sizeof(offsetSize);
end;
procedure Dictionary.dicRewrite;
var
i: integer;
begin
itemsCount := 0;
header := StringOfChar(char(0), 11*offsetSize);
try
fileName := 'A:\test.bin';
if FileExists(fileName) then
DeleteFile(fileName);
fsOutput := TFileStream.Create(fileName, fmCreate);
try
fsOutput.Write(header,Length(header));
finally
end;
finally
fsOutput.Free;
end;
end;
end.