CLR Extender Reference

CLRCreateObject Function

Description »

Creates a new .NET Object from one of the assemblies made available with SetCLRClassLibrary

CLRCreateObject(cClassName [, eParameter1 , eParameter2 , ...])

Parameters

cClassName
The name of the class to create. Use the class fully qualified name in this format: Namespace1::Namespace2::ClassName. The type should be exported as Public to be usable from outside of the assembly.
Note:

You can use the Assembly Browser to see the Full Qualified Names of the types.

Note:

It searches the Assemblies opened with SETCLRClassLibrary.

[, eParameter1 , eParameter2 , ...]
The parameters to pass to the instance's constructor. See the class documentation for info about the parameters.
Note:

Some .NET classes only exposes constructors with parameters. Be sure to include the right number and type of parameters.

Return Value

An object reference. If it can't create the object, fails and an error is raised with additional information shown

Example »

The following example creates a form, adds some controls and shows the form. Resize the form to see how the button is Docked to the bottom of the form.

PUBLIC oForm && so it remains reachable from FoxPro
LOCAL oControl
= SETCLRClassLibrary("system.windows.forms.dll",.T.) && Be sure the assembly is in the ClrClassLibrary path
oForm = CLRCreateObject("SYSTEM::Windows::Forms::Form")  &&Constructor without parameter
* Creates a Checkbox
oControl = CLRCreateObject("SYSTEM::Windows::Forms::CheckBox")
oControl.Text = "I was created from FoxPro"
oControl.AutoSize = .T.
oForm.Controls.Add(m.oControl)

* Creates a button
oControl = CLRCreateObject("SYSTEM::Windows::Forms::Button")
oControl.Text = "Click me"
oControl.AutoSize = .T.
oControl.Dock = 2
oControl.Top = m.oForm.Height - m.oControl.Height && at bottom
oControl.Parent = m.oForm && The parent
oForm.Show()
Remarks »

This function is modeled after the VFP's CREATEOBJECT.

To create a .NET Form:

= SETCLRClassLibrary("system.windows.forms.dll",.T.) && Be sure the assembly is in the ClrClassLibrary path
oForm = CLRCreateObject("SYSTEM::Windows::Forms::Form")  &&Constructor without parameter
oForm.Text = "Hello from VFP"
oForm.Show()

Send comments about this topic to eTecnologia.net.