George Birbilis wrote: > Sorry for rushing to reply below, indeed "Free" is a non-class, > non-virtual method in Delphi7 sources too, just checked it > > Regarding the stuff I say below though, not sure what "self" contains > (at the someClassMethod code body) when you do > someInstance.someClassMethod() instead of someClass.someClassMethod(). > Does it always contain the class self or the "someInstance"? (be it nil > or not). I'd expect the 2nd !
Neither. It contains the class of self. > > cheers, > George > > ---------------- > 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. > > > > ------------------------------------------------------------------------ > > avast! Antivirus <http://www.avast.com>: Outbound message clean. > > Virus Database (VPS): 0625-0, 19/06/2006 > Tested on: 19/6/2006 1:27:04 ìì > avast! - copyright (c) 1988-2006 ALWIL Software. > > _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
