Monday, December 12, 2011

.NET objects now First-class citizens in Guineu (build 426)

The most wanted features in Guineu were frequently ones that don't even exist in Visual FoxPro, such as making HTTP request, transferring files via FTP, placing phone calls, having a signature control, and so forth. Many of these made it into Guineu in form of a SYS(8xxx) function or a new base class that can be enabled.

Some of these features are still lacking such as accessing a bluetooth or serial printer, retrieving GPS information, obtaining phone book entries and text messages, and much more. Quite often there's sample code for C# or VB.NET for the Microsoft Compact Framework. Yet, often it's only few who request a particular feature. That makes it particular difficult to implement a solution that covers not only those developers particular needs, but also the needs of others in future scenarios.

This release is a major step forward!

We now support .NET objects in the same manner as native objects. The philosophy behind Guineu has always been to keep the look and feel of Visual FoxPro. Therefore you use .NET objects exactly like you would use native objects in Guineu or ActiveX controls in Visual FoxPro. There are no new commands or functions as the next sample demonstrates:

Local loForm, loButton
If Os(6) == "3"  && Windows CE
Set Classlib To \Windows\GAC_System.Windows.Forms_v2_0_0_0_cneutral_1.dll
Else             && Windows 9x, Windows NT
Set Classlib To C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll
loForm = CreateObject("System.Windows.Forms.Form")
loForm.Text = "Hello"
loButton = CreateObject("System.Windows.Forms.Button")
loButton.Text = "World"
loForm.Controls.Add (m.loButton)

The SET CLASSLIB command now works for VCX, PRG and DLL files. CREATEOBJECT() searches .NET classes at the same time as searching for Guineu classes. You can access properties and call methods on .NET objects as you can do in Guineu objects. 

To load a DLL you need to pass the path to the DLL unless it is in the Windows search path. Please note that SET PATH TO is ignored, because Windows is in charge of loading the DLL. As with FLL libraries in Visual FoxPro you cannot embed these DLLs into the application.

On Windows Mobile it's a bit difficult to determine the actual location of the DLL file. By default, File Explorer hides any DLL and loading the Windows directory on a device can take some time. To find the file you can use the ADIR() function using a little Guineu program to list all installed GAC*.DLL files.


This is version one. There are naturally a number of things that don't yet work, some easy to fix, some more difficult.

NEWOBJECT() cannot load .NET objects yet. Adding a .NET control to an existing control also doesn't work. Guineu will always use the parameterless default constructor. Binding to events is not yet possible.

Guineu performs an automatic type cast based on the values you pass in. If there are multiple competing overloads of a method, you might not get the correct one. Similar, return values might be casted to objects when you expect them to be simple data types. This is especially an issue with Enumerations. CAST() does not support any of the native types. In fact, CAST() isn't even in the product yet.

Only public instance members are available. Static methods and private properties are not accessible. GETINTERFACE() doesn't work yet, nor does FOR EACH pick up the IEnumerable interface.

New features

The OS() function implements values 1-6 now. OS(6) returns the platform. This is 1 for Windows 9x, 2 for any Windows NT based system (NT, 2000, XP and later), and 3 for Windows mobile.


Repeatedly executing CREATE CURSOR would open a further cursor with the same alias.

ADIR() returned the wrong number of entries and wouldn't indicate directories.

SYS(2015) would not return a new value every call.


Unknown said...

Hey, I would really like to encourage you to continue the good work you are doing.
If you can pull this off as a viable language under .Net you have my business.

P Hemans

Macrosoft said...

Great information about .net objects.

Visual FoxPro to .Net