xsharp.eu • FoxPro table didn't open in X# FoxPro Console - Page 2
Page 2 of 6

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 1:30 am
by cecilchamp
Still looking for Project Options...
Chris wrote:Hi Matt,
FoxProMatt_MattSlay wrote:Use

Code: Select all

FIELD LastName
Just like you do for LOCAL


This is because the X# compiler requires everything referred to in your code to be identified.

You can turn this off with a compiler option if you want to use non-declared variables.
You just need to enable the options "Enable Memvar Support" and "Enable Undeclared variables support" (in the Language page of the Project options) and then the compiler will allow using it also undeclared. It will still report a warning though, just in case you did that accidentally in code, so make sure you do not have "warnings as errors" also enabled, because this will turn the warning into an error.

FoxPro table didn't open in X# Foxo Console

Posted: Sun Nov 24, 2019 1:39 am
by FoxProMatt
Without SET DEFAULT working, you will need to specify the full path to where the DBF is located.

Just because you put it in your project folder that is not good enough. In Visual Studio developer sessions, when you run the app, it actually compiles to an EXE located and running from the Bin folder in your project, which is not your root project folder that’s why I cannot find the DBF file.

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 3:03 am
by Chris
cecilchamp wrote:Still looking for Project Options...
Chris wrote:Hi Matt,
FoxProMatt_MattSlay wrote:Use

Code: Select all

FIELD LastName
Just like you do for LOCAL


This is because the X# compiler requires everything referred to in your code to be identified.

You can turn this off with a compiler option if you want to use non-declared variables.
You just need to enable the options "Enable Memvar Support" and "Enable Undeclared variables support" (in the Language page of the Project options) and then the compiler will allow using it also undeclared. It will still report a warning though, just in case you did that accidentally in code, so make sure you do not have "warnings as errors" also enabled, because this will turn the warning into an error.
Right-click on the Project name in the Solution Explorer in VS and select "Properties" from the context menu. Then navigate to the "Language" page on the left, you will find the two options there.

As for SET DEFAULT, you can simply use for now

SetDefault("C:addrdata")

or, define this in the top of your .prg file

#command SET DEFAULT TO <path> => SetDefault(<path>)

and then use in your code

SET DEFAULT TO "C:addrdata"

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 3:22 am
by cecilchamp
Okay, now I am starting to get somewhere, sort of.

Found the Language properties under the application. These were set already to the below values. Still have an issue with the USE command.

Memory Variables
Enable Memvar Support - TRUE
Enable Undeclared Variables support - TRUE

I will do the other things you mentioned with SET DEFAULT. Still need to determine why USE won't open the table.
Thanks Chris!

My entire code follows:

Code: Select all

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text

#command SET DEFAULT TO <path> => SetDefault(<path>)
#command USE <(db)>                                                     ;
             [VIA <rdd>]                                                ;
             [ALIAS <a>]                                                ;
             [<new: NEW>]                                               ;
             [<ex: EXCLUSIVE>]                                          ;
             [<sh: SHARED>]                                             ;
             [<ro: READONLY,NOUPDATE>]                                  ;
             [INDEX <(index1)> [, <(indexn)>]]                          ;
                                                                        ;
      => dbUseArea(                                                     ;
                    <.new.>, <rdd>, <(db)>, <(a)>,                      ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>        ;
                  )                                                     ;
                                                                        ;
      [; dbSetIndex( <(index1)> )]                                      ;

FUNCTION Start() AS VOID STRICT
    LOCAL i AS INT
    Field LastName
    
    SET DEFAULT TO "C:addrdata"
        
    SELECT 0
    USE address Index lfname
    FOR i = 1 to 3
        ? LastName    
    ENDFOR
	RETURN	

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 6:47 am
by Karl-Heinz
Hi Cecil,

About your open problem: Check via RddSetDefault() which Dbf engine is used. When i select the Foxpro dialect the default driver is still "DBFNTX". What you need is the "DBFVFP" driver.

Code: Select all

FUNCTION Start() AS VOID STRICT
    LOCAL i AS INT
