[fpc-pascal]files handler in FPC
Adam Naumowicz
adamn at math.uwb.edu.pl
Thu Mar 7 00:59:35 CET 2002
Hello,
On 6 Mar 2002, [iso-8859-2] £ukasz Le¶niak wrote:
> Hello!
> My name is Lukasz Lesniak and I am from Poland (Central Europe).
Although I'm in Japan now, I remember where Poland is quite well :-))
> 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?
I can't see no loop here ! How do you think this is supposed to read all
the list ?
BTW - the BP snippet you included is a little old style but I can't see
there anything the FPC compiler should complain at.
Regards,
Adam Naumowicz
--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------
More information about the fpc-pascal
mailing list