George Birbilis ([EMAIL PROTECTED])
Microsoft MVP J# for 2004-2006
Borland "Spirit of Delphi"
* QuickTime, QTVR, ActiveX, VCL, .NET
http://www.kagi.com/birbilis
* Robotics
http://www.mech.upatras.gr/~Robotics
http://www.mech.upatras.gr/~robgroup
> >> If so, what side-effects would this cause when applied across the
> >> complete class-hierarchy?
> >
> > Blow up the size of you executable.
>
> And a virtual method call is slower than a non-virtual call.
> (as it needs to do a few lookups: class, VMT)
>
> To ensure self is not nil, you can insert a check in a method
> itself. However, you cannot defend yourself against an
> invalid (but non-nil) object pointer. (I.e. a pointer to an
> object that is freed already.)
>
That's why you use a class method. In Delphi you can call a class method upon an object instance. In that case "self" will contain the Object Instance you called it upon (which can be "nil") and not the class reference
E.g.
Type
Tsomething=class
class procedure DoSomethingSafe;
procedure DoSomething;
end;
Procedure Tsomething.DoSomething;
Begin
//access some class fields etc.
End;
procedure Tsomething.DoSomethingSafe;
Begin
if self<>nil then
DoSomething;
End;
Var
x:Tsomething;
Begin
x:=nil;
x.DoSomethingSafe;
End.
