Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The approach given by <a href="https://stackoverflow.com/users/255257/jachguate">jachgate</a> is great, and probably better, but in case you do want to implement this, you will need a <code>TThreadList</code> on the server that is created when the service is started. Use the <code>TThreadList</code> because it's thread-safe. You can have on <code>TThreadList</code> per table so that you can minimize the performance hit of navigating the lists. To control what's locked, you'll need an object that's created and passed to the list</p> <pre><code> TLockedItem = class(TObject) public iPK: Integer; iClientID: Integer; end; </code></pre> <p>To do the actual locking, you'd need something like this:</p> <pre><code>function LockItem(pPK, pClientID: Integer): Boolean; var oLockedItem: TLockedItem; oInternalList: TList; iCont: Integer; bExists: Boolean; begin bExists := False; if (Assigned(oLockedList)) then begin oInternalList := oLockedList.LockList; try if (oInternalList.Count &gt; 0) then begin iCont := 0; while ((not bExists) and (iCont &lt; oInternalList.Count)) do begin oLockedItem := TLockedItem(oInternalList[iCont]); if (oLockedItem.iPK = pPk) then bExists := True else Inc(iCont); end; end; finally oLockedList.UnlockList; end; if (not bExists) then begin oLockedItem := TLockedItem.Create; oLockedItem.iPK := pPK; oLockedItem.iClientID := pClientID; oInternalList := oLockedList.LockList; try oInternalList.Add(oLockedItem); finally oLockedList.UnlockList; end; end; end; Result := bExists; end; </code></pre> <p>That's just an ideia of what you'd need. You would have to do an unlock method with similar logic. You'd probably need a list for the clients, that would keep a point of each TLockItem held by each client, in case of lost connection. This is not a definitive answer, just a push on the direction, in case you want to implement this approach. <br> Good luck</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload