Mega Code Archive

 
Categories / Delphi / Examples
 

Interfaces off the beaten track

Malcolm Groves shows how to use interfaces to automatically destroy objects, restore objects to previous states, cut away swathes of try..finally blocks, and deal with memory leaks. Since interfaces were introduced in Delphi 3, there have been a few articles covering the topic in The Delphi Magazine. Back in Issue 21, Brian Long wrote about this exciting new addition to the Object Pascal language as part of his exploration of Delphi 3. Then, in Issue 32, Marco Cantù took us through an excellent article on simulating multiple inheritance using interfaces. Since then, interfaces have cropped up here and there in various articles, all the way through to last month, when Martin Humby explored the performance issues relating to large-scale interface usage [And this month, even! Ed]. So, if this is the case, what on earth do I think I can add to the topic? Well, I’m actually going to look at a feature of interfaces that is quite often overlooked as simply a side effect, namely lifecycle management. I’m going to introduce you to a few uses for interfaces which maybe you haven’t seen before, and hopefully provide useful utility classes along the way.