//    Field LastName

   ? RddSetDefault()  //  // <---- does it show"DBFNTX" ?
    
     RddSetDefault ( "DBFVFP" )  // <---- Foxpro driver 

  ? RddSetDefault()  //  // <---- must show "DBFVFP"
    
   
    SET DEFAULT TO "C:addrdata"
        
    SELECT 0
    USE address Index lfname
    FOR i = 1 to 3
        ? LastName    
    ENDFOR
	RETURN	

regards
Karl-Heinz

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 12:52 pm
by FoxProMatt
Cecil- are you sure your started with a VFP dialect project?

Right-click in the project in solution Explorer and click proprieties. You can see what the Dialect is.

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 1:08 pm
by cecilchamp
Yes. I picked FoxPro Console. However, I went to Dialect in Properties and found in "Visual FoxPro Compatibility- Inherit from Custom Class" was set to FALSE. Does that matter?

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 1:13 pm
by cecilchamp
Karl, did you mean for me to use that as a Function in the program? If yes, I got nothing back. Otherwise, I am not sure how to check which driver is being used.

Application under Properties shows:
Dialect - FoxPro
Output Type - Console Application

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 1:14 pm
by FoxProMatt
Are you getting a compiler error or a runtime error?

FoxPro table didn't open in X# FoxPro Console

Posted: Sun Nov 24, 2019 1:20 pm
by cecilchamp
All I see is the Console black screen appear and then USE is highlighted with a Red background dot at the end of the code line with a white X in it. The note shows XSharp.RDD.RddError: 'Exception or type 'XSharp.RDD.RddError' was thrown.'

More Details follow:

XSharp.RDD.RddError
HResult=0x80131500
Message=Exception of type 'XSharp.RDD.RddError' was thrown.
Source=XSharp.RT
StackTrace:
at XSharp.RDD.DBF._dbfError(Exception ex, UInt32 iSubCode, UInt32 iGenCode, String strFunction, String strMessage, UInt32 iSeverity)
at XSharp.RDD.CDX.CdxTag.EvaluateExpressions()
at XSharp.RDD.CDX.CdxTag.Open()
at XSharp.RDD.CDX.CdxTag..ctor(CdxOrderBag oBag, Int32 nPage, String cName)
at XSharp.RDD.CDX.CdxTagList.ReadTags()
at XSharp.RDD.CDX.CdxOrderBag.Open(DbOrderInfo info)
at XSharp.RDD.CDX.CdxOrderBagList.Add(DbOrderInfo info, Boolean lStructural)
at XSharp.RDD.DBFCDX.Open(DbOpenInfo info)
at XSharp.CoreDb.<>c__DisplayClass111_0.<UseArea>b__0()
at XSharp.CoreDb.Do[T](Func`1 action)
at XSharp.CoreDb.UseArea(Boolean lNew, Type rddType, String cName, String cAlias, Boolean lShare, Boolean lReadOnly)
at XSharp.CoreDb.<>c__DisplayClass109_0.<UseArea>b__0()
at XSharp.CoreDb.Do[T](Func`1 action)
at XSharp.CoreDb.UseArea(Boolean lNew, _RddList rddList, String cName, String cAlias, Boolean lShare, Boolean lReadOnly)
at XSharp.RT.Functions.DbUseArea(__Usual[] Xs$Args)
at ConsoleApplication4.Exe.Functions.Start() in C:UserscecilsourcereposConsoleApplication4Program.prg:line 30

I think it is NOT handling the CDX file that is attached to the DBF file.

See below screen shot.

I finally figured it out. It was the CDX file. XSharp can't seem to handle it. I created a 2-record table without a CDX file and it worked just fine. Also, Since I was initially using FOR/ENDFOR, I should also have used SKIP to display the next record. It didn't matter anyway since the CDX file could not be handled. This must be part of ORDER in the USE statement that is not yet working. I had forgotten that using INDEX is for IDX individual indexes.

Here's the final code:

Code: Select all

FUNCTION Start() AS VOID STRICT
    LOCAL i AS INT
    Field LastName
    
    SET DEFAULT TO "C:addrdata"
        
    SELECT 0
    USE Names
    SCAN
        ? LastName, FirstName   
    ENDSCAN
    WAIT
    SELECT Names
    USE
	RETURN