Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
New .net interop library for VFP
Message
From
21/02/2019 11:48:53
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
21/02/2019 06:55:25
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
01666517
Message ID:
01666618
Views:
535
This message has been marked as a message which has helped to the initial question of the thread.
Likes (3)
>>Hi everybody, there's a new open source .Net interop library for VFP
>>called "kodnet" similar to wwDotnetBridge.
>>
>>The author claims it has advantages over it, but I have not tested
>>kodnet -nor ww.DotNetbridge!- , so it would be interesting if folks who
>>are familiar with .net interop could take a look and share with
>>us their findings.
>>
>>site: https://github.com/voxsoftware/kodnet
>
>Thanks for sharing. All samples are working fine for me.
>
>One thing I tried was a simple form that I created and I was surprised by the errors I got. Probably forms are not supported at all.

Cool. I take my word back, I made it to work. This is a simple .Net form showing in VFP desktop but a sample is always good - disregard more than needed library references :)
Don't forget to run:
do fullpath('kodnet.prg')
Also you might need to change connection string (likely it is only me to name it SQLExpress2012).
TEXT TO m.code noshow
using System;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Drawing;
using System.Xml.Serialization;

public class program{
	public static void main(){
	}
}
namespace Compiled
{
	public class Test
	{

		public System.Windows.Forms.Form GetForm()
	{
		string constr = @"server=.\SQLexpress2012;trusted_connection=yes;database=Northwind";
		DataSet ds = new DataSet();
			var catAdapter = new SqlDataAdapter("select * from Categories",constr);
			catAdapter.Fill(ds, "Categories");
			
			//var c2p = ds.Relations.Add("Cat2Products",
			//ds.Tables["Categories"].Columns["CategoryId"],
			//ds.Tables["Products"].Columns["CategoryId"]);

			Form f = new Form { Text = "ComboBox ornek", Height = 200, Width = 500 };
			ComboBox cb1 = new ComboBox { Left = 10, Top = 10, Width = 450, Font = new Font("Courier New", 8) };
			ComboBox cb2 = new ComboBox { Left = 10, Top = 60, Width = 450, Font = new Font("Courier New", 8) };

			f.Controls.AddRange(new Control[] { cb1, cb2 });

			cb1.DataSource = ds.Tables["Categories"];
			cb1.ValueMember = "CategoryId";
			cb1.DisplayMember = "CategoryName";
			cb1.SelectedIndex = -1;

			cb1.SelectedIndexChanged += (sender, args) =>
			{

				var selectedValue = ((ComboBox)sender).SelectedValue;
				cb2.DataSource = null;
				cb2.Items.Clear();
				DataTable tbl = new DataTable();
				var prodAdapter = new SqlDataAdapter("select * from Products where CategoryId = @id", constr);
				prodAdapter.SelectCommand.Parameters.Add("@id", SqlDbType.Int).Value = selectedValue;
				prodAdapter.Fill(tbl);

				cb2.DataSource = tbl;
				cb2.DisplayMember = "ProductName";
				cb2.ValueMember = "ProductId";
			};

			return f;
		}
	}
}
ENDTEXT 

_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.Linq.dll")
_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.dll")
_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Drawing.dll")
_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Xml.dll")
_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Xml.Serialization.dll")
_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.dll")
_Screen.dotnet4.loadAssemblyFile("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.Entity.dll")


LOCAL engine

* COMPILE C# CODE
Local asem, test, person

engine= _screen.kodnet.getStaticWrapper("jxshell.csharplanguage").construct()
m.engine.Runscript(m.code)
asem = m.engine.getCompiledAssembly()
_Screen.kodnet.loadAssembly(m.asem)


* now you can use the type compiled 
test= _screen.kodnet.getStaticWrapper("Compiled.Test").construct()
frm = test.GetForm()
frm.ShowDialog()
I like it.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform