Expose X# run-time functions to C#
Posted: Thu Oct 10, 2019 4:36 pm
Hi Juraj, hi Jamal,
will prepare it tomorrow morning.
Wolfgang
will prepare it tomorrow morning.
Wolfgang
Code: Select all
USING System
USING System.Collections.Generic
USING System.Text
FUNCTION TestFunction() AS STRING
RETURN "Test"
Code: Select all
USING System
USING System.Collections.Generic
USING System.Text
using System.Runtime.CompilerServices
using XSharp
using XSharp.Internal
using XSharp.RT
function KeyExp() as string
return iif(_FIELD->FIRST > "R", "Y", "N")
Code: Select all
USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
using System.Runtime.CompilerServices
using XSharp
using XSharp.Internal
using XSharp.RT
using MyXSharpClassLibrary
FUNCTION Start() AS VOID STRICT
LOCAL cDbf AS STRING
cDbf := "c:testmynewtest"
RddInfo(_SET_AUTOOPEN, true)
RddSetDefault("DBFCDX")
DbCreate(cDbf , {{"LAST" , "C" , 10,0}, {"FIRST", "C", 10, 0}})
DbUseArea(true, "DBFCDX", cDbf, "mynewtest", false, false)
? DbCreateOrder("FIRST", cDbf,"Upper(FIRST)+KeyExp()")
? DbCreateOrder("LAST", cDbf,"Upper(LAST)")
LOCAL aValues, aValues2 AS ARRAY
aValues := {"JACK", "MARK", "HARRY", "Mary", "ROB", "SALLY"}
aValues2 := {"MAC", "JIM", "paul", "SUE", "THERE", "ELF"}
FOR LOCAL n := 1 AS DWORD UPTO ALen(aValues)
DbAppend()
FieldPut(1,aValues[n])
FieldPut(2,aValues2[n])
NEXT
DbGoTop()
WHILE !EOF()
? FieldGet(1), FieldGet(2)
DbSkip(1)
END
?
? "Set order: "
? DbSetOrder("FIRST")
DbGoTop()
WHILE !EOF()
? FieldGet(1), FieldGet(2)
DbSkip(1)
END
? "Records:", LastRec()
? DbSetOrder("LAST")
DbGoTop()
WHILE !EOF()
? FieldGet(1), FieldGet(2)
DbSkip(1)
END
DbCloseArea()
WAIT
RETURN
Code: Select all
using System;
using System.Windows.Forms;
using XSharp;
using XSharp.RT;
using XSharp.VO;
using XSharp.RDD;
using XSharp.Internal;
using XSharp.Core;
[assembly: XSharp.Internal.ClassLibrary("Functions", "MyXSharpClassLibrary")] // is this correct ??
namespace DBFCDX_CS_Sample
{
public partial class Form1 : Form
{
public const int RDD_INFO = 100;
public const int _SET_AUTOOPEN = RDD_INFO + 4;
public const int _SET_AUTOORDER = RDD_INFO + 5;
public Form1()
{
InitializeComponent();
}
private void ReservationsDBFbutton_Click(object sender, EventArgs e)
{
XSharp.CoreDb.RddInfo(_SET_AUTOOPEN, true);
if (XSharp.RT.Functions.DbUseArea(true, "DBFCDX", @"C:testmynewtest.dbf", "newtestdbf", true, false))
{
XSharp.RT.Functions.DbSetOrder("LAST");
// MessageBox.Show(XSharp.RT.Functions.FCount().ToString());
MessageBox.Show(XSharp.RT.Functions.LastRec().ToString());
XSharp.RT.Functions.VoDbCloseArea();
}
}
}
}
Chris wrote:Hi Jamal,
Maybe indeed you accidentally defined this attribute twice?
Also you need to specify the class name (complete, including the namespace) in the first parameter, not the assembly name of the library, but that has to do with the runtime behavior only of course.
Code: Select all
System.Reflection.Assembly.Load("MyXSharpClassLibrary");
You're welcome! First time I had this I also lost many hours! This time it took much lessJamal wrote:Hi Chris,
In the mean time I found another way to load the assembly without creating a dummy function. I only had to call:
Oh man! I could have saved hours by knowing this.Code: Select all
System.Reflection.Assembly.Load("MyXSharpClassLibrary");
Thanks!
Jamal