Monday, March 8, 2004

Play the rumor game/Public Instant Messaging

Play the rumor game

OK, Andrew I suppose I owe you an apology as well. I re-read my post and it seems that the tone of my message may have come across a little harsh. It was my feeble attempt at some humor.

I would like to clarify the reason I made the statement that class helpers have nothing to do with IDisposable. Class helpers were introduced into the language to facilitate easier porting of existing Win32 VCL code to .NET. For instance, TComponent has the properties ComponentCount: Integer; and Components[Index: Integer]: TComponent;. Since TComponent is actually declared as an alias to System.ComponentModel.Component, those properties don't exist. By creating class helpers, we can seemingly add methods to existing classes without using inheritance. This is pure "syntactic sugar." When I mentioned the IDisposable thing in the context of class helpers, I was trying to illustrate that <object instance>.Free; pattern was facilitated by the use of class helpers. I tried to indicate that class helpers were a feature in and of themselves; "Delphi introduces an interesting language construct called "class helpers." There could be a whole tome written about the subject of "class helpers"..."

The IDisposable pattern is actually triggered by the declaration of a destructor override. So if you declare an override to destructor Destroy; override; you are telling the compiler to implement the IDisposable pattern. You must override the Destroy; method in order for the compiler to see this pattern. We would have done this even if we didn't have class helpers. That is why I tried to downplay the relationship between class helpers and the IDisposable pattern. The fact that class helpers eased the programmers use of that pattern was purely serendipitous ;-)