Page 1 of 2
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 4:29 pm
by Anonymous
When I USE a DBF and do not set an index or order tag, then I use the SCAN command to iterate over it and print certain records, the order that X# displays the records does not match the order that VFP displays the records.
See screenshot which compares VFP output to X# output.
DBF and CDX attached for testing (in a zip file) Note, the CDX is not used in my code, but I sent it because it is present in the folder.
Here's the code:
Code: Select all
Function TestUseWithScan()
Local lnX As Int
Set Default To "C:WorkLM5AppData"
Field cParent, cFilename
Set Exclusive Off
If !USED("WA1")
Select 0
Use "wwBusinessObjects" Alias "WA1"
Endif
Select WA1
Scan For Deleted() and !Empty(cFilename)
? cFilename
Endscan
End Function
Screenshot:
- 2020-07-29 11_20_56-VPF Xsharp test app 1 (Running) - Microsoft Visual Studio.png (11.38 KiB) Viewed 614 times
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 6:12 pm
by Chris
Hi Matt,
Thanks, so apparently VFP does not automatically open index files, as VO does, we need to change that. For now, you can instruct X# to not automatically open them, by adding this in the beginning of your code:
RddInfo(_SET_AUTOOPEN ,FALSE)
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 6:16 pm
by FoxProMatt
So besides just *opening* the CDX, does it by default also begin using the first index tag or something??
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 6:26 pm
by Chris
Yes!
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 6:27 pm
by FoxProMatt
Chris - why does this code have to go "...in the beginning of your code" ??
Indeed, I found that it has to be pretty early in the Start() function, before my test method is called, and that if I try to place that code within my test function, it has no affect.
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 6:32 pm
by Chris
Hi Matt,
It just has to be called before you open the dbf, because if you open it, by default the RDD automatically opens the index file as well. Unless you tell it not to, with the said function call.
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Wed Jul 29, 2020 10:02 pm
by Karl-Heinz
Chris wrote:Hi Matt,
Thanks, so apparently VFP does not automatically open index files, as VO does, we need to change that. For now, you can instruct X# to not automatically open them, by adding this in the beginning of your code:
RddInfo(_SET_AUTOOPEN ,FALSE)
Hi Chris,
My FP does auto open a structural CDX. My FP even complains when i open a DBF and such a created CDX is not available, saying that the strutural flag will be removed. My FP is too old, so i can´t test Matts wwBusinessObjects.dbf
it seems the strutural flag has been removed from Matts wwBusinessObjects.dbf. That would explain why VFP does not auto open the wwBusinessObjects.cdx, while X# ignores the missing flag and auto opens the wwBusinessObjects.cdx ?
regards
Karl-Heinz
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Thu Jul 30, 2020 5:01 am
by FoxProMatt
It seems the structural flag has been removed from Matts wwBusinessObjects.dbf.
Well, if something is missing, it was not intentional on my part to remove it. Years ago when I created that DBF I simply used the VFP IDE to create the table structure and the 3 indexes that are in the CDX. I have not tinkered with it beyond that.
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Thu Jul 30, 2020 8:22 am
by robert
Matt,
I think you should not use
RddInfo(_SET_AUTOOPEN ,FALSE)
but
RddInfo(_SET_AUTOORDER ,0)
This tells the runtime to open the production index but not select the first tag in the index.
Robert
Record order incorrect using Scan on a DBF with no Index/Order...
Posted: Thu Jul 30, 2020 1:49 pm
by FoxProMatt
Understand, but, consider making this the default behavior in FoxPro dialect, because that existing programs don’t want an order set it and we shouldn’t have to add new code to our old programs to achieve that.