Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Is this OK?
Mon, Aug 31 2020 1:59 AMPermanent Link

Ian Branch

Avatar

Hi Guys,
Is this construct valid/legal as a means of testing if a record is locked and if it is, exiting the procedure?

{code}
 //
 Try Parts.LockCurrentRecord
 except
   MessageBeep(MB_ICONEXCLAMATION);
   ShowMessage('The Parts record for Part # ' + lblPartNo.Caption + ' is currently in use/locked by another user.' + #13#10 +
     'The operation cannot continue!' + #13#10 + 'Please retry later.');
   Exit;
 End;
 //
 Parts.UnlockCurrentRecord;
 //
{code}

It just seems strange to me.

Regards,
Ian
Mon, Aug 31 2020 2:45 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


Looking at the manual

<<Use the LockCurrentRecord method to manually lock the current row. Row locks established via this
method are persistent and are maintained across any Edit or Delete calls. You must manually unlock any
rows locked using this method via the UnlockCurrentRecord or UnlockAllRecords methods.>>

I'd say it depends what you want it for. My interpretation of the manual is that its different to editing a record and won't notify you if another user has the record locked for editing. I'll need to set up a test bed to try that out.

I looked at the manual a bit more and found

TEDBDataSet.RecordIsLocked Method

<<Use this method to determine if the current row has been locked by the LockCurrentRecord method. This
method only includes manually-locked rows and will not indicate if a row is locked via the Edit method
when the current session's RecordLockProtocol is set to lpPessimistic. Such row locks are considered
implicit.>>

So if its to see if someone else is editing the record - it won't. Have you thought of


{code}
 //
 Try
Parts.Edit;
 except
   MessageBeep(MB_ICONEXCLAMATION);
   ShowMessage('The Parts record for Part # ' + lblPartNo.Caption + ' is currently in use/locked by another user.' + #13#10 +
     'The operation cannot continue!' + #13#10 + 'Please retry later.');
   Exit;
 End;
 //
 Parts.Cancel;
 //
{code}

Roy Lambert
Mon, Aug 31 2020 3:03 AMPermanent Link

Ian Branch

Avatar

HI Roy,
I missed that bit about only being relevant for manual locks. Frown
Your solution will do the Job admirably.  I am even able to eliminate the OnEditError routine I had. Smile

Regards & Tks again,
Ian
Image