RLock

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Apollo VCL Component Reference > TApolloTable > TApolloTable Methods >

RLock

Declaration

function RLock( lRecNum: LongInt ): WordBool;

Description

Locks the defined record. Apollo supports multiple record locks (except under D3 and CB3). So, if you lock one record, and do not Unlock it before locking another record, both records will be locked. Use the LockCount property to tell how many records are currently locked.

 

image\tip.gif Under earlier releases, this function was, for the most part, simply remapped to call TDataSet's Edit method, and was simply included to assist in migration from Xbase syntax. However, that behavior precluded the use of Apollo's multiple record-locking functionality and has since been changed. The new behavior is to not place the record in Edit mode, but to simply apply the lock. Therefore, before updating a record in this way, you should either set SpeedMode to True, or just use the Edit method instead. You should generally only call RLock directly when you require multple records locked at the same time, or when using SpeedMode on a shared table. NOTE: Multiple record locking is not available under Delphi 3.x.

Parameters

lRecNum: The physical record number of the record to be locked. If another record is already locked by the same task, it is not released before the new lock is placed.

Return Value

True if the lock is successful and False if not. Apollo will retry locks according to the time-out value established by SetLockTimeout.

 

image\tip.gif On a peer-to-peer network (such as Windows NT), you must set OptimisticBuffering to False. Otherwise, RLock will always return True and Locked will always return False. This is because with Optimistic Buffering enabled, no locks are actually applied. RLock still returns True because there is no reson to deny access to the record in that mode. On dedicated server networks (such as Novell Netware) Optimistic Buffering is turned off automatically by default.

Delphi Example

// Single record lock example

with ApTbl do

begin

SpeedMode := True; 

if RLock( RecNo ) then

begin 

 StrPCopy( cpTemp, Edit1.Text ); 

 Replace( 'NAME', R_CHAR, @cpTemp ); 

 Unlock( RecNo ); 

end 

else 

 ShowMessage( 'Record lock failed' ); 

 SpeedMode := False; 

end;

 

// Multiple record lock example

with ApTbl do

begin

 IndexName := ''; // Natural order

 SpeedMode := True; 

 GoTop; // Move to the top of the table

 for i := 1 to 10 do // Lock the first 10 records

 begin 

         try  

                 RLock( RecNo );

         except  

                 ShowMessage( 'Could not lock record #' + IntToStr( RecNo )); 

 end; 

end; 

 

Unlock( 5 ); // Unlock only record number 5

 

SpeedMode := False; 

end;

C++Builder Example

// Single record lock example

ApTbl->SpeedMode = TRUE;

if (ApTbl->RLock( ApTbl->RecNo ))

{

 StrPCopy( cpTemp, Edit1->Text ); 

 ApTbl->Replace( "NAME", R_CHAR, cpTemp ); 

 ApTbl->Unlock( ApTbl->RecNo ); 

}

else

 ShowMessage( "Record lock failed" ); 

ApTbl->SpeedMode = FALSE;

 

// Multiple record lock example

ApTbl->IndexName = ""; // Natural order

ApTbl->SpeedMode = TRUE;

GoTop(); // Move to the top of the table

for (i=0; i<10; i++) // Lock the first 10 records

{

 if (ApTbl->RLock( RecNo ) = FALSE)

         ShowMessage( "Could not lock record #" + IntToStr( RecNo )); 

}

ApTbl->Unlock( 5 ); // Unlock only record number 5

ApTbl->SpeedMode = FALSE;

See Also

FLock, Locked, LockCount, LockList, SetLockTimeout, Unlock