I'd like to put the assign and reset of a text file into a function, and then use the function to return a line from the file, without needing to close the file then re assign and reset  every time (for performance reasons) - see below for my attempt. <div>
<br></div><div>This doesn't work because I guess the file handles etc are local to the function are volatile, so cannot be accessed in the main program  Is there a simple way to fix this ie to make this function work. Of course one can const in a function to make normal variables non volatile...but files etc?<div>
<br></div><div>TIA for any ideas...John   <div><br></div><div>main program...</div><div>get_line('tmp.tmp,0), to assign and reset;</div><div><br></div><div>{get lines}</div><div>str1:=get_line('tmp.tmp,1);</div><div>
str2:=get_line('tmp.tmp,1)</div><div>....</div><div>{close)</div><div>get_line('tmp.tmp,2) </div><div><br></div><div>assume function is defined as </div><div>function get_line( fname;string;flag:longint):string;</div>
<div>var f:text</div><div>begin</div><div>if flag=0 then</div><div> begin</div><div>  assign(f,fname);</div><div>  reset(f);</div><div> end;</div><div>if flag=1 then </div><div>while not eof(f) do</div><div> begin</div><div>
  readln(f);</div><div> end;</div><div> </div><div> if flag=2 then close(f);</div><div> get_line;=f;</div><div>end;</div></div></div>