Andrew Stopford's Weblog

poobah

News

Articles

MbUnit Folks

Old Blogs

Play the rumor game

Apologies go out to Borlands Allen Bauer, there is no Delphi 9.0 (I ment Delphi 8.0), nothing short of ashamed I blame the aliens :P Not sure why Allen states that IDispose has nothing to do with helper classes. His article states.

So if you don't "destroy" an object, how do you make it release its references? In .NET, there is a simple pattern that is followed. An object that needs to do immediate resource cleanup, should implement the IDisposable interface. It has one method called procedure Dispose; (or for you that prefer a more "curly" world void Dispose();). Now when you want to "destroy" an item in the container, you cast the item to IDisposable and call the Dispose method. In the Dispose method it just performs the nessesary steps to remove itself from the container.

Sure, you could manually remove the item from the container yourself and forgo the IDisposable riggamarole, but what if you hand the item off to someone that has no specific knowledge of the particular container instance in which the object is currently living? This is why the IDisposable pattern is important.

So let's bring all this around now to Delphi 8 for .NET and its view of the world. All this IDisposable stuff seems tedious and would require some massive changes to my code to play nicely in .NET. This is where Delphi has realized some of the benefit of arriving a little later to the party. Delphi introduces an interesting language construct called "class helpers." There could be a whole tome written about the subject of "class helpers", but suffice it to say, they have given the Delphi programmer a familiar world in which to work. All that code you have written in which you dutifully have implemented your destructors to properly clean up after yourself, release resources, and generally keep your house in order can now continue to live on..and serve a real purpose beyond simply releasing memory. Releasing memory is no longer the responsibility of the lowly Destroy destructor. It now is a cue to the Delphi compiler that you want it to implement the IDisposable pattern for you. Your object now implicitly implements IDisposable and the Dispose method maps to your Destroy destructor

Seems IDispose and helper classes are involved if you ask me? Maybe I have it wrong, lets prevent the rumor game and someone put me stright.

Comments

Allen Bauer said:

Andrew,

Sorry for the mixup. I tried to clarify the relationship between class helpers and IDisposable here:

http://homepages.borland.com/abauer/archives/2004_03_07_archive.php.
# March 8, 2004 11:24 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)