tags:

views:

145

answers:

3

Hi are there any nice videos or other resources on how to use Interfaces in delphi?

I am after the basics and more advanced stuff.

+5  A: 

Not a video, but this explains the basics.

Gamecat
IMHO this is a bad introduction - in the provided example code the interface is not even used. The whole point of interfaces would be a lot more obvious if mumsBike and dadsCar were both of type IRecyclable in TForm1.FormCreate().
mghie
+2  A: 

Since COM uses interfaces this online course is also an introduction to interfaces.

Lars Truijens
+6  A: 

Once you have read stuff on the web you should probably look into code by other programmers to see how (and why) they used interfaces in real code.

For example in the Subversion repository of the dUnit SourceForge site you will find the XPObserver.pas file, which implements the Observer pattern for Delphi, using interfaces. This code is very interesting, as usually in this pattern the observed objects each keep a list of observers, and the observers each keep a reference to the object(s) they observe. A naive implementation using interfaces would create circular references, the interfaces would keep their reference counts from reaching 0, and this would result in memory leaks. The code in XPObserver.pas shows how you can use typecasting to solve this problem.

IMO the most of XP*.pas files are worth a closer look. For example XPInterfacedObject.pas contains an explanation why aggregated interfaces must all use a common reference counter, and presents an alternative solution to TAggregatedObject and TContainedObject as implemented in the VCL.

mghie