[DUG] Object is Object vs Object.Classname = 'Object'
Ross Levis
ross at stationplaylist.com
Wed Jan 26 15:25:27 NZDT 2011
Yeah, I "clicked" yesterday that I should be using ClassType which is
working correctly for my purpose.
Cheers.
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Jolyon Smith
Sent: Wednesday, 26 January 2011 9:11 AM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Object is Object vs Object.Classname = 'Object'
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/f023af18/attachment.html
More information about the Delphi
mailing list