Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find - List Dialog
Message
 
 
To
10/11/2002 03:21:52
General information
Forum:
Visual FoxPro
Category:
CodeMine
Miscellaneous
Thread ID:
00718579
Message ID:
00730046
Views:
15
Gary,

>Probably the simplest way to do this is to use the native VFP seek command. Seek on the child table to find your record. If you find it, record its primary key in a variable, note its parent's key value to a variable too.

Then, seek on the parent table. When you have found the parent record, using the parent cursor's CDE object, call its RecordWasMoved method. This will re-sync the datamanager with your changes (pointer relocation) to the parent cursor that it did not know about. Then go back to the child table. Depending on your RI logic, the re-sync on the parent table may have moved the child record again. That's OK. <

Would you give the following code a peek. It was a little different, so I wanted your expert advice as I didn't really know how CodeMine 7 deals with me moving these record pointers, etc.

You mentioned calling the RecordWasMoved() in the CDE, but I had problems doing that so I called the THISFORM.cmDataManager.RecordWasMoved() instead. Also, I called the THISFORM.cmDataManager.FIND() to move the child record - which made it selected as I wanted when the lookup form was closed. It seems to be working perfectly, but I was a little concerned since I used the one in the DM. What you think? This code is in the Click() of the CmdToolActionButtonList that I placed on a form.
LOCAL liHouseID, liPersonID, nSelect, nRecno, lOrgTag, lChildFnd

* Set the cWorkArea and select the special cursor we use to
* lookup by. Also set special form required properties.
THISFORM.cWorkArea="PersLook"
SELECT PersLook
THISFORM.cNavWorkArea="PersLook"
* Is special looking up class.
THISFORM.cListDialogClass = "frmPersLook"
DODEFAULT()
* Since frmPersLook is a modal window, following is processed
* after the frmPersLook is closed.

* Store the items from the lookup cursor we will use to search
* the parent and child table with.
m.liHouseID = PersLook.HouseID
m.liPersonID = PersLook.PersonID

* Reset the form to the defaults.
THISFORM.cWorkArea="House"
THISFORM.cNavWorkArea=SPACE(0)
THISFORM.cListDialogClass = "frmDataListForm"
* Select parent cursor and find record.
SELECT House
m.nSelect = SELECT()
m.nRecno = RECNO()
m.lOrgTag = TAG()
SET ORDER TO TAG HouseID
SEEK m.liHouseID
* Return controlling index to original.
IF !EMPTY(m.lOrgTag)
	SET ORDER TO TAG m.lOrgTag
ENDIF
* Either accept the new Parent location, or reject
* it if the parent was not found.
IF FOUND()
	* Following will update required CodeMine items.
	THISFORM.cmDataManager.RecordWasMoved('House')
	* Following finds the correct Child record so that it is selected
	* when RecordWasMoved is called. It should always be OK to start at first child
        * record because of RecordWasMoved() above. The .T. parameter
        * in the following Find() means start search at first child record.
	m.lChildFnd = THISFORM.cmDataManager.FIND("personid == "+STR(m.liPersonID),"Person",.T.)
	IF m.lChildFnd = .F.
		THISFORM.DisplayMessage('The Person record was not found for some reason.')
	ENDIF

ELSE
	* Record was not found. This should be impossible - but we will inform user
	* just in case.
	THISFORM.DisplayMessage('Sorry the House record was not found. Try another.')
	IF m.nRecno <= RECCOUNT()
		GOTO (m.nRecno)  && Restore record pointer.
	ENDIF
	RETURN .T.
ENDIF

* Refresh Form.
THISFORM.REFRESH()
As always, your thoughts are appreciated.

Mel Cummings
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform