Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General Tcursor question 1

Status
Not open for further replies.

CleoMan

Programmer
Jun 18, 2003
110
ZA
This might sound vague, but I'm not looking for an exact answer, so bear with me.

I use tcursor in a loop. The following code for the tcursor is place inside the loop. (The loop works fine)

tCursor.Column1 = 100
tcursor.column2 = "sss"
tCursor.postRecord()
sleep()

But for some or other reason the tcursor does not insert all 121 records (nr of times the loop executes) as I want it to. Only two records are inserted...

Any idea as what to look for or what I might be doing wrong?

Thanks
Richard
 
First, if you are not in a scan loop (or have code to advance the record number, like tCursor.nextRecord()) then you are not stepping though a table, you are simply changing the same record over and over.

Second, if the table is keyed on either or both of these fields then you may be causing a key violation.

Third, you do not need to post each record or sleep(). It's unnecessary and slow.

Code:
scan tCursor:

  tCursor.Column1 = 100
  tcursor.column2 = "sss"

endscan



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Richard,

Let me try to add some details to Mac's advice:

1. Are you changing a field in the index currently being used by the tCursor, either one of the key fields or a field in the current secondary index? If so, that's why you're not see updates in all your records.

When you update a field that's paret of the current index, the record "flies" to the new location when it's posted. Thus, the record pointer used by the scan loop no longer points to the same location in the table.

If this is what's happening, then you need to replace your scan loop with a loop that tests for the end of record condition, e.g:

Code:
while not tc.eot()
   tc.KeyField = atNewValue
   tc.next()
endWhile

2. If you aren't modifying a field that's part of the selected index, then you are (as Mac alluded) probably violating some integrity constraint. For example, you might be:

-- Duplicating a value that has a Unique index assiciated with it.

-- Trying to use a value that's below the Min valcheck or above the Max valcheck.

-- Trying to change the field to a value that's not in a lookup table defined with the table.

-- Running into some other integrity contraint declared in the table's structure.

However, I must disagree with Mac about the utility of formally posting changes, for that's the only way to test for this condition and determine what the exact problem is.

In my experience, I have found it helpful to be as explicit with Paradox as possible (and I'm not talking about the language all programmers speak: profanity).

Instead, I'm suggesting that Paradox and ObjectPAL try to be very forgiving environments for the novice and "helpfully" understand situations where you've not been as careful as you might be.

When this happens, you periodically get results that aren't precisely what you expected. These typically take a long time to troubleshoot and, when you've finally nailed the problem, you're often frustrated by what seems to be a silly response by Paradox/ObjectPAL.

In truth, the only way to get exactly what you want out of ObjectPAL is to be as clear as possible in your code. That is, instead of coding: action( dataPostRecord ), you should write point that action to a certain object, e.g. active.action( DataPostRecord ).

Now, I can't really go into all the relevant details at the moment, but this actually applies to the possible scenario I outlined earlier.

To determine if you are accidentally violating an integrity constraint, you need to:

1. Open the form in a Design window.

2. If you do not see the Program menu on the main menu, choose Tools | Settings | Developer Preferences, place a checkmark in the Show Developer menus checkbox on the General tab, and then choose OK.

3. From the Program menu, place checkmarks next to the Program | Compiler Warnings and Program | Compile with Debug settings. (This tells Paradox to provide more detailed information for errors and this extra information can frequently lead you to the source of the problem that generated the error.)

4. Near the start of your code, add the following line:

Code:
   errorTrapOnWarnings( Yes )

This tells Paradox to treat all errors the same. The frequently helps you find the actual line of code that failed, instead of the line of code that was confused by the failure.

5. Save and run your code.

Also, keep in mind that Paradox's error dialogs often provide additional details, but only when you click the [>>] button. When enabled, this button displays more specific information about the error. These details frequently explain the specific problem.

In any event, you need to review your code and see if you're changing a field that's part of the current index. That should help you determine your next steps.

Hope this helps...

-- Lance
 
One other thing I do when I'm dealing with changing key values with scan loops is to create a static key set using a query. For example let's say we have a Parts table with three fields: PartID, PartType, and PartInfo. The first field is the key and I need to make some changes to that value. Let's say I need to change the PartID values of all entries with the Part Type of 'Car'. I'd do a query of the Parts table for all records containing 'Car' in the PartType field and include PartId and PartType in the result set of Answer.db

Then I would open answer.db and parts.db with respective tCursors (ansTC and partTC). Stick partTC in edit mode and ansTC in a scan loop. Use locate to make the changes.

Code:
var
 partTC, ansTC     tCursor
endvar

partTC.open(":work:parts.db")
partTC.edit()
ansTC.open(":priv:answer.db")

scan ansTC:

   partTC.locate("partID",ansTC.partID)
   partTC.partID = (partTC.partID + "xx")

endscan

partTC.endEdit()
partTC.close()
ansTC.close()


Not elegant perhaps, but slap some error trapping on it and it works for me.



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Whoa, that is some information overload. I'll have to read through all the advice a few more times :)

Yes I do use a scan loop, I basicaly copye fields from table 1 to table 2 , but require aditional information from table1 to be found in other tables..

So I use the scan to loop through table 1, get all the information needed for table 2 and the use insertRecord.

I want to thank all of you sincerley for all the help and advice, and do know that I only post after I have tried to fix the error myself, and could not do so..

As always grateful
Richard

PS: Do not get frustrated with my simple questions and keep in mind that my company is only one of two in my country that uses paradox, so if I seem uneducated with Paradox it is becuase I am.. :)
 
I used the debugging technique explained by Lance, and I found that there was a key violation.

I corrected the problem by changeing the key into a autonumber field, and lo and behold the code worked perfectly.

So, Lance and Langley: Thanks!

-Richard-

 
Richard,

Glad the hear you solved the problem and I'm sorry the amount of information was overwhelming. I sometimes get carried away in my explanations.

Still, it's given me a couple of ideas for articles on my site, so... :)

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top