Record insertion, editing, logical deletion and persistence
RecLock(cAlias,lAdd) → fields → MsUnlock(); DBDelete()Distinguishes locking, field changes and logical deletion.
Overview
RecLock(alias,.T.) starts insertion and .F. attempts to lock the positioned record for editing; check its result before writes. MsUnlock ends the lock but alone is not a multi-table business transaction. DBDelete marks logical deletion rather than physically removing data. This example uses an owned temporary table without production records. The referenced community code contains messages inside a transaction and unchecked RecLock calls; those parts are not reproduced. (Sources: refs. 1–3.)
Syntax
RecLock(cAlias,lAdd) → fields → MsUnlock(); DBDelete()Commented example
#Include "Protheus.ch"
User Function Ed485()
Local oTmp := FWTemporaryTable():New(GetNextAlias(),{{"ED_TEXT","C",20,0}})
Local cAlias
// Test temporary table only.
oTmp:Create()
cAlias := oTmp:GetAlias()
If RecLock(cAlias,.T.)
(cAlias)->ED_TEXT := "ED01"
(cAlias)->(MsUnlock())
EndIf
(cAlias)->(DbGoTop())
If !(cAlias)->(Eof())
If RecLock(cAlias,.F.)
(cAlias)->ED_TEXT := "ED02"
(cAlias)->(DbDelete())
(cAlias)->(MsUnlock())
EndIf
EndIf
oTmp:Delete()
FreeObj(oTmp)
Return NilDemonstrates insertion, editing and deletion marking in a temporary table, then removes the owned table. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Prefer business routines and MVC for real records. Provide failure handling, cleanup and concurrency control.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.