fbpx
× Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET

DBF Index Files and Dialect Core

More
4 months 2 weeks ago #1 by Gianluca Pinoli
DBF Index Files and Dialect Core was created by Gianluca Pinoli
Hi All,
I'm testing Vulcan DBF RDD trying using it in a WinForm Application.
I've created a simple test class in a DLL x86 only Dialect Vulcan (VulcanTest.dll):

If i use it from a Dialect Vulcan (both console and winform) application (x86) work fine, but in a Dialect Core application (x86) it's seem impossible open the index file (DBF file opens and is readable)

Reference:
VulcanRT
VulcanRTFuncs
VulcanVORDDClasses
VulcanVOSystemClasses

Anyone have a suggestion?


Regards
Gianluca


**********************************************************************************************************************
PRIVATE METHOD button1_Click(sender AS OBJECT, e AS System.EventArgs) AS VOID STRICT
local oClass AS ClassDBF
local sRet as string
oClass := ClassDBF{}

sRet :=oClass:GetDescrizione("0001009")
Messagebox.Show( sRet )
return
**********************************************************************************************************************


*********************************************************************************************
// ClassDBF.prg
// Created by : Gianluca
// Creation Date : 8/31/2018 3:19:01 PM
// Created for :
// WorkStation : NB-GIANLUCA


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

BEGIN NAMESPACE VulcanTest

/// <summary>
/// The ClassDBF class.
/// </summary>
CLASS ClassDBF

CONSTRUCTOR()
RETURN

method GetDescrizione(sCodice as string) as STRING
local sRet := "" as string
LOCAL oDB as DBServer
local oFSIndex as FileSpec
oDB := DBServer{"C:\GDOSHOP\ARCHIVI9\ARTICOK.DBF",FALSE,TRUE,"DBFCDX"}
oFSIndex := FileSpec{ "ARTICOK.CDX" }
oFSIndex:Path := "C:\GDOSHOP\ARCHIVI9\"
if !oFSIndex:Find()
oDB:Close()
Return "File Indice non trovato"
endif
if !oDB:SetIndex(oFSIndex)
oDB:Close()
Return "Indice non Applicato"
endif
oDB:GoTop()
if !oDB:Seek("0001009")
oDB:Close()
Return "Articolo non trovato"
endif
sRet := (STRING)oDB:FIELDGET("CODICE") + " "+ (STRING)oDB:FIELDGET("DESCRIZIO")
oDB:Close()
return sRet

END CLASS
END NAMESPACE // VulcanTest

*********************************************************************************************

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #2 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic DBF Index Files and Dialect Core
Hi Gianluca,

this cannot work since you need the macro compiler for the index maintenance.

And the Core dialect does not know what to to with the Date datatype.

If you like to use DBF files in a Core dialect application, you have to put all the DBF management in a VO or Vulcan dialect intermediate library.

This may be true also when the RDDs are released, because also they will rely on the macrocompiler and the specific VO datatypes.

Wolfgang

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #3 by Gianluca Pinoli
Replied by Gianluca Pinoli on topic DBF Index Files and Dialect Core
Thanks Wolfgang.

What do you mean suggesting an intermediate library? A Library with a static method exposed?

Regards
Gianluca

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #4 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic DBF Index Files and Dialect Core
Hi Gianluca,

no. A library that contains a sort of proxy classes.

If you need a sample how this could work, let me know.

Personally I would not use a Core dialect class when I need to access DBF files. Now that the X# runtime is available I will use it because it has a very positive effect on my productivity <g>.

Wolfgang

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #5 by Gianluca Pinoli
Replied by Gianluca Pinoli on topic DBF Index Files and Dialect Core
Hi Wolfgang,
In this phase i'm more testing that developing a real application.
When X# RDD will be ready I'll indeed use it, but in the while if you can send me a smple of your proxy class I'd appreciate it.

Regards
Gianluca

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #6 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic DBF Index Files and Dialect Core
Hi Gianluca,

my proxy class was so specific that I have to rewrite it as sample. I will do this over the weekend.

Wolfgang

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #7 by Gianluca Pinoli
Replied by Gianluca Pinoli on topic DBF Index Files and Dialect Core
Thanks Wolfgang

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago - 4 months 2 weeks ago #8 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic DBF Index Files and Dialect Core
Hi Gianluca,

