Indicates whether the enum instance has the specified flag(s) set.
Return type: LOGICAL
Access: PUBLIC
Applies to: Progress.Lang.FlagsEnum class
(thisInstance AND flags = flags)
This means that if flags has multiple flags set, the method returns TRUE only if all the flags in flags are set in the enum instance. For example:
DEFINE VARIABLE myPermission AS Permission NO-UNDO. DEFINE VARIABLE lRret AS LOGICAL NO-UNDO. myPermission = Permission:Read. /* Returns TRUE. */ lRet = myPermission:IsFlagSet(Permission:Read). /* Returns FALSE because Write is not set in myPermission. */ lRet = myPermission:IsFlagSet(Permission:ReadWrite). /* Returns FALSE because the method is passed both the Read and Write flags because of the bitwise OR, but Write is not set in myPermission. */ lRet = myPermission:IsFlagSet(Permission:Read OR Permission:Write). |
Because IsFlagSet() cannot be passed an enum instance with an underlying value of 0, you must check for that case before using the method, using the EQ (=) or NE (<>) operators or the Equals() method, for example. Using the Permission enum from above, the following example checks that the user's permission level, myPermission, matches the permission level needed, neededPermissions, to perform an operation. The code checks to make sure neededPermissions is not Permission:None first, before invoking IsFlagSet():
DEFINE VARIABLE neededPermissions AS Permission NO-UNDO. DEFINE VARIABLE myPermission AS Permission NO-UNDO. ... myPermission = Permission:Read. IF (neededPermissions NE Permission:None) OR (NOT myPermission:IsFlagSet(neededPermissions)) THEN MESSAGE "You do not have permission for this operation.". END. |