Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can SEEK() return .T. but have the wrong record?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00903416
Message ID:
00903656
Views:
20
Thank you all for your quick responses. I didn't get a chance to see them until this morning. I still haven't solved the problem, but I can give you more information that seems relevant.

1. The SEEK that is failing is the one using the primary index, which is based on a numeric field. A field that I never modify.

2. As you know by now, the application I'm working on is populating a TreeView control from a table. The user can modify the tree, and the modifications are put into the table. The table has 5 fields:
- LocID (Integer: the primary index)
- PatientID (integer: the LocID of the parent of this node)
- ChildOrder(integer:, the relative oder of children of a given parent)
- Text (char: the label for the node)
- Description (char: an internal description for the node).

3. The TreeView control itself is working quite well. I can populate it from the table, including getting all children in the right order on each node. Also, drag & drop is working just fine.

4. The DragDrop method is where the problem is. The treeview aspect of that works quite well. The problem I'm having is in the code where I need to modify the ParentID of the node being moved, and the ChildOrder of its siblings under the original and new parents. NOTE: this function neither adds nor removed records from the table, nor, does it modify any LocID values. It just modifies values in ParentID and ChildOrder fields.

5. I am running this form under the VFP debugger using 2 monitors, with the debugger on monitor #2. The status line at the bottom of the VFP main screen shows me the current physical record #. I can also view the table in the Data Session window. So, I can see what it is I am trying to do.

6. The problem is quite reproducible. I can run the form, and drag a certain node (I'll call it node X) from node A, and place it on node B. Then, without restarting the form,I can move it from B back to A. The SEEK()calls all work correctly. If, I then try to repeat this, without restarting the form, the SEEK() returns .T., but instead of setting the record pointer to the record containing NodeX, it set it to record #1. If I exit the form after the first move from A to B and back again, and look at the table, I can see that PatientIDs and ChildOrder have been correctly set. If I run the form again, again, it works correctly in the first move from A to B and back again, but will fail on the next SEEK.

7. The following is the segment of code in DragDrop where this activity takes place:

SET EXACT ON
USE (THISFORM.cDBFname) EXCLUSIVE
IF (THISFORM.oNodex.Parent.Children > 1)&& does node to move have siblings?
SET ORDER TO LOCTREEID
llResult = SEEK(VAL(THISFORM.oNodeX.Key))
nRecord = RECNO() && for debugging purposes
IF llResult = .F.
MESSAGEBOX("SEEK failure.Index: LOCTREEID.Node: "+THSIFORM.oNodeX.text)
ELSE
SET ORDER TO TREEORDER
SKIP 1
SCAN WHILE ParentID = VAL(THISFORM.oNodeX.Parent.Key)&& move up
REPLACE ChildOrder WITH ChildOrder - 1
ENDSCAN
ENDIF
ENDIF
oNewParentNode = oNodeHighlight
IF (oNewParentNode.Children > 0) && down in ChildOrder to make room
SET ORDER TO TREEORDER
cSrchString = STR(VAL(oNewParentNode.Key)) + STR(oNewParentNode.Children)
llResult = SEEK(cSrchString)
nRecord = RECNO()
IF(llResult = .F.) && find last child of new parent
MESSAGEBOX("SEEK fail.Index:TREEORDER."+THSIFORM.oNewParentNode.text)
ELSE
DO WHILE ParentID = VAL(oNewParentNode.Key)
REPLACE ChildOrder WITH ChildOrder + 1
SKIP -1
ENDDO
ENDIF
ENDIF
SET ORDER TO LOCTREEID
llResult = SEEK(VAL(THISFORM.oNodeX.Key))
nRecord = RECNO()
IF (llResult = .F.)
MESSAGEBOX("SEEK failure. Index: LOCTREEID. Node: "+THSIFORM.oNodeX.text)
ELSE
REPLACE ParentID WITH VAL(oNewParentNode.Key)
REPLACE ChildOrder WITH 1
THISFORM.oNodex.Parent = oNewParentNode
THIS.DropHIGHLIGHT = .NULL.
THISFORM.lIndrag = .F.
ENDIF


Thanks again for your help.

Jim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform