D.Tkalcec (RTC)
|
|
« Reply #1 on: April 20, 2016, 10:00:28 AM » |
|
TRtcConnection component already has the "Info:TRtcInfo" property, which can be used to store any kind of connection-related information and data. TRtcInfo class extends the TRtcRecord class, which allows you to store any kind of data in a simple-to-use RTC record. To store pointers to persistent objects, which you do NOT want to have destroyed with the connection, simply use the "Info.Obj[]" property.
For objects which you DO WANT to be AUTO-FREED with the connection, you can implement your own custom object container by extending the "TRtcObject" class and implementing the "Kill" method, where you should free all the memory and objects your container "contains", as well as the container itself.
Here is a dummy "container" class extending the TRtcObject class, whose instances can be stored in the "Info.Obj[]" property on the "Sender:TRtcConnection" component and will be autofreed when the connection component is destroyed ...
interface type TMyContainer=class(TRtcObject) public procedure Kill; override; end; implementation procedure TMyContainer.Kill; begin // Make sure the destructor for our container will be called NOW ... {$IFDEF NEXTGEN} DisposeOf; {$ELSE} Free; {$ENDIF} end;
Naturally, that is just a dummy shell class, making sure the container will be autofreed if assigned to the Info.Obj[] property. To store useful information in your container, you will also need a constructor (so you can create and initialize your container), a destructor (to free memory and objects stored), as well as methods and/or properties for accessing the objects and/or data it contains.
If you need more examples, check the "TRtcFileStream" and/or "TRtcObjectManager" classes in the rtcInfo unit, which extend the TRtcObject class to make sure their instances will be autofreed when assigned to the Info.Obj[] property.
Best Regards, Danijel Tkalcec
|