|
<< Click to Display Table of Contents >> Delphi Examples: DbiIsRecordLocked |
![]() ![]()
|
Checks the lock status of the current record.
This example uses the following input:
IsRecordLocked(Table1, True);
NOTE: If ByAnyone is true, then the function also checks if any other session has the record locked. If ByAnyone is false, then only the current session is checked. The function returns False if not locked, and True if locked.
The function is:
function IsRecordLocked(Table: TTable; ByAnyone: Boolean): Boolean;
var
Locked: BOOL;
hCur: hDBICur;
rslt: DBIResult;
begin
Table.UpdateCursorPos;
// Is the record locked by the current session...
Check(DbiIsRecordLocked(Table.Handle, Locked));
Result := Locked;
// If the current session does not have a lock and the ByAnyone varable is
// set to check all sessions, continue check...
if (not Result) and (ByAnyone) then begin
// Get a new cursor to the same record...
Check(DbiCloneCursor(Table.Handle, False, False, hCur));
try
// Try and get the record with a write lock...
rslt := DbiGetRecord(hCur, dbiWRITELOCK, nil, nil);
if (rslt <> DBIERR_NONE) then begin
// if an error occured and it is a lock error, return true...
if (HiByte(rslt) = ERRCAT_LOCKCONFLICT) then
Result := True
else
// If some other error happened, throw an exception...
Check(rslt);
end
else
// Release the lock in this session if the function was successful...
Check(DbiRelRecordLock(hCur, False));
finally
// Close the cloned cursor...
Check(DbiCloseCursor(hCur));
end;
end;
end;