Sean ROBINS wrote: > It seems that since Delphi2005 was released, you can declare constants > and types within the body of a class's interface declaration. > > For example: > > unit MyUnit; > > interface > > type > TMyClass = class(TObject) > public > const > A_LITTLE_CONSTANT = 5; > type > TMyInternalEnum = (aFirstItem, aSecondItem, aThirdItem); > > .... > > end; > > implementation > > ... > > end; > > > > The question is, why would you want to use this style of declaration, > and what are the benefits/pitfalls of doing so?
That's cool, I'm glad to hear that's been done. I suspect this syntax represents the Delphi support for certain .NET language features that was implemented for Delphi.NET and back-formed onto the language as a whole. Benefits: It extends the data hiding aspects of class declarations to associated types and constants, increasing abstraction and encapsulation. It provides additional layers of "namespace" scoping for such items. Pitfalls: There's clearly some potential for confusion as this is a fairly big departure from traditional Pascal/Delphi declaration syntax. Question: Are such declarations treated as "static" class properties? I.e. can they be accessed via the class name alone, or is an instance required? For example, can I say?: var X: Integer; EnumVar: TMyClass.TMyInternalEnum; begin X := TMyClass.A_LITTLE_CONSTANT; EnumVar := TMyClass.aFirstItem; ?? I would suspect/hope so; that would be the most parallel with the .NET syntax I presume this is intended to implement. Of course, if such members are declared private or protected, the scoping rules for that should come into play. I don't have D200x or I'd check for myself. :-/ Stephen Posey [EMAIL PROTECTED] _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

