Answer the question
In order to leave comments, you need to log in
Working with files in Delhi. How not to go crazy?
I have two procedures.
The first one adds an entry to the file:
Procedure Add_Rec(app:RecType;way:string);
var
f:FileType;
recc:RecType;
i:integer;
begin
Assign(f,way);
reset(f);
while not(Eof(f)) do
begin
read(f,recc);
inc(i);
end;
close(f);
rewrite(f);
writeln('---',i);
Seek(f,i);
write(f,app);
close(f);
end;
reset(f);
while not(Eof(f)) do
begin
read(f,recc);
inc(i);
end;
close(f);
procedure output(way:string);
var
f:filetype;
rec:RecType;
i:integer;
begin
assign(f,way);
reset(f);
if filesize(f) > 0 then
for i:=1 to filesize(f) do
begin
read(f,rec);
writeln('Запись ',i,':');
writeln(' Марка: ',rec.model);
writeln(' Цвет: ',rec.color_car);
writeln(' Гос. номер: ',rec.state_number);
writeln(' Владелец: ',rec.owner);
end
else
writeln('Файл пуст.');
close(f);
end;
Answer the question
In order to leave comments, you need to log in
Discover TFileStream, TMemoryStream and TStringStream - this is exactly what Delphi uses to work with files.
Required reading:
Serialization - Pascal-style files (this is how you do it now)
Serialization - data streams (and this is about how to do it in the Delphi world)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question