Board index » delphi » Read lots of records at the same time from a typed file

Read lots of records at the same time from a typed file

I want to read lots of records at the same time from a typed file.
How can I do it?

--
< Mark >
E-mail: mszak...@konyvtar.c3.hu

 

Re:Read lots of records at the same time from a typed file


Quote
> I want to read lots of records at the same time from a typed file.
> How can I do it?

   There are several ways that I can think of, one using BlockRead, which
can read in large amount(s) of data with a single I/o.  First, you could
allocate a buffer of N times the record size and fill it with a BlockRead
of that many bytes (but handling the short block at the end of file in a
special manner).  You will have to "parse" the records from the buffer
the data way read into, but that's easy (with Move).
   A second way is to use the typed file Read with more than 1 variable
in the argument list: Read (file_var, R1, R2, R3, R4, etc.).

Re:Read lots of records at the same time from a typed file


On 4 Sep 1997 20:30:00 -0700, mrc...@primenet.com (Mike Copeland)
wrote:

Quote
>> I want to read lots of records at the same time from a typed file.
>> How can I do it?

>   There are several ways that I can think of, one using BlockRead, which
>can read in large amount(s) of data with a single I/o.  First, you could
>allocate a buffer of N times the record size and fill it with a BlockRead
>of that many bytes (but handling the short block at the end of file in a
>special manner).  You will have to "parse" the records from the buffer
>the data way read into, but that's easy (with Move).

Not necessarily, it could also be done with variant records, absolute
variables, or typecasting:

type
  TMyRec = record
    value : integer
  end ;

  TVarInput = record
    case byte of
      0 : ( RecArray : array [1..10] of TMyRec ) ;
      1 : ( ReadBuff : array [0..19] of byte ) ;
  end ;

var
  MyBuff : TVarInput ;
  x : integer ;
begin
  BlockRead( F, MyBuff.ReadBuff, SizeOf( MyBuff.ReadBuff )) ;
  X := MyBuff.RecArray[3].Value ;

Quote
>   A second way is to use the typed file Read with more than 1 variable
>in the argument list: Read (file_var, R1, R2, R3, R4, etc.).

That'll work too, or how about into an array:

var
  RecArray : array [1..10] of TMyRec ;

begin
  Read( F, RecArray[1], RecArray[2], RecArray[3]... RecArray[10] ) ;

Regards,

Stephen Posey
slpo...@concentric.net

Other Threads