[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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
0
Wallstreet
Asked:
Wallstreet
  • 3
  • 2
1 Solution
 
ziolkoCommented:
dont do typecast and use TInterfaceList.
ziolko.
0
 
BorlandManCommented:

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
0
 
WallstreetAuthor Commented:
Thank you verymuch Ziolko
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
WallstreetAuthor Commented:
Thank for the insights BorlandMan
0
 
ziolkoCommented:
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.
0
 
WallstreetAuthor Commented:
Ziolko,

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

Thank You.
Wallstreet
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now