L
L.Ming
Unregistered / Unconfirmed
GUEST, unregistred user!
关于一个这样的内存流操作,大家可能都看过很多了,但是有一个问题,这只能针对性某一种记录类型而定,有没有办法处理得通用一点,就是任意一种记录都可以操作?这是类的方法与属性,看名字基本都可以知道他的意思了 TDataStream = class(TMemoryStream) private function GetNumRecs: Longint
function GetCurRec: Longint
procedure SetCurRec(RecNo: Longint)
function Eof: Boolean
function Bof: Boolean
protected function GetRecSize: Longint
virtual
public function SeekRec(RecNo: Longint
Origin: Word): Longint
function WriteRec(const Rec): Longint
function AppendRec(const Rec): Longint
function ReadRec(var Rec): Longint
procedure DeleteRec(CurRec: Longint)
procedure First
procedure Last
procedure NextRec
procedure PreviousRec
// NumRecs shows the number of records in the stream property NumRecs: Longint read GetNumRecs
// CurRec reflects the current record in the stream property CurRec: Longint read GetCurRec write SetCurRec
end;但是有一个问题,就是说里面这个返回记录大小的函数,他是固定某一种类型,因为对类的不太熟悉,不知道SizeOf()里面的类型可否作为变量来使用呢?就是根据用户提供的记录类型而变动,这样的话,程序中有多个类就不用写多次代码了。function TDataStream.GetRecSize(var x):Longint;begin {这个函数返回的是关于这个流内的单个记录的大小 This function returns the size of the record that this stream knows about (TPersonRec) } Result := SizeOf(TNumData);end;
function GetCurRec: Longint
procedure SetCurRec(RecNo: Longint)
function Eof: Boolean
function Bof: Boolean
protected function GetRecSize: Longint
virtual
public function SeekRec(RecNo: Longint
Origin: Word): Longint
function WriteRec(const Rec): Longint
function AppendRec(const Rec): Longint
function ReadRec(var Rec): Longint
procedure DeleteRec(CurRec: Longint)
procedure First
procedure Last
procedure NextRec
procedure PreviousRec
// NumRecs shows the number of records in the stream property NumRecs: Longint read GetNumRecs
// CurRec reflects the current record in the stream property CurRec: Longint read GetCurRec write SetCurRec
end;但是有一个问题,就是说里面这个返回记录大小的函数,他是固定某一种类型,因为对类的不太熟悉,不知道SizeOf()里面的类型可否作为变量来使用呢?就是根据用户提供的记录类型而变动,这样的话,程序中有多个类就不用写多次代码了。function TDataStream.GetRecSize(var x):Longint;begin {这个函数返回的是关于这个流内的单个记录的大小 This function returns the size of the record that this stream knows about (TPersonRec) } Result := SizeOf(TNumData);end;