CLR Extender Reference

Samples overview

Description »

Several samples are shipped with .NET Extender to give you a JumpStart on using .NET technologies from VFP. The samples of course are written on VFP and are stored in the folder HOME()+"\Tools\eTecnologiaNETExtender\Samples".

Ado.net

Ado.net is the Data access method in the .NET Framework, it IS NOT so powerful like the Data Access of VFP, but using it gives you access to DataSources that are not available on VFP, thus you can extend your reach.

The best way to work with ado.net data is through the XMLAdapter, you load the ado.net DataTable using standard .NET Functionality and then convert the DataTable to XML and load it to VFP through XMLTable.ToCursor().

You then set the cursor to buffering = 5 &&Table buffering, make the changes you want and then update the Data using XMLAdapter to create the XML with just the changes (see function UpdateData in the samples) .

The above method lets you use the powerful DataAcccess functionality of VFP which is far superior to the one available in Ado.net.

ASP.NET

The sample located in the Samples\ASP.NET\WebServices folder, is a .NET WebService which performs some simple math operations. You can see the operations available at: http://www.etecnologia.net/samples/webservices/mathservice.asmx.

This sample uses pure .NET Framework technology to call the WebService. If you plan to use WebServices in your app this is the recommended way because the SOAP Toolkit shipped with VFP has been phased out by Microsoft.

With the WebServices Importer you can create a .NET Assembly with a WebService proxy, which is basically a Class that you use as if it were the true object, your calls are sent to the above url and the response converted to the type you expect. All this is transparent to you, you just have to instantiate the class using CLRNewObject.

In the sample directory are 4 files:

MathService.asmx This is the ASP.NET WebService, MathService.asmx. This is not used in the sample but is included as a guide on what operations it does. This webservice is executed in www.eTecnologia.net
Generated.vb This is the code generated by WebServices importer.
Generated.dll This Assembly was automatically created by WebServices importer.
test_mathservice.prg This is the very sample. It shows how easy is to call web services.

Compression

This sample shows you how to use the SharpZipLib library, which is available at http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx.

Some interesting techniques used are:

  • Byte arrays, VFP does not have a Byte Array type, but you can make any string a byte array using the VFP's CREATEBINARY function.
  • Using streams. Streams are the .NET Object Oriented files (and beyond files) equivalent to FOPEN, FWRITE, FREAD VFP Functions. With .NET streams you are not limited to FileStream you have MemoryStreams, CryptoStreams (cryptography), NetworkStream (for network operations using sockets).

The sample stores the files in HOME()+"Tools\eTecnologiaNETExtender\Samples\Compression\SampleFiles\InputFiles" to a zip file: test.zip.

Then it opens the resulting zip and extracts the 6th file to the directory. A class is used to show common patterns for dealing with zip files.

IO

Teach how to perform Input/Output (IO) in the .NET Framework. There are several samples showing how to use the .NET Streams, writing to a TextFile and reading from a file.

Of particular interest is the sample test_encryptedstream.prg which encrypts on the fly and then decrypts. It shows how to read from a stream, using bytes arrays, and converting bytes array to string using System.Text.AsciiEncoding.

MenuStrip

This sample is explained in more detail here. It lets you place Menus and Toolbars in any VFP Form with the Office 2003 Look and Feel.

Here is a screen shot:

Printing

This sample is an extract from the next generation Object Oriented Report system in development for the .NET Compiler for VFP. In the next OOP Report you will design your reports using the Form Designer and then the output will be produced using the .NET Framework .

The sample is explained in more detail here. A screenshot with the Form Designer at the Left and the Report Preview (using System::Drawing::Printing::PrintPreviewController) on the Right side:

This sample shows how to perform several tasks related with System::Drawing, this is GDI+ functionality. It shows how to Use Brushes, Draw Text, Draw Images, Coordinates translation and more.

Windows::Forms Controls in VFP Forms

The sample SourceGridSample shows you how to put a powerful SpreadSheet like Grid, in VFP. It is based in the component SourceGrid.

XML

The form transform-xml.scx lets you select two files; the xml file which contains the data and the XSLT sheet, with the transformation info.

It creates a XSLCompiledTransform and loads the info. The bulk of the process is in the Click Event of the Transform Button.

LOCAL oXSLT, oXSLArguments, oStringWriter

* Creates the Transform Object
oXSLT = CLRCreateObject("system::xml::xsl::XSLCompiledTransform")
* Loads the XSLT sheet
oXSLT.Load(THIS.Parent.cntXSLT.edtfilelocator.Value)
* Creates an empty argument list 
oXSLArguments = CLRCreateObject("system.xml.xsl.XSLTArgumentList")

* Outputs the transformation to a String
* You can output to anything derived from TextWriter

oStringWriter = CLRCreateObject("system::io::StringWriter")

* Calls the transform
oXSLT.Transform(THIS.Parent.cntXMLSource.edtfilelocator.Value,oXSLArguments,oStringWriter)

* Gets the transformation results which is stored in oStringWriter
THIS.Parent.edtResults.Value = oStringWriter.ToString()
THIS.Parent.edtResults.Refresh()
Example »

Remarks »


Send comments about this topic to eTecnologia.net.