multi lock, how ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

multi lock, how ?

Post by AUGE_OHR »

hi,

i want to make a Sample where i "lock" multi Records
but my Sample does not work the Way i expect :o

i do use RLOCK() but do not UNLOCK so i thought it is still "lock" when "move" to other Record ...
but it seems to UNLOCK when move Pointer ... hm

what i´m doing wrong ... need Idea :idea:

Code: Select all

#include "HMG.CH"
#include "hbthread.ch"

REQUEST HB_GT_WIN_DEFAULT           // Console

MEMVAR aList
PROCEDURE MAIN()
LOCAL nThread
LOCAL nMainThreadID := GetCurrentThreadID()

PUBLIC aList := {}

   nThread := hb_threadStart( HB_THREAD_INHERIT_PUBLIC, @Look4Lock(), @aList )
   AttachThreadInput( nMainThreadID, HMG_ThreadHBtoWinID( nThread  ), .T. )

   USE TIMEWORK SHARE

   GOTO 10
   RLOCK()
   GetLockList(@aList)
   INKEY(3)

   GOTO 20
   RLOCK()
   GetLockList(@aList)
   INKEY(3)

   GOTO 99
   RLOCK()
   GetLockList(@aList)
   INKEY(3)

   hb_threadDetach(nThread)
RETURN

PROCEDURE GetLockList(aList)
   aList := DBRLOCKLIST()
RETURN

PROCEDURE Look4Lock(aList)
LOCAL nSize
LOCAL nCount
LOCAL nThread

   DO WHILE .T.
      nSize := LEN( aList )
      FOR nCount := 1 TO nSize
         @ 0,0 SAY "locked Record Number"
         @ nCount,0 SAY aList[ nCount ]
      NEXT
      hb_idleSleep( 0.5 )
      if INKEY() = 27
         EXIT
      ENDIF
   ENDDO

RETURN
have fun
Jimmy
hansmarc
Posts: 40
Joined: Thu Jun 23, 2016 5:38 am
Location: Belgium

Re: multi lock, how ?

Post by hansmarc »

Hi Jimmy,

use DBRLOCK(recno) in place of rlock().
You must specify the recno if you want another record to be locked.
dbrlock() without argument unlocks all records and locks ONLY the current one.

See also DBRLOCKLIST() thats returns a array with all locked records.

Regards
Hans
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: multi lock, how ?

Post by AUGE_OHR »

hi marc
hansmarc wrote: Thu Nov 10, 2022 3:42 pmuse DBRLOCK(recno) in place of rlock().
have total forgot it, thx
have fun
Jimmy
Post Reply