tryLock(lockTarget: Object; lockType: Integer; lockDuration: Integer; timeout: Integer): Boolean;
The tryLock method of the Object class attempts to acquire a lock of the specified type and duration, waiting up to the timeout period (in milliseconds) to obtain the lock on the object specified in the lockTarget parameter.
If the lock can be acquired, the method returns true. If the lock cannot be obtained, this method returns false and no lock exception is raised.
The following table lists the lock type, lock duration, and timeout system global constant values.
Global Constant | Integer Value | Category |
---|---|---|
Exclusive_Lock | 3 |
|
Reserve_Lock | 2 |
|
Share_Lock | 1 |
|
Update_Lock | 4 |
|
Persistent_Duration | 2 |
|
Session_Duration | 1 |
|
Transaction_Duration | 0 |
|
LockTimeout_Immediate | -1 |
|
LockTimeout_Infinite | Max_Integer (#7FFFFFFF) |
|
LockTimeout_Process_Defined | -2 |
|
LockTimeout_Server_Defined | 0 (use the server-defined default) |
|
The following example shows the use of the tryLock method.
lockException(lockException: LockException): Integer; vars result : Integer; message : String; begin message := "Cannot get lock for " & lockException.lockTarget.String & ". It is locked by user "; result := app.msgBox(message & lockException.targetLockedBy.userCode & ". Retry?", "Lock Error", MsgBox_Question_Mark_Icon + MsgBox_Yes_No); if result = MsgBox_Return_Yes then app.mousePointer := Busy; while not tryLock(lockException.lockTarget, lockException.lockType, lockException.lockDuration, LockTimeout_Server_Defined) do app.mousePointer := Idle; result := app.msgBox(message & lockException.targetLockedBy.userCode & ". Retry?", "Lock Error", MsgBox_Question_Mark_Icon + MsgBox_Yes_No); if result = MsgBox_Return_No then return Ex_Abort_Action; endif; app.mousePointer := Busy; endwhile; return Ex_Resume_Next; else return Ex_Abort_Action; endif; epilog app.mousePointer := Idle; end;