对一个二进制的文件进行读写操作,这种文件包含一个记录和一个动态的数组,数组的长度信息包含在这个记录中.即文件中的数据象这样排列
记录
数组
记录
数组
....
现在想通过两个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是数组
上面的代码是错的
请问大家会如何实现这个上面的问题
记录
数组
记录
数组
....
现在想通过两个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是数组
上面的代码是错的
请问大家会如何实现这个上面的问题
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);
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;
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);
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;