Link to home
Start Free TrialLog in
Avatar of Wallstreet
Wallstreet

asked on

How to add an Interface type to a container

Hello All,

Can anybody tell me how I could add an Object (which has been typecasted to an Interface) in any of Delphi Containers.

The reason I have typecasted to an Interface is, mainly due to multiple inheritance.

I tried to add the object to a TList and to a TObjectList with no success. It says "Incompatible types"

It looks like TList or TObjectList don't like to add anything which has been typecasted to an interface.


Thanks in advance,
Jeewa
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BorlandMan
BorlandMan


yep.

also, keep in mind that when you add that interface to TInterfacelist that the Interface will not drop out of memory until you delete it from the TInterfaceList.... which is pretty much what you want (right?)

J
Avatar of Wallstreet

ASKER

Thank you verymuch Ziolko
Thank for the insights BorlandMan
WallStreat one more tip if You will try to typecast Interface to pointer You have to call _AddRef after typecast and _Release before destroying interface.
ziolko.
Ziolko,

I don't have an immediate need to do that but appreciate you telling me.

Thank You.
Wallstreet