[DUG] Object is Object vs Object.Classname = 'Object'
Jolyon Smith
jsmith at deltics.co.nz
Wed Jan 26 09:10:56 NZDT 2011
The two are not comparable in function so cannot really be compared for
efficiency:
if a is b then
Will evaluate true if a is an instance of b or of any class derived from b.
if (abc.Classname = 'TMyObject') then
Will evaluate true only if abc is an instance of TMyObject and only if the
classname of TMyObject uses the exact capitalisation in the comparison
string.
So it depends what you are trying to do... if you need to test for an
instance being of a specific class and only a specific class then the
ClassName comparison is valid, but a more efficient and more type-safe
alternative would be:
if (a.ClassType = TMyObject) then
But if you need to detect when a is of class TMyObject or some class that
ultimately derives from TMyObject, then an is or InheritsFrom() test is the
only option.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20110126/d5b33a09/attachment.html
More information about the Delphi
mailing list