Author: William Gerbert
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..
1 program dummy;
2 3 var4 a, b: TObject;
5 6 begin7 // some code to assign the pointers8 // ...9 10 // now evaluate the RTTI of two instantiated objects11 if a is b then12 ShowMessage('a is derived from b or same class');
13 14 if a.classtype = b.classtype then15 ShowMessage('a and b are of the same class');
16 17 // alternative to ClassType comparison (slower!)18 if a.ClassName = b.ClassName then19 ShowMessage('a and b are of the same class')