>> >> It happens when you try to free an object which either you didn't
>> >> create, or you've already set free.
>> >
>> > Only when the pointer to the object is containin nil. This
>> is not the
>> > case if you free an object and also not the case if the variable
>> > pointing to that object is on the stack and it is not created.
>> >
>>
>> classes declared with the keyword class are never stored on the stack.
>>
>
> I haven't followed your discussion, just mentioning here that
>
> X.Free
>
> Should never fail since it's a class method and its implementation checks
> if
> X is nil. If it's not it calls the destructor of "self" (which is the
> hidden
> param each method gets passed to and will be X in this case)
>
> Procedure TObject.Free;
> begin
>  if self<>nil then
>   self.Destroy;
> end;
>

I just want to say this again:

Free is NOT a class method, is a TObject method. Every class has a Free
method because it is inherited from TObject, but the method is NOT a
"class method".

A "class method" is a method you can call for the class (you don't need an
object to call it) as:

cant:=TMyClass.getInstancesCount; //wich returns the count of objects
created of that class

A class's method is a method that is part of a class (any method not
defined with the class keyword) as:

TheObject := TMyClass.Create();
show := TheObject.ClassName();//wich should return 'TMyClass'

you can't do:

TMyClass.ClassName();

Last thing is that Self has different meanings in "class methods" than it
does in regular methods. In regular methods Self is the object for wich
the method has been called, in "class methods" it is the class for wich
the method has been called.

To understand this, you have to think that every method you declare has an
additional first parameter. If you declare this

procedure TMyClass.Dummy(aNumber:integer);

what you really are getting is:

procedure Dummy(Self:TMyClass;aNumber:integer);

and that's why, when you call:

MyObject.Dummy(5);

the actual call will be:

Dummy(MyObject,5);

giving you, inside the method, Self = MyObject = the object for wich you
called the method.

Hope this clarify things a little.
Bye.
David.

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to