I hate to be a Delphi spoiler, but Excel or Access can probably do all that 
out-of-the-box. Try opening it with Excel or Access.

Dave

--- On Thu, 10/30/08, Brad Hall <[EMAIL PROTECTED]> wrote:
From: Brad Hall <[EMAIL PROTECTED]>
Subject: RE: [delphi-en] Line feed (#10) terminated lines in files
To: [email protected]
Date: Thursday, October 30, 2008, 10:17 PM










    
            Good suggestions from everyone  - that's what I would have done if 
it

was allowable.



I need to retain the file as it exists, ie: no adding CR to the end of

the lines, etc. The user can modify part of the file which I then need

to write back in the same format as read.



I'm also unable to load it into a TMemo as the user is only seeing one

line at a time from the file. The size of the file is also undetermined,

could be 2Kb, could be 2Gb.



Best way to explain the file type is a file of records - 1 record is

being displayed to the user at a time.



The user clicks a button which reads one line at a time from the file,

then the fields are being extracted from the line + displayed to the

user in a string grid.



Any line from the file can be accessed for display to the user. My query

regarding accessing the last line of the file was to get a record count

from the file (not filesize) + to get a record count from a delimited

file you need to read every line in the file till EOF.



ReadLn will read in the entire file if there are no CR's in it, which

isn't pretty on large files ;-)



So that's why I'm looking for an alternative way to read the file 1 line

at a time instead of manipulating it by adding CR's or loading the whole

file.



Thanks.



____________ _________ _________ __



From: [EMAIL PROTECTED] ps.com [mailto:[EMAIL PROTECTED] ps.com] On

Behalf Of Rob Kennedy

Sent: Friday, 31 October 2008 2:58 PM

To: [EMAIL PROTECTED] ps.com

Subject: Re: [delphi-en] Line feed (#10) terminated lines in files



darckness000 wrote:

> I'm trying to read line-feed (ASCII #10) terminated lines from a file 

> (think UNIX file), not the usual CRLF (ASCII #13 #10) terminated 

> lines.

> 

> What I'm doing at the moment is to `Read' 1 char at a time into a var 

> until I hit an LF + then display the string to the user. While this 

> works, it is sloooowwwwwwwwww when seeking to the last line in a 

> large file.



If you want the last line, then maybe you could read backward from the 

end of the file.



> I've tried using `Read' with zero based character arrays - + while 

> this is much faster, read fills the array completely (ie: if the 

> array is [0..999], Read will read 1000 chars from the file) instead 

> of stopping at the LF in the file. As each line in the file is 

> variable in length, I am unable to allocate a static array. Dynamic 

> arrays don't work with `Read', but as I don't the length of each 

> string in the file this doesn't really matter.



You know, that's exactly what ReadLn does. But when it reaches the end 

of a line, it keeps the remainder of the buffer around to use for the 

next line.



> When comparing speed against what I'm currently doing + using ReadLn 

> (ReadLn doesn't read the LF, I was just testing speed), ReadLn is so 

> much quicker it's unbelievable.



Based on my reading of the Delphi 2005 code, it's the line feed that 

makes ReadLn stop reading. Merely a carriage return is _not_ sufficient 

for ending a line. They do not mark the end of a line, and they are not 

copied into the result buffer. What version are you using?



> My question is, does anyone know of a way to read LF terminated lines 

> from a file with speed comparable to ReadLn?



TStrings.LoadFromFi le handles all sorts of line-end styles. If you can 

afford to load the entire file into memory.



-- 

Rob



[Non-text portions of this message have been removed]




      

    
    
        
         
        
        








        


        
        


      

[Non-text portions of this message have been removed]

Reply via email to