Blockread

From: Wade Moore (wadepm_at_sbcglobal.net)
Date: 12/31/03


Date: Tue, 30 Dec 2003 20:49:15 -0600

I am using blockread to get some data from a file. I have set up a
tempoarary record type to get the data and then I write it to the arrays
where the data is stored to be used by the program. The following bit of
code does NOT work. After the first blockread the length of "vals" is set
back to zero!

type
  feqdata = record
    time:real;
    vals:array of single;
  end;

var
  tdata:feqdata;
  time:array of real;

begin
  AssignFile(tsdfile,tsdfilename);
  reset(tsdfile,sizeof(tdata));
  setlength(time,numrecords);
  setlength(tdata.vals,totalpoints);
  for i:=1 to numrecords do begin
      blockread(tsdfile,tdata,1);
      time[i]:=tdata.time*24;
      for j:=1 to totalpoints do
        plotpoint[j].flw[i]:=tdata.vals[i];
 end;

However, the code below DOES work. If I change to a fixed length array for
"vals" then everything works fine. The problem is in the real program I
never know a priori what the length of "vals" will be. It appears I can not
have a variable length array if I am using that record to do a blockread?
Thanks for your help guys.

type
  feqdata = record
    time:real;
    vals:array[1..1240] of single;
  end;

var
  tdata:feqdata;
  time:array of real;

begin
  AssignFile(tsdfile,tsdfilename);
  reset(tsdfile,sizeof(tdata));
  setlength(time,numrecords);
  for i:=1 to numrecords do begin
      blockread(tsdfile,tdata,1);
      time[i]:=tdata.time*24;
      for j:=1 to 1240 do
        plotpoint[j].flw[i]:=tdata.vals[i];
 end;



Relevant Pages

  • Re: Blockread
    ... > I am using blockread to get some data from a file. ... > feqdata = record ... In the above record, 'vals' is just a pointer to an array on the heap, not ...
    (borland.public.delphi.language.objectpascal)
  • Re: Blockread
    ... I tried that way but it reads very slow, using the blockread is much, much ... My problem I think is that the file I am reading consists of a type ... real value followed by a unknown number of type single values. ... >> It appears I can not have a variable length array if I am using that ...
    (borland.public.delphi.language.objectpascal)