Forum > General

Error at begin Code Again

<< < (2/2)

cdbc:
Hi.

Here's another take on the problem...:

--- Code: ---Function LinesToArray(Var A:TFileLines; const FPath:String):LongInt; 
Var 
 FileVar:TextFile; 
 Counter:Integer; 
begin 
  Result := CountFileLines(FPath); 
  SetLength(A,Result); 
  AssignFile(FileVar,FPath);
 
  // the next block should run just fine...
  Counter:= 0;
  while not EoF(FileVar) do begin
    Readln(FileVar,A[Counter]);
    inc(Counter); 
  end; 
  // don't overcomplicate things, keep it simple :-)

  CloseFile(FileVar); 
end;
--- End code ---

hth - Regards Benny

Martin_fr:

--- Quote from: cdbc on July 03, 2010, 10:47:02 am ---Here's another take on the problem...:

--- Code: ---  Counter:= 0;
  while not EoF(FileVar) do begin
    Readln(FileVar,A[Counter]);
    inc(Counter); 
  end; 

--- End code ---

--- End quote ---

And it will crash, if the amount of lines increases (another process writing to the file) between the call to CountFileLines and the repeat loop.

Yes you can increase the size of the array while you are in the loop, and it's how I would do it. But let Jasper explore at what I assume is his level...

cdbc:

--- Quote ---Yes you can increase the size of the array while you are in the loop, and it's how I would do it. But let Jasper explore at what I assume is his level...
--- End quote ---

+1  :D

Regards Benny

Navigation

[0] Message Index

[*] Previous page

Go to full version