Alex,
The reason you're experiencing this is because your cursor is table buffered. When you click the Cancel button in the edit form, CListObjEdit is sending a cancel() message to the business object which removes the record from the cursor!
I thought about this and came up with the following solution that works for both row and table buffered cursors...let me know how this works for you:
1. Add a new method to KBizObj called SaveFieldValues() that contains the following code:
LOCAL loSelect
loSelect = CREATE('CSelect', This.GetAlias())
IF NOT PEMSTATUS(This, "oValues", 5)
This.AddProperty("oValues")
ENDIF
SCATTER NAME This.oValues MEMO
2. Add another new method to KBizObj called RestoreFieldValues() that contains the following code:
LOCAL lcAlias, lnField, lnFldCnt, lcCmd
lcAlias = This.GetAlias()
lnFldCnt = FCOUNT(lcAlias)
FOR lnField = 1 TO lnFldCnt
lcField = FIELD(lnField, lcAlias)
IF NOT EVAL(lcAlias + "." + lcField) == EVAL("This.oValues."+lcField)
lcCmd = "REPLACE " + lcField + " WITH " + "This.oValues." + ;
lcField + " IN " + lcAlias
&lcCmd
ENDIF
ENDFOR
3. Change CListObjEdit.cmdEdit.Click() as follows:
Change...
llRetVal=DoForm(THIS.Parent.cEditForm,.F.,ThisForm,This.Parent.oBizObj)
IF NOT llRetVal
*-------------------------------------
*--- The user selected Cancel in the
*--- CListObjEditForm. Cancel any
*--- edits to the record
*-------------------------------------
This.Parent.oBizObj.Cancel()
ENDIF
To...
*----------------------------------
*--- Save the original field values
*----------------------------------
This.Parent.oBizObj.SaveFieldValues()
*--------------------------------------------
*--- Edit the currently highlighted record
*--- Indicate EDIT mode, pass a reference
*--- to this form and the list object.
*--------------------------------------------
llRetVal=DoForm(THIS.Parent.cEditForm,.F.,ThisForm,This.Parent.oBizObj)
IF NOT llRetVal
*-------------------------------------
*--- Restore the original field values
*-------------------------------------
This.Parent.oBizObj.RestoreFieldValues()
ENDIF
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com