The 'TS_InterfaceSafe'-class can be used to 'transport' interfaces in a secure way ( with proper refcounting, and the application dous not have to bother about memory allocation etc. ). The example below shows how the 'TS_InterfaceSafe' is used ( by the library ) to convert a pointer to a 'TS_DelegateIDispatch' ( or 'TS_DelegateIDispatchAuto') instance.
Note: The 'ulAddRef' parameter should normaly be TRUE, If the parameter is TRUE then the 'TS_InterfaceSafe' object will increment 'ref-count' on the in 'uupoAIUnknown' specified interface. The 'ref-count' on the interface is always decremented ( using 'Release()' ) when the interface safe is destroyed.
The 'udwGets' parameter can limit the number of interfaces that can be get from this safe. If this parameter is 1 then only one interface can requested from the safe. When the 'Gets' counter is counted down to zero the safe will release the enclased interface.
Note: All interfaces that are handed out by the 'TS_InterfaceSafe' object will be ref-counted ( using 'AddRef()' ) and the application must 'Release()' the interface that was received from the interface safe.
Example
oInterfaceSafe:=TS_InterfaceSafe{ oOwner, PTR( _CAST, LONG( pstruWinVariantArg.uVariant.ppDispVal ; ...
...) ), TRUE, NIL }
IF oInterfaceSafe:FInit
DO CASE
CASE symClass==NULL_SYMBOL
uRetVal:=TS_DelegateIDispatch{ oOwner, oInterfaceSafe }
CASE TS_IsClassOfClass( symClass, #TS_DelegateIDispatch )
uRetVal:=CreateInstance( symClass, oOwner, oInterfaceSafe )
TSTrace SetCreatedAt uRetVal
CASE TS_IsClassOfClass( symClass, #TS_DelegateIDispatchAuto )
uRetVal:=CreateInstance( symClass, oOwner, oInterfaceSafe )
TSTrace SetCreatedAt uRetVal
OTHERWISE
TSTrace Warning "!TS_IsClassOfClass(symClass,oOwner,#TS_DelegateIDispatch)"
uRetVal:=TS_DelegateIDispatch{ oOwner, oInterfaceSafe }
END
IF !(