Re: Re: Re: Reading a file?


Posted by Jean Claude Servaye on October 29, 2000 at 03:10:53:

In Reply to: Re: Re: Reading a file? posted by Denis on October 27, 2000 at 21:58:24:

: When i press a button nothing happens.
: here is the code as i iserted it modified code:

: var
: F : TextFile;
: A : String;
: N : Integer;
: I : Integer; {you forgot to identify I, maybe i need to identify it not like integer} // yes I forgot it
: SecondSection : Boolean;

: begin
: AssignFile(F,'new.txt'); {maybe I need to write this 'c:\project1\new.txt' instead of 'new.txt' ?}// yes, you must write full path if the file is not in the same directory as the program

: Reset(F); // open the file in read mode
: SecondSection := False; // flag to remember if the second part is reached
: A := '';
: I := 0;
: While not Eof(F) do begin // repeat for each line of file
: If A = '------' then SecondSection := True; // test if the second part is reached, you must replace the '----'by the same string as in the file to separate the 2 parts

: ReadLn(F,A); // read one line
: If SecondSection then begin // if we are in the second part
: N := Pos(' ',A); // find space in string
: StringGrid1.Cells[0,I] := Copy(A,1,N-1); // copy first part of line to string grid
: A := Copy(A,N+1,Length(A)); // takes the rest of string
: N := Pos(' ',A); // find space
: StringGrid1.Cells[1,I] := Copy(A,1,N-1); // copy second part
: StringGrid1.Cells[2,I] := Copy(A,N+1,Length(A)); // copy third part
: end;
: end;
: end;

: P.S can u plz write beside each line a short description ike what it does.




Related Articles and Replies: