BytePtr
01-11-2005, 01:56 PM
Im not newbie in programming, just trying to learn more every day with my experiments.
I need to create one specific file, like described in documenttation of file format. But my problem is how to write many records in file? Look my code.
type
tmy_file_header=record
file_type:array[0..3] of Char;
vers_code:Word;
end;
mfh: tmy_file_header;
f: file of tmy_file_header;
procedure TForm1.Button1Click(Sender: TObject);
begin
assignfile(f,'c:\data.dat');
{$I-}
reset(f);
seek(f, filesize(f));
{$I+}
if ioresult=0 then
begin
// write
mfh.file_type:='MHDR';
mfh.vers_code:=100;
write(f,mfh);
end
else
begin
{$I-}
rewrite(f);
{$I+}
if ioresult=0 then
begin
// write
mfh.file_type:='MHDR';
mfh.vers_code:=100;
write(f,mfh);
end
else
showmessage('Unable to create file!');
end;
end;
tmy_file_header is my first record, but i must to create more records and write them all to one file, without removing/corrupting previous data from/in file.
If i write another:
f: file of other_record; then Delphi displays error: "Incompatible types: first record and other record"
Creating every time new F type is not good way.
How to solve this problem? Any ideas?
btw: i just started learning using delphi "record and type".
I need to create one specific file, like described in documenttation of file format. But my problem is how to write many records in file? Look my code.
type
tmy_file_header=record
file_type:array[0..3] of Char;
vers_code:Word;
end;
mfh: tmy_file_header;
f: file of tmy_file_header;
procedure TForm1.Button1Click(Sender: TObject);
begin
assignfile(f,'c:\data.dat');
{$I-}
reset(f);
seek(f, filesize(f));
{$I+}
if ioresult=0 then
begin
// write
mfh.file_type:='MHDR';
mfh.vers_code:=100;
write(f,mfh);
end
else
begin
{$I-}
rewrite(f);
{$I+}
if ioresult=0 then
begin
// write
mfh.file_type:='MHDR';
mfh.vers_code:=100;
write(f,mfh);
end
else
showmessage('Unable to create file!');
end;
end;
tmy_file_header is my first record, but i must to create more records and write them all to one file, without removing/corrupting previous data from/in file.
If i write another:
f: file of other_record; then Delphi displays error: "Incompatible types: first record and other record"
Creating every time new F type is not good way.
How to solve this problem? Any ideas?
btw: i just started learning using delphi "record and type".