Record order incorrect using Scan on a DBF with no Index/Order...

This forum is meant for questions about the Visual FoxPro Language support in X#.

Anonymous

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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
2020-07-29 11_20_56-VPF Xsharp test app 1 (Running) - Microsoft Visual Studio.png (11.38 KiB) Viewed 695 times
Attachments
wwbusinessobjects.zip
(5.41 KiB) Downloaded 84 times
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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)
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FoxProMatt

Record order incorrect using Scan on a DBF with no Index/Order...

Post by FoxProMatt »

So besides just *opening* the CDX, does it by default also begin using the first index tag or something??
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Record order incorrect using Scan on a DBF with no Index/Order...

Post by Chris »

Yes!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FoxProMatt

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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.
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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
FoxProMatt

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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.
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FoxProMatt

Record order incorrect using Scan on a DBF with no Index/Order...

Post 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.
Post Reply