The distinction is important when you do not explicitly use the Nil constant value. Assigned may have been originally intended for that, it became used generally for opaque pointer references, to maintain that opacity.
Assigned() is a built-in function handled by the compiler. I don't think it is overloaded, as there are no definitions to overload. It only works on types which ultimate derive from, or are identical to, the Pointer type. It shouldn't be any slower than a comparison to Nil, since that is what it is replaced with at compile-time, at least on the Windows platform.Probably best to use Assigned for readability, It's most likely an inline function however It's also an overloaded function so I believe there's run-time type checking going on, don't really know but probably is. If so it'd be technically faster to stick with nil comparisons. Maybe, I'm only assuming that type checking for overloaded functions is run-time for all types, I think it is for class types. Or maybe not, class instance reference being a pointer, maybe you can't have overloaded functions for different class types with the same calling conventions, meaning that overloading might be a compile time thing. Perhaps the compiler will optimize when the program only ever uses one version of the overloaded function. Maybe.
I'm probably giving this too much thought. I'm a bit bored today. In fact it'd probably just be quicker to fire up Lazarus and try overloading a function with different class types.
EDIT : yes you can overload with identical calling convention for different class types so it's Run Time type checking and nil comparisions are faster (At least in ObjFPC mode with FPC) for class references and pointers. Assuming of course that a nil comparison isn't also subject to run-time checks, which it probably isn't as it wouldn't get past the compile time checks.
I should imagine overloaded functions with different conventions are sorted out at compile time though.
I have no idea what you are referring to with respect to Assigned. It is simply a built-in function which the compiler hard-codes to a Nil check. If you're not explicitly using Nil as a data value, or are dealing with opaque (pointer) types, it is more "proper" to use Assigned.
Bookmarks