Is it possible to access .DBC (VFP) databases through xSharp?

This forum is meant for questions and discussions about the X# language and tools
pluisje
Posts: 4
Joined: Mon Jun 10, 2019 2:25 pm

Is it possible to access .DBC (VFP) databases through xSharp?

Post by pluisje »

Matt Slay wrote:
it would be nice to have a code sample that shows the exact lines of code that are required to open a DBF and loop over it to print or display a few of the fields the screen or in a simple dialog. [...] I know you were just giving basic feedback, but the "using the DBFVFP RDD" will be a mystery to VFP folks,
I second that very much!
Speaking for myself: coming from VFP and PHP (Notepad++), Visual Studio is also new to me.
So when the VFP-dialect is running, I will be looking for a small "Hello World".
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Is it possible to access .DBC (VFP) databases through xSharp?

Post by lumberjack »

pluisje wrote:Matt Slay wrote:
it would be nice to have a code sample that shows the exact lines of code that are required to open a DBF and loop over it to print or display a few of the fields the screen or in a simple dialog. [...] I know you were just giving basic feedback, but the "using the DBFVFP RDD" will be a mystery to VFP folks,
I second that very much!
Speaking for myself: coming from VFP and PHP (Notepad++), Visual Studio is also new to me.
So when the VFP-dialect is running, I will be looking for a small "Hello World".
Well depending what type of "Hello World" you looking for:

Console app

Code: Select all

FUNCTION Start() AS VOID
  ? "Hello World"
RETURN
Lets do it as a form:

Code: Select all

FUNCTION Start() AS VOID
  VAR oForm := MyFirstXSharpForm() // Note X# understand both () and {} for object creation
  Application.Run(oForm)
RETURN

CLASS MyFirstXSharpForm INHERIT Form 
  CONSTRUCTOR() // Or INIT() in the VFP language syntax
    SUPER()
    Size := Size(100, 100) // In the VFP syntax assignment can also be done by "="
    Text := "My first XSharp Form"
    BackColor := Color.Blue
    VAR btn := Button()
    btn.Text := "Close"
    btn.Location := Point(5,5)
    btn.Click := MyButtonClick
    Controls.Add(btn)
  RETURN
  METHOD MyButtonClick(o AS OBJECT, e AS EventArgs) AS VOID
    MessageBox.Show("Good bye my first X# form")
    Close()
  RETURN
END CLASS // Also understand ENDDEFINE
Ok, I know this is not 100% complete, but hopefully gives an idea to VFP users not yet trying to do anything in X#.
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Is it possible to access .DBC (VFP) databases through xSharp?

Post by lumberjack »

Hi Matt,
FoxProMatt_MattSlay wrote: Once the release is publicly available, it would be nice to have a code sample (maybe a new blog post) that shows the exact lines of code that are required to open a DBF and loop over it to print or display a few of the fields the screen or in a simple dialog. Just a simple code example that VFP users can see the X# code and even copy-paste it onto a project and see it run.
With the public GA to be released soon, here is a bit of "DBFVFP" background.

First thing, one need to understand the pre-processor. In that context the following from the X# include folder in the file dbCmd.xh:

Code: Select all

#command USE                            => dbCloseArea()

#command USE <(db)>                                                     ;
             [VIA <rdd>]                                                ;
             [ALIAS <a>]                                                ;
             [<new: NEW>]                                               ;
             [<ex: EXCLUSIVE>]                                          ;
             [<sh: SHARED>]                                             ;
             [<ro: READONLY>]                                           ;
             [INDEX <(index1)> [, <(indexn)>]]                          ;
                                                                        ;
      => dbUseArea(                                                     ;
                    <.new.>, <rdd>, <(db)>, <(a)>,                      ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>        ;
                  )                                                     ;
                                                                        ;
      [; dbSetIndex( <(index1)> )]                                      ;
      [; dbSetIndex( <(indexn)> )]
The trick to see how the command is translated into a function call is the optional VIA part. That allows us to tell the system what driver we want to use. There are a couple of surprises that this allows us to do using the Replaceable Database Driver (RDD) concept:

Code: Select all

USE "c:blahblah" VIA "DBFVFP"
USE "c:blahblah.csv" VIA "DELIM" FIELDS {{"Name", "C", 10, 0}, {"LastName", "C", 30, 0}}  DELIMITER ","
There is also a function RddSetDefault("DBFVFP") that we can use at startup to set the default RDD if we want to omit the VIA clause.

Hope this is of interest to some.
______________________
Johan Nel
Boshof, South Africa
Post Reply