Register new object for streaming.
Source position: objects.pp line 748
procedure RegisterType( |
var S: TStreamRec |
); |
RegisterType registers a new type for streaming. An object cannot be streamed unless it has been registered first. The stream record S needs to have the following fields set:
The VMT of the object can be retrieved with the following expression:
VmtLink: Ofs(TypeOf(MyType)^);
In case of error (if a object with the same ObjType) is already registered), run-time error 212 occurs.
Unit MyObject; Interface Uses Objects; Type PMyObject = ^TMyObject; TMyObject = Object(Objectrong !!'); Field : Longint; Constructor Init; Constructor Load (Var Stream : TStream); Destructor Done; Procedure Store (Var Stream : TStream); Function GetField : Longint; Procedure SetField (Value : Longint); end; Implementation Constructor TMyobject.Init; begin Inherited Init; Field:=-1; end; Constructor TMyobject.Load (Var Stream : TStream); begin Stream.Read(Field,Sizeof(Field)); end; Destructor TMyObject.Done; begin end; Function TMyObject.GetField : Longint; begin GetField:=Field; end; Procedure TMyObject.SetField (Value : Longint); begin Field:=Value; end; Procedure TMyObject.Store (Var Stream : TStream); begin Stream.Write(Field,SizeOf(Field)); end; Const MyObjectRec : TStreamRec = ( Objtype : 666; vmtlink : Ofs(TypeOf(TMyObject)^); Load : @TMyObject.Load; Store : @TMyObject.Store; ); begin RegisterObjects; RegisterType (MyObjectRec); end.