xsharp.eu • VFP9 with CDX concerns ?
Page 1 of 4

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 6:22 am
by DexterZ
Hello all!

Tried VFP solution and it's great! I just have some inquiries and concerns :

1. Does DBF with CDX working ? because DBF created with VFP9 with CDX getting corrupted
once I issued a replace command on a field. the corrupted DBF cant be open in VFP9 but I
open it on VFP5.

2. Any tuts links how to maniputate DBF files directly in C# using XSharp library.

Many thanks ^_^Y

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 9:38 am
by robert
Dexter,
We could really use some more info w.r.t. #1. Do you have example code ?
For #2: No tutorials yet

Robert

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 9:56 am
by wriedmann
Hi Dexter,
Any tuts links how to maniputate DBF files directly in C# using XSharp library.
I have some small sample applications that use DBF files from X# Core dialect.
What do you need? A WinForms application that can access DBF files?
Only read access or also write? Using a DataTable object is enough?
Wolfgang
P.S. my background is Clipper and VO, not VFP

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 11:16 am
by DexterZ
Inquiry 1 : Here's my test code

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

Code: Select all

FUNCTION Start() AS VOID STRICT
    
    SELECT 0 
    USE "C:TEMPTESTDB.DBF" SHARED
    
    APPEND BLANK
    *   
    Replace DOC_TYPE with "RR"  ,;
            DOC_NO   with "12345"    
    
    WAIT "Press a key to exit ^_^"
    
RETURN	
The Problem :

1, Using the above code accessing TESTDB.DBF "without" CDX it's ok


2. But if I put a CDX tag on DBF, it appended a blank records only
and did not replace the value both fields are still empty.

ex: INDEX ON DOC_TYPE+DOC_NO TAG DOC_NO

Inquiry 2 : XSharp in C#

I tried the following code inside C# and working correctly but that it :) I can't find the Replace command.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using XSharp;
using XSharp.Core;
using XSharp.RT;
using XSharp.VFP;

using XDb = XSharp.CoreDb;

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            XDb.SetSelect(1);
            XDb.UseArea(true, "DBFVFP", @"C:TEMPTESTDB.DBF", "TESTDB", true, false);            
            XDb.Append(true);
            
        }
    }
}

Thank you WriedMan+Robert ^_^y

Dex

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 11:18 am
by Chris
Could you please send also the dbf and cdx files so we can reproduce the problem here? Thanks!

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 11:21 am
by robert
Dexter,

Dex,

1) What happens if you close the file properly at the end of your code ?

2) To write values with the CoreDb layer you need to call FieldPut() with the column number and value.. Also don't forget to commit the changes and close the dbf.:

Code: Select all

XDb.Commit()
XDb.CloseArea()

Robert

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 11:24 am
by DexterZ
Thanks Chris! The attached zipped file includes TestDb.DBF and TestDb.CDX

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 11:26 am
by DexterZ
Cool! I'll play with it more, many thanks Robert !

VFP9 with CDX concerns ?

Posted: Mon Jan 20, 2020 12:55 pm
by DexterZ
YAY! Many thank's Robert the code below works like a charm even in share mode side by side with VFP9 and records with CDX also reflects in VFP9! ^_^y

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using XSharp;
using XSharp.Core;
using XSharp.RT;
using XSharp.VFP;

using XDb = XSharp.CoreDb;

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            //--> Table work area
            //
            XDb.SetSelect(1);
           
            //-> Open table in shared mode
            //
            if (! XDb.UseArea(true, "DBFVFP", @"C:TEMPTESTDB.DBF", "TESTDB", true, false) )
            {
                MessageBox.Show("Unable to open table TESTDB.DBF");
            }
            else
            {
                //--> Add blank record
                //
                XDb.Append(true);

                //-->  Update fields value
                //
                XDb.FieldPut(1, "DM");       // DOC_TYPE
                XDb.FieldPut(2, "DM-12345"); // DOC_NO

                //--> Write to disk 
                //
                XDb.CommitAll();

                //--> Close table
                //
                XDb.CloseArea();
            }
          
        }
    }
}

VFP9 with CDX concerns ?

Posted: Tue Jan 21, 2020 6:47 am
by lumberjack
Hi Dexter,
DexterZ wrote:YAY! Many thank's Robert the code below works like a charm even in share mode side by side with VFP9 and records with CDX also reflects in VFP9! ^_^y
And the $1m effort to convert that to X#... :cheer:

Code: Select all

using System
using System.Collections.Generic
using System.Linq
using System.Threading.Tasks
using System.Windows.Forms

using XSharp.VFP
using XDb = XSharp.CoreDb

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread];
FUNCTION Start() AS VOID
    //--> Table work area
    XDb.SetSelect(1)
    //-> Open table in shared mode
    if ! XDb.UseArea(true, "DBFVFP", @"C:TEMPTESTDB.DBF", "TESTDB", true, false)
        MessageBox.Show("Unable to open table TESTDB.DBF")
    else
         //--> Add blank record
         XDb.Append(true)
         //-->  Update fields value
         XDb.FieldPut(1, "DM");       // DOC_TYPE
         XDb.FieldPut(2, "DM-12345"); // DOC_NO
         //--> Write to disk 
         XDb.CommitAll()
         //--> Close table
         XDb.CloseArea()
     endif
RETURN