Bob wrote:

> Horrors!  I'm in the process of familiarising myself with the new
> VB for .NET.  In all fairness I must say its not too bad at all,
> though I've been having quiet gloats at the "new" language
> features ("ha! - had that in Delphi 1" etc.).  I hadn't
> discovered any capabilities I wasn't familiar with in Delphi,
> until I came across VB's Shared class data members.
>
> They work like this: a data member is declared as Shared (scope
> can be specified normally) and all instances of the class and its
> descendants share the same variable - a bit like having a global
> with class scope.  I can see how they'd be useful in some situations.
>
> Quelle horreur, out-gunned by VB!  I can't find an equivalent in
> Delphi - this is even worse than losing the Americas cup!  Can
> anyone put me out of my misery and point out a feature of
> deepest, darkest Delphi where we can do the same?

Actually, C++ has them too since day 1 - they're called static or class
members in C++.

Delphi has class functions and class methods, but not class members.

You could 'fake' them by having a class function which returns an object
instance which was kept in a private (i.e. implementation section) unit
variable.

In fact, we use this idiom in a number of places - the class function even
operates as a singleton factory i.e. it creates an instance the first time
it's called and returns that instance thereafter.

This is sometimes quite handy for avoiding for resolving tricky
initialization order issues between cooperating classes in different units.

TTFN,
  Paul.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to