[fpc-pascal] accessing files from a function

dhkblaszyk at zeelandnet.nl dhkblaszyk at zeelandnet.nl
Mon May 16 12:37:08 CEST 2011



On Mon, 16 May 2011 10:28:19 +0000, johnelee1944 at googlemail.com
wrote:  

> thanks all - btw it wasn't the real code just an example I
made up , the while loop wasn't needed- mistake! 
>
>But the q still
remains - having three functions would still give the problem I have
now- that when doing a file_read (my function flag=1) would say 'file
not open' because the handles are volatile & local to file reset - >that
was the point of my original email. Seems as if there is no solution?

>John

Of course there is. As was stated earlier you need to make the
filehandle a global not a local variable. You could also handle it
differently and use a TStringList instead. 

var
 s: TStrings;

s :=
TStringList.Create;
s.LoadFromFile('MyFile.txt');
//do something with
line 12
writeln(s[12]);
s.Free

Regards, Darius 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110516/2d707c75/attachment.html>


More information about the fpc-pascal mailing list