Re: Another shitty example of exceptions
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 04/07/04
- Next message: Skybuck Flying: "Re: D8.NET No Destroy Method ?!"
- Previous message: Mikael Mortensen: "Re: Getfile D3"
- In reply to: Skybuck Flying: "Re: Another shitty example of exceptions"
- Next in thread: Bruce Roberts: "Re: Another shitty example of exceptions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 7 Apr 2004 13:38:58 +0200
"Skybuck Flying" <nospam@hotmail.com> wrote in message
news:c50k7o$2ep$1@news3.tilbu1.nb.home.nl...
[...]
> Since calling a method is only valid if the instance of the class
> exists... otherwise one would normally get an access violation ?!
>
> So I don't understand why it is valid to call .Free on a nil reference ?
Because Free is a static method. For a virtual method, it wouldn't work.
When you write "X.Free", the compiler resolves the Free method and for
static methods, it knows at compile-time which routine will be called:
TObject.Free. If Free were virtual, X might refer to a class which
overrides Free, and inspection of the object X refers to is necessary.
This inspection does assume that X actually refers to an object; if it
doesn't, that's an access violation - you can't dereference nil.
The code generated for "X.Free" is the same as for a non-OO call
"Free(X)", and there is nothing wrong with passing nil as a parameter.
The remaining problem is determining which Free to call, and for static
methods this can be completely resolved at compile time based on the
declared type of X.
Groetjes,
Maarten Wiltink
- Next message: Skybuck Flying: "Re: D8.NET No Destroy Method ?!"
- Previous message: Mikael Mortensen: "Re: Getfile D3"
- In reply to: Skybuck Flying: "Re: Another shitty example of exceptions"
- Next in thread: Bruce Roberts: "Re: Another shitty example of exceptions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]