DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Testing if two objects are 'related' or 'identical' (RTTI)

Do you need to know whether object a is of a derived class from the class that another object b is of? Or if they may even be of the same class?

The following little code snippet tells it..

program dummy;
   b: TObject;
   // some code to assign the pointers
  // ...

   // now evaluate the RTTI of two instantiated objects
  if a is b then
     ShowMessage('a is derived from b or same class');
   if a.classtype=b.classtype then
     ShowMessage('a and b are of the same class');
   // alternative to ClassType comparison (slower!)
  if a.ClassName=b.ClassName then
     ShowMessage('a and b are of the same class')
You don't like the formatting? Check out SourceCoder then!
Generated 4:01:54 on Oct 21, 2017