thanks all - btw it wasn't the real code just an example I made up , the while loop wasn't needed- mistake! <br /><br />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? <br />John<br /> <br /><br />On , Rainer Stratmann <RainerStratmann@t-online.de> wrote:<br />> In my eyes it is (very) unlogic.<br />> <br />> <br />> <br />> Why don't you make 3 functions?<br />> <br />> Something like this...<br />> <br />> <br />> <br />> var filename : string; // global var for storing the filename<br />> <br />> <br />> <br />> function file_reset( name : string ) : boolean;<br />> <br />> function file_read( var eof : boolean ) : string;<br />> <br />> function file_close : boolean;<br />> <br />> <br />> <br />> Whith your example you don't have to pass the filename for operation 1<br />> <br />> (flag=1).<br />> <br />> <br />> <br />> Rainer<br />> <br />> <br />> <br />> Am Monday 16 May 2011 02:28:14 schrieb John Lee:<br />> <br />> > I'd like to put the assign and reset of a text file into a function, and<br />> <br />> > then use the function to return a line from the file, without needing to<br />> <br />> > close the file then re assign and reset  every time (for performance<br />> <br />> > reasons) - see below for my attempt.<br />> <br />> ><br />> <br />> > This doesn't work because I guess the file handles etc are local to the<br />> <br />> > function are volatile, so cannot be accessed in the main program  Is there<br />> <br />> > a simple way to fix this ie to make this function work. Of course one can<br />> <br />> > const in a function to make normal variables non volatile...but files etc?<br />> <br />> ><br />> <br />> > TIA for any ideas...John<br />> <br />> ><br />> <br />> > main program...<br />> <br />> > get_line('tmp.tmp,0), to assign and reset;<br />> <br />> ><br />> <br />> > {get lines}<br />> <br />> > str1:=get_line('tmp.tmp,1);<br />> <br />> > str2:=get_line('tmp.tmp,1)<br />> <br />> > ....<br />> <br />> > {close)<br />> <br />> > get_line('tmp.tmp,2)<br />> <br />> ><br />> <br />> > assume function is defined as<br />> <br />> > function get_line( fname;string;flag:longint):string;<br />> <br />> > var f:text<br />> <br />> > begin<br />> <br />> > if flag=0 then<br />> <br />> >  begin<br />> <br />> >   assign(f,fname);<br />> <br />> >   reset(f);<br />> <br />> >  end;<br />> <br />> > if flag=1 then<br />> <br />> > while not eof(f) do<br />> <br />> >  begin<br />> <br />> >   readln(f);<br />> <br />> >  end;<br />> <br />> ><br />> <br />> >  if flag=2 then close(f);<br />> <br />> >  get_line;=f;<br />> <br />> > end;<br />> <br />> <br />> <br />> <br />> <br />> _______________________________________________<br />> <br />> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org<br />> <br />> http://lists.freepascal.org/mailman/listinfo/fpc-pascal<br />> <br />>