xsharp.eu • DBF with keyword "REF"
Page 1 of 1

DBF with keyword "REF"

Posted: Mon Sep 09, 2024 9:18 am
by dododo01
Hi,

We use a DBF file with an attribute named "REF" which is a primary key.
This file is used with applications developed under VO 2.7b. This does not pose any problem.
However, when migrating to XSharp, knowing that "REF" is a keyword, it no longer works.

Is there a solution, without modifying the DBF file, to get around this problem?

Thanks.

Re: DBF with keyword "REF"

Posted: Mon Sep 09, 2024 1:07 pm
by Chris
That should work also in X#. What is the code that you use that gives you problems?

Re: DBF with keyword "REF"

Posted: Tue Sep 10, 2024 8:05 am
by dododo01
Here is an example of code that does not work:

[STAThread];
FUNCTION Start() AS INT
LOCAL oXApp AS XApp
TRY
oXApp := XApp{}
oXApp:Start()
CATCH oException AS Exception
ErrorDialog(oException)
END TRY
RETURN 0

CLASS XApp INHERIT App
METHOD Start()

TestDBFNTX()

SELF:Exec()

END CLASS
FUNCTION TestDBFNTX()
LOCAL oDB AS DBserver
LOCAL ii AS DWORD
LOCAL sIndex AS STRING
LOCAL cpt AS DWORD

oDB := DBserver{"c:\temp\tests\dodo.dbf", FALSE, FALSE, "DBFNTX"}
IF !oDB:used
TextBox{ , "Error", "open error : "+sIndex}:Show()
ELSE
cpt := 0
FOR ii:=1 TO 20
sIndex := "c:\temp\tests\dodo"+PadL(AllTrim(Str(ii, 2, 0)), 2, "0")+".ntx"
IF !oDB:CreateIndex(sIndex, "REF")
TextBox{ , "Error", "Index create error : "+sIndex}:Show()
ELSE
cpt ++
ENDIF
NEXT ii
oDB:Close()
TextBox{ , "Information", AsString(cpt)}:Show()
ENDIF
RETURN



The problem occurs when the index was created with VO and when using DBserver:SetIndex in XSharp.

Re: DBF with keyword "REF"

Posted: Tue Sep 10, 2024 10:19 am
by Chris
Thanks, I see the problem, so it happens when creating an index. It's a bug, will open a report about this for it to be fixed, but fortunately there's a workaround you can use, change

oDB:CreateIndex(sIndex, "REF")

to

oDB:CreateIndex(sIndex, "@@REF")

and it should work. The "@@" in front of a keyword name tells the compiler (and the macrocompiler here, which is used to compile the index expression) to not treat the keyword as such, but as a regular identifier instead.

Re: DBF with keyword "REF"

Posted: Tue Sep 10, 2024 12:11 pm
by dododo01
it works in XSharp.
However, the new index "@@REF" is no longer readable by VO. Too bad.
thanks for your feedback.

Re: DBF with keyword "REF"

Posted: Tue Sep 10, 2024 1:19 pm
by Chris
Ah, right, sorry about that. Are you a FOX subscriber? If yes, I will send you a fix as soon as this is fixed.

Re: DBF with keyword "REF"

Posted: Wed Sep 11, 2024 9:59 am
by dododo01
No, I am not a FOX subscriber

Re: DBF with keyword "REF"

Posted: Wed Sep 11, 2024 10:17 am
by Chris
That's fine of course, I think the problem will have been fixed until the release of the next public build and will be included in there. Unless it proves very difficult to fix it (it's a problem in the macro compiler and might be a bit complicated), but I don't expect so.

Link to the reported issue, so you can monitor its progress: https://github.com/X-Sharp/XSharpPublic/issues/1557