Board index » delphi » Read function nulls my array!

Read function nulls my array!

I'm having a few problems with the Read() function in Delphi2. My program
reads a log file and looks for certain strings. This all works fine
except for the following section which has to read two lines..

eg

Unable to locate source path or file specification
 KELVIN'S_PC/Drive-C:\

Read(f, linebuff) always works fine, reading in a line of the file, but the
second Read(f, linebuff) puts a null (#0) character at the beginning of the
linebuff array rather than reading in a new line.

Why is this happening ?! Any help would be muchly appreciated.

Kelvin.

-//-

   Read (f, linebuff);

   if (StrPos(linebuff, 'Unable to locate source path')<>nil)
     then begin
          Read(f, linebuff);              // <-- Problem here
          if (StrPos(linebuff, 'KELVIN'S_PC')<>nil)
            then Error:=1;
          end;

-//-

where linebuff is an array[0..159] of char
      f is a system.textfile

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

 

Re:Read function nulls my array!


You need to advance to the next line.  See Help on Read
procedure... After the first Read, each subsequent Read sees
the end-of-line marker and returns a zero-length string.

If I may make a suggestion (not knowing your app), why not
use Readln.  Much more straight forward if your log file is
ASCII.

Mark

polyes...@my-dejanews.com says...

Quote
> I'm having a few problems with the Read() function in Delphi2. My program
> reads a log file and looks for certain strings. This all works fine
> except for the following section which has to read two lines..
>  [snip]

Other Threads