IF <find a slot> AND (RLOCK() or RetryLock()) REPLACE..... UNLOCK ELSE * other code to create a slot ENDIF * Retrylock is a UDF of mine which retries a lock attempt after RLOCK fails.I believe in avoiding FLUSH and particularly FLOCK(). RLOCK() and UNLOCK do an implicit flush. Your existing code made it possible for update attempts on the same record.
FUNCTION RetryLock PARAMETER cAlias, msg * Attempt to lock a record and return .T. if successful. * NOTE: The calling program MUST already have attempted an RLOCK() * IF RLOCK() OR RetryLock() * <replace etc> * ENDIIF * * msg is optional IF EMPTY(m.cAlias) * lock current work area cAlias= ALIAS() ENDIF IF TYPE('m.msg') # 'C' msg= 'The program is currently unable to access a record or file.' ; + 'You can retry now, or cancel and try again later.' ENDIF DO WHILE MsgBox(m.msg, 'File/Record in use by another.', 69) = 4 * User is being persistant! IF RLOCK(m.cAlias) RETURN .T. ENDIF ENDDO * User has given up hope! RETURN .F.>Earlier today I was troubleshooting a foxpro 2.6 application. There seemed to be a multi-user issue which really threw me for a loop.
>MSLOT = 0 >MSLOTCATG = SPACE(10) >IF .NOT. EMPTY(PRODUCT.DEPARTMENT) > SELECT DEPTTYPE > SEEK PRODUCT.DEPARTMENT > IF (.NOT. EMPTY(DEPTTYPE.SLOTCATG)) && Should this product get a slot > MSLOTCATG = DEPTTYPE.SLOTCATG > SELECT SLOTS > DIDITLOCK = FLOCK() > > LOCATE FOR EMPTY(SLOTS.PRODUCT_ID) .AND. SLOTS.SLOTCATG = DEPTTYPE.SLOTCATG > IF (FOUND()) > MSLOT = SLOTS.SLOT > REPLACE SLOTS.PRODUCT_ID WITH MPRODUCTID,; > SLOTS.ARTIST WITH MARTIST2,; > SLOTS.TITLE WITH MTITLE2,; > SLOTS.DEMO WITH SPACE(1) > ELSE >>... code to execute if there aren't any more slots. ...
> ENDIF > ENDIF >ENDIF >FLUSH >UNLOCK IN SLOTS >>