The Comimport Statement

Syntax

$ ComImportDeclaration = COMIMPORT FROM string

{( ClassImportDeclaration | InterfaceImportDeclaration ) “;” }

END COMIPORT ";"

 

$ ClassImportDeclaration = CLASS ident : BaseImportClass

$ End Class ident ";"

$ BaseImportClass = qualident

 

$ InterfaceImportDeclaration = INTERFACE ident [“:” BaseImportInterface]

$ BaseImportInterface = qualident

Description

The ComImport block is used to import descriptions of classes and interfaces from the library (dll) and type library (tlb). The key word FROM is followed by a string with GUID or the file path and the file name, from which descriptions are imported. Interfaces can be imported with the keyword INTERFACE or as classes with the keyword CLASS. All methods and properties with no Restricted or Hidden attributes are imported for each interface.

Use the New operator to create objects for imported classes. An instance of a COM object is created. Calling object methods and methods of interfaces implemented by COM objects results in calling corresponding methods of these COM objects.

Example

Executing the example requires the MyDll.dll file of the type library located in the root directory of the C drive. The library implements a COM object with the name "Test" recorded in the Windows registry. The interface of the ITest COM object has the implemented TestFunction function accepting two integer parameters for input and returning a real value.

Comimport From "C:\MyDll.tlb"

Interface ITest;

Class Test: Object, ITest

End Class Test;

End Comimport;

 

Sub Main;

Var

a: Test;

i: Double;

Begin

a := New Test.Create;

Try

i := a.TestFunction(4, 4);

Debug.WriteLine(i.ToString);

Except

Debug.WriteLine("Error executing the TestFunction function");

End Try;

End Sub Main;

After executing the example the TestFunction function is executed. If the function returns a valid value, this value is displayed in the development environment console, otherwise an error message is returned.

If the GUID library is known, the Comimport block can be recorded as follows:

Comimport From "{BC528177-3B14-4D47-9C2D-E69B6045CC62}"

Interface ITest;

Class Test: Object, ITest

End Class Test;

End Comimport;

See also:

Operators