TIP: Click on subject to list as thread! ANSI
echo: delphi
to: BRYAN SMITH
from: PETER COLLIS
date: 1996-06-08 11:00:00
subject: Help

-= Pete Replied to Bryan Smith about: Help =-
G'day Bryan
 PC> overcoming it by first opening the input text file using
 PC> FileOpen() then doing a seek to the end of the file to get it's
 PC> size closing it and re-opening it as a textfile, to get the file
 PC> pointer position i just used a longint and added the length of
 PC> each line read +2 to it.
 BS> There is a trick I saw first in Clipper that you might be able
 BS> to make use of here.  Suppose the file is open as binary, but
 BS> that you want to do the equivalent of a ReadLn.  The idea is to
 BS> read in a buffer from the file, large enough so you know that it
 BS> will be longer than the longest line that will be encountered.
 BS> Then scan the buffer until you find the first CR/LF. It is now
 BS> easy to calculate how much you must move the file pointer back
 BS> so that it is placed immediately after the CR/LF, i.e.
 BS> positioned ready to read the next line.  Then you pass back to
 BS> the calling program just that part of the buffer that lies ahead
 BS> of the CRLF.
When i couldn't find what i wanted with the std Delphi routines i
started to write such a function but then thought "hangon if i'm going
to learn Delphi properly i shouldn't be trying to re-invent the
language" so i went back to the supplied routines and used them.
 BS> This may be exactly what happens deep-down when you make a
 BS> ReadLn call in Pascal/Delphi.
I guess at it's lowest level you end up with a disk read that's just
loading bytes into a buffer from a file so i'd say your right.
 BS> Regarding the fixed-record-length file you are creating in order
 BS> to do a binary search for part numbers.  Is there any chance
 BS> that you could use a Delphi TStringList instead, to do it
 BS> in-core ?  Or build your own linked list from scratch ?
That would be quicker but at times there's greater than 100,000
records involved so i work on the theory that under some conditions
there maybe insufficent memory to do this, FWIW the search routine is
quite fast even using the disk.
 BS> Back to the binary read, here is some (TP 7.0) code you can play
 BS> with. No guarantees !
[code saved & deleted]
thanks i'll add it to my code collection.
   -=Pete=-
--- OMX/Blue Wave v2.12
---------------
* Origin: Gates of Hell (3:713/914.16)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.