对一个二进制的文件进行读写操作,这种文件包含一个记录和一个动态的数组,数组的长度信息包含在这个记录中.即文件中的数据象这样排列
                  记录
                  数组
                  记录
                  数组
                  ....
现在想通过两个TLIST的类型来分别存储读出来的记录和数组的指针,代码如下
   AssignFile(F,FileN);
   ReSet(F,1);
   try
       While not Eof(F) do begin
         BlockRead(F,SRec,Sizeof(SRec));
         FPixel:=nil;
         SetLength(FPixel,SRec.EsNum);
         for i:=0 to SRec.EsNum-1 do
           BlockRead(F,FPixel[i],SizeOf(PSearchPoint));
         SRecList.Add(@SRec);   //有问题
         SPixelList.Add(@FPixel);   //有问题
       end;
   finally
     CloseFile(F);
   end;
SRec是记录,FPixel是数组
上面的代码是错的
请问大家会如何实现这个上面的问题

解决方案 »

  1.   

    type
      r = ^SRec;
      SRec = record
       a:integer;
    end;type FPixel = array of integer;var
     SRecList,SPixelList:TList;
     p: ^FPixel;
    ... new(r);
     new(p);
    ...
     SRecList.Add(r);   //换这样试试
     SPixelList.Add(p);
      

  2.   

    可以考虑使用TFileStream方法吗?http://lysoft.7u7.net
      

  3.   

    type
      PSRrec = ^SRec;
      PSearchPoint=^SearchPoint  //瞎猜
      SeachPoint=record
        .....
      end;
      Fpixel=array of SearchPoint;
    ...........
    var pp:PSRec;
      AssignFile(F,FileN);
       ReSet(F,1);
       try
           While not Eof(F) do 
           begin
             new(pp);
             BlockRead(F,pp^,Sizeof(SRec));
             FPixel:=nil;
             SetLength(FPixel,SRec.EsNum);
             BlockRead(F,FPixel[0],SizeOf(SearchPoint)*SRec.EsNum);
             SRecList.Add(pp);   
             SPixelList.Add(FPixel); 
           end;
       finally
         CloseFile(F);
       end;
      

  4.   

    不好意识,更正一下type
      sR = ^SRec;
      SRec = record
       a:integer;
    end;type FPixel = array of integer;var
     SRecList,SPixelList:TList;
     p: ^FPixel;
     r: sR;  
    ... new(r);
     new(p);
    ...
     SRecList.Add(r);   //换这样试试
     SPixelList.Add(p);
      

  5.   

    现在主要的问题是编译能通过,可以读出SREC这个记录的数据,读FPIXEL的数据时什么都没有
      

  6.   

    更严重的问题是由于如果有多个记录,似乎TLIST里面存放的只是最后一个记录的地址
      

  7.   

    现在我自己做了一个类似于TLIST的类,还是存在类似的问题,发现往TLIST里面加数据的时候还行,但是往外读数据的时候什么都没有type
      SPixel=array of PSearchPoint;  TDatPixelList=class(TObject)
      private
      CCount:integer;
      FList:TList;  procedure SetCount(aCount:integer);
      function  ReadItem(Index:integer):SPixel;
      procedure WriteItem(Index: integer; const Value: SPixel);
      public  constructor Create(Count:integer);
      destructor Destroy; override;  procedure Add(aItem:SPixel);
    //  Procedure Clear;
    //  Procedure Delete(index:integer);
    //  function First:SPixel;
    //  function Last:SPixel;  property Items[Index:integer]:SPixel Read ReadItem Write WriteItem;
      property Count:integer Read CCount Write SetCount;  end;implementation{ TDatPixelList }procedure TDatPixelList.Add(aItem: SPixel);
    var Temp:^SPixel;
    begin
       Inc(CCount);
       Temp:=@aItem;
       FList.Add(Temp^);
    end;constructor TDatPixelList.Create(Count: integer);
    begin
      inherited Create;
      CCount:=0;
      FList:=TList.Create;
      Flist.Count:=CCount;
    end;destructor TDatPixelList.Destroy;
    begin
      FreeAndNil(FList);
      inherited;
    end;function TDatPixelList.ReadItem(Index: integer): SPixel;
    begin
      if (Index<0) or (Index>=Flist.Count) then begin
        MessageDlg('Index Error',mtError,[mbCancel],0);
        Exit;
      end;
      Result:=FList.Items[Index];
    end;procedure TDatPixelList.SetCount(aCount: integer);
    begin
       CCount:=aCount;
    end;procedure TDatPixelList.WriteItem(Index: integer; const Value: SPixel);
    begin
      if (Index<0) or (Index>=Flist.Count) then begin
        MessageDlg('Index Error',mtError,[mbCancel],0);
        Exit;
      end;  FList.Items[Index]:=Value;
    end;