Bram Kuijvenhoven wrote:
> Al Boldi wrote:
> > Bram Kuijvenhoven wrote:
> >>   function TAncestor.ToStringSafe:string;
> >>   begin
> >>     if self=nil then Exit('<nil>');
> >>     Result:=ToString; // now it's safe to call the virtual method
> >>   end;
> >
> > Are you sure it's really safe to call?
>
> I think so: function ToStringSafe:string; is not virtual. You can check it
> yourself by running the code.

Did you ever try calling an instantiated TObject.Free twice?

An invalid self is conceptually incorrect.  Think about it.
It would mean, that you are running inside code that doesn't really exist.
Does this have any meaning other than being some strange hack?

> > BTW, is there a way to make Assigned(obj) really check for a valid
> > pointer?
>
> Not really.
> - When destroying an object, the pointer is invalid, but still points to a
> memory area with about the same data as before; how would you see the
> difference

It should at least reset the calling pointer to nil.

Thanks!

--
Al

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

Reply via email to