ヘッダーがゼロで埋められたファイルに書き込む関数/メソッドを作成しようとしました
header := StringOfChar(char(0), 11*offsetSize);
しかし、作成されたファイルを確認すると、次の値 (16 進数) が含まれています。
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.