c-treeVCL assumes resource entries will be locked for only short intervals. This means you should process resource updates without permitting user interactions to occur during the actual update. Do not lock a resource and then request user input. If a table is created with transaction control, (either CTCREATE_PREIMG or CTCREATE_TRNLOG has been OR-ed into the file mode at create time), be careful not to include resource updates, (additions, deletions or updates), in long transactions. Locks cannot be released until a transaction commits or aborts.
c-treeVCL resource handling code will automatically unlock resources were necessary, but resources can be manually unlocked by the user. Use the following property to check if a resource is locked or not:
property Locked : boolean read IsLocked;
TCtResource.Locked() returns true if the resource is locked, otherwise it returns false. The following method should be used to unlock resources whose locks are no longer necessary:
procedure Unlock; virtual;
TCtResource.Unlock() releases a lock placed on a resource by one of the following read resource functions: TCtResource.First(), TCtResource.Next() and TCtResource.Find().
Example
procedure UnlockResource(hTable : TCtTable);
var
hRes : TCTResource;
begin
Writeln('Unlocking resource of table ', hTable.Table);
hRes := TCtResource.Create(hTable, 0, 0);
try
// find a resource
if hRes.Find('MyResource', true) then
begin
if hRes.Locked then
begin
Writeln('Resource: ', hRes.Resource, 'is locked');
hRes.Unlock();
end
else
Writeln('Resource: ', hRes.Resource, ' was not locked');
end;
except
on err: ECtError do Writeln('Error ', err.Message);
end;
hRes.Free;
end;