It can sometimes be useful to determine if an object is a instance of a subclass of some specified parent class.
While over-use of this probably suggests a class framework which has not been well designed, it is valuable in specific instances.
There are two static methods on the SysDictClass which can be used for this purpose:
static boolean isSuperclass(classId _id, classId _potentialAncestorId)
This method checks if the classId passed in _id is a subclass of the _potentialAncestorId
static boolean isEqualOrSuperclass(classId _id, classId _potentialAncestorId)
This method checks if the classId passed in _id is a subclass of the _potentialAncestorId, and will also return true if _id equals _potentialAncestorId
The following code uses the SalesTableType heirarchy as an example.
SalesTableType stt;
SalesTableType_Journal stt_j;
;
// This is true as stt is an ''instance'' of SalesTableType
if (SysDictClass::isEqualOrSuperclass(classidget(stt), classnum(SalesTableType)))
{
// Code here will be run
}
// This is true as stt_j is a ''subclass'' of SalesTableType
if (SysDictClass::isEqualOrSuperclass(classidget(stt_j), classnum(SalesTableType)))
{
// Code here will be run
}
// This is true as stt_j is an ''instance'' of SalesTableType_Journal
if (SysDictClass::isEqualOrSuperclass(classidget(stt_j), classnum(SalesTableType_Journal)))
{
// Code here will be run
}
// This is FALSE as stt is NOT an instance or subclass of SalesTableType_Journal
if (SysDictClass::isEqualOrSuperclass(classidget(stt), classnum(SalesTableType_Journal)))
{
// Code here will NOT be run
}
No comments:
Post a Comment