you will find the entire code attached also as XIDE export files.

This is the library code, compiled with X#, VO dialect, x86 mode:
using Vulcan.VO

class DBFReader
	protect _cFilePath as string
	protect _cIndex as string
	protect _cRDD as string
	protect _oDBServer as DBServer
	
constructor( cFilePath as string, cIndex as string, cRDD as string )
	
	_cFilePath := cFilePath
	_cIndex := cIndex
	_cRDD := cRDD
	_oDBServer := DBServer{ _cFilePath, true, false, _cRDD }
	_oDBServer:SetIndex( _cIndex )
	
	return          
	
property Eof as logic
	get
		local lReturn as logic
		
		if _oDBServer == null
			lReturn := true
		else
			lReturn := _oDBServer:EOF
		endif
	
		return lReturn
	end get
end property
	
method Skip() as logic
	local lReturn as logic
	
	lReturn := _oDBServer:Skip()
	
	return lReturn
	
method GetValue( cFieldName as string ) as object 
	local oReturn as object
	
	oReturn := _oDBServer:FieldGet( cFieldName )
	
	return oReturn
		
destructor()
	
	if _oDBServer != null
		if _oDBServer:Used
			_oDBServer:Close()
		endif
	endif
	
	return	
	
end class

and this is the application, compiled with X# Core dialect, x86 mode:
using System

function Start( ) as void     
	local oReader as DBFReader
	local cDBFFile as string
	local cDBFIndex as string
	local cFirstName as string
	local cLastName as string
	local cCustId as string

	cDBFFile := "C:\cavo28\Samples\Ssatutor\Customer.dbf"
	cDBFIndex := "Cust1.ntx"
	Console.WriteLine( i"Trying to open {cDBFFile}..." )
	oReader := DBFReader{ cDBFFile, cDBFIndex, "DBFNTX" }  
	while ! oReader:Eof
		cCustId := oReader:GetValue( "Cust_ID" ):ToString()
		cFirstName := oReader:GetValue( "First_Name" ):ToString()
		cLastName := oReader:GetValue( "Last_Name" ):ToString()
		Console.WriteLine( i"Customer {cCustId} is {cFirstName} {cLastName}" )
		oReader:Skip()
	end
	
return

This code is missing any error handling and was written only for demonstration purposes. So please don't take it as sample how to write correct code.

File Attachment:

File Name: CoreDBF.zip
File Size:3 KB


Wolfgang
Attachments:
Last edit: 4 months 2 weeks ago by Wolfgang Riedmann. Reason: Correction of code
The following user(s) said Thank You: Gianluca Pinoli

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #9 by Gianluca Pinoli
Replied by Gianluca Pinoli on topic DBF Index Files and Dialect Core
Hi Wolfgang,
Thank you for the samples.
I tested your code, but I have the same problem, CoreDBF works, but if you try to apply "Cust2.ntx" instead of "Cust1.ntx" you'll get the same result.
Setting Vulcan dialect and adding reference to VulcanRT.dll and VulcanRTfunc.dll it start working as required.
Have you got the same problem?
If not, any idea of were is my mistake?

Regrds
Gianluca

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago - 4 months 2 weeks ago #10 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic DBF Index Files and Dialect Core
Hi Gianluca,

you are right - I have forgottten something very important. The Vulcan runtime needs to be initialized.

Please add this class to the library:
class VulcanLoader

static method InitVulcan() as void
	local t as Type
	local mi as System.Reflection.MethodInfo

	t := typeof(VulcanLoader)
	mi := t:GetMethod( "InitVulcan" )
	Vulcan.Runtime.State.AppModule := mi:Module
	
	return

end class

and add the following line before opening the first DBF file:
VulcanLoader.InitVulcan()

This is again an export of both files.

File Attachment:

File Name: CoreDBF.zip
File Size:3 KB

When using the Vulcan or VO dialect, X# does this under the hood.

Wolfgang
Attachments:
Last edit: 4 months 2 weeks ago by Wolfgang Riedmann. Reason: Addition

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #11 by Gianluca Pinoli
Replied by Gianluca Pinoli on topic DBF Index Files and Dialect Core
Thanks Wolfgang,
now it works

Regards
Gianluca

Please Log in or Create an account to join the conversation.