I tried to create a function/method which should write to a file with a header filled with zeros
header := StringOfChar(char(0), 11*offsetSize);
But when I check the file which was created, it has the following values (hex):
C026A200160000000100000006000000264C656B63650000B2000000B04D45005C1EA200306CA20000000000
I expected the output file should contain
0000 0000 0000 0000 0000 0000
Then I also tried to fill it with chr(1)
and the result was similar:
C026A200160000000100000006000000264C656B63650000B2000000B04D45005C1EA200306CA20000000000
(It looks the same).
When I debug in Delphi 7, I watch the header when it is filled with zeros:
#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
When I fill it with chr(1)
then it contains...
#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
So my question is, why is this happening? What am I doing wrong that the output file contains the wrong data?
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.