> The downside is that the 'protected' feature isn't possible as create is
> public in TObject.  
> Means that an outsider using your class can still unknowingly do a
> TMyGadet.Create even if they're not a descendant.


a good point.

TMyGadget could declare it's own Create (masking the one inherited from
TObject) and just abort something like this:


    type TMyGadget = class(TObject)
    private
        constructor Create;
    end;

    constructor TMyGadget .create;
    begin
       abort;
    end;

but this is less than ideal since a call won't be detected until runtime.


Even if you make it abstract - like this:

    type TMyGadget = class(TObject)
    private
        constructor Create; virtual;abstract;   //hide it
    end;

and then later try to create via

    myGadget := TMyGadget.Create;

you don't get an error at compile time - just a warning.   (Kind of makes
you wonder what happens at runtime though).


Sometimes I wish Borland would just make all members of stuff in the VCL
protected to get around these sorts of problems.     When I need access - 
they have it declared Private.    When I need to hide access - they have 
it declared Public.

Even with that, it would be difficult to prevent a derived class from
calling the wrong Create though since you can't "demote" a method from 
protected to private.

aaaarrgh.

-ns


---------------------------------------------------------------------------
    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"

Reply via email to