[fpc-pascal]files handler in FPC
Łukasz Leśniak
lukasz.lesniak at interia.pl
Wed Mar 6 18:13:03 CET 2002
Hello!
My name is Lukasz Lesniak and I am from Poland (Central Europe). I use Pascal
very often.
I've declared structure:
(* ------------------------------------------------------------ *)
type Person = record
name: string[20];
.
{something else}
{about 40 position}
.
age : Word;
end;
SetOfPerson = ^ElemOfSetOfPerson;
ElemOfSetOfPerson = record
desc: Person;
prev: SetOfPerson;
next: SetOfPerson;
end;
filePerson = file of Person;
(* ------------------------------------------------------------ *)
First I wrote my program in Turbo Pascal. Now I want
to convert source to FPC and the problem is:
(* ------------------------------------------------------------ *)
procedure ReadDataFromFile(var s: SetOfperson)
var F: filePerson;
p: SetOfPerson;
.
.
Assign(F, path_to_F);
{$i-}
Reset(F);
{$i+}
if IOResult <> 0 then Halt(1);
while not Eof(F) do
begin
new(p);
Read(F, p^.desc);
p^.next:=s;
s:=p;
end;
.
.
(* ------------------------------------------------------------ *)
and trying the same in FPC
(* ------------------------------------------------------------ *)
procedure ReadDataFromFile(var s: SetOfperson)
var i, F: LongInt;
p: SetOfPerson;
.
.
i:=0;
F:=FileOpen(path_to_F, fmOpenRead);
if F = -1 then Halt(1);
new(p);
FileSeek(F, i, fsFromBeginning);
FileRead(F, p^.desc, SizeOf(p^.desc));
(* XXX *)
p^.next:=s;
s:=p;
i:= i + 1;
end;
(* ------------------------------------------------------------ *)
XXX - question is: how to read file with FileRead function
from beginning to end, beacause this code reads only one person!
I am using FileSeek. It is good?
_____________________________________
/* created by luke BFTH */
More information about the fpc-pascal
mailing list