Managed extensions for VCL - general tutorial

Welcome to ManagedVCL - the best components suite to work with .Net framework from Delphi and C++ Builder. ManagedVCL provides a way to:

Managed VCL can not:

.Net objects

Instance of .Net object is created with one of these functions (declared in ClrUtils unit):

When creating .Net objects with Managed VCL full type names (including namespace) must be provided, for example, TypeName should be "System.Xml.XmlDocument" but not "XmlDocument". Managed VCL will load .Net framework and needed assembly if needed.

When you create .Net object you get variable of type OleVariant. If .Net object is defined with COM support (ClassInterface attribute is AutoDispatch or AutoDual) you may use it as COM object, i.e.:

procedure Test()
var
	obj: OleVariant;
begin
	obj := ClrCreateInstance('MyAssembly', 'MyType');
	obj.Method(5);
end;

In case of exception this method will raise EOleExcetion, not EClrException. To raise EClrException, use interfaces in .Net classes or TClrObject.ObjectProperty.

Managed VCL includes also special object that lets you call properties/methods/fields more effective - TClrObject. This object lets also work with .Net objects that are not COM visible and with static properties/methods/fields.

.Net types

Managed VCL provides an way to work with .Net types without creating instances of .Net objects. With types you can:

.Net type can be created with one of these functions (declared in ClrUtils unit):

When calling one of these functions you get pointer to _Type interface that is defined in mscorlib_tlb unit.

Managed VCL contains special object to work with .Net types - TClrType. This object lets you call static properties/methods/fields and get information about .Net type such as enumerate interfaces, constructors, properties, methods, fields, events.

.Net assemblies

Managed VCL can load .Net assemblies using assembly name (for example, "System.Xml, Version = 1.0.5000.0, PublicKeyToken = b77a5c561934e089, Culture = neutral"), assembly file name (for example, "C:\Windows\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"), with assembly partial name (for example, "System.Xml") and even from streams and resources.

Managed VCL includes special component - TClrAssembly that implements all this functionality. This component loads an assembly and can be used to get types and create objects declared in loaded assembly.

Example

To learn more about Managed VCL and try it at work, please start with "Hello dotNet" example. "Embedded assembly" example shows how to compile .Net assembly into Delphi executable (as resource) and load it at runtime.