VFP9 with CDX concerns ?

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

User avatar
DexterZ
Posts: 28
Joined: Sat Dec 03, 2016 1:35 am

VFP9 with CDX concerns ?

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

VFP9 with CDX concerns ?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

VFP9 with CDX concerns ?

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
DexterZ
Posts: 28
Joined: Sat Dec 03, 2016 1:35 am

VFP9 with CDX concerns ?

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

VFP9 with CDX concerns ?

Post by Chris »

Could you please send also the dbf and cdx files so we can reproduce the problem here? Thanks!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4523
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

VFP9 with CDX concerns ?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
DexterZ
Posts: 28
Joined: Sat Dec 03, 2016 1:35 am

VFP9 with CDX concerns ?

Post by DexterZ »

Thanks Chris! The attached zipped file includes TestDb.DBF and TestDb.CDX
Attachments
TestDb_DBF_CDX.zip
(434 Bytes) Downloaded 84 times
User avatar
DexterZ
Posts: 28
Joined: Sat Dec 03, 2016 1:35 am

VFP9 with CDX concerns ?

Post by DexterZ »

Cool! I'll play with it more, many thanks Robert !
User avatar
DexterZ
Posts: 28
Joined: Sat Dec 03, 2016 1:35 am

VFP9 with CDX concerns ?

Post 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();
            }
          
        }
    }
}
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

VFP9 with CDX concerns ?

Post 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
______________________
Johan Nel
Boshof, South Africa
Post Reply