COM/OLE description
A brief description of COM/OLE library. This library also contains the support of the VARIANT type, used for data transmitting from/to COM objects. Variables of the oleobj type are used for working with the COM objects; furthermore, each variable of this type has one appropriate COM object. A COM objects method is called with the help of the ~ late binding operation. There are two ways of binding a COM object with a variable , as follows:
1. The oleobj.createobj method is used for creating a new COM object:
oleobj excapp
excapp.createobj( "Excel.Application", "" )
2. Binding a variable with the existing COM object (child) is returned by another COM object method call:
oleobj workbooks
workbooks = excapp~WorkBooks
The oleobj object can maintain the following kinds of late binding:
- elementary method call excapp~Quit, with/without parameters;
- set value excapp~Cells( 3, 2 ) = "Hello World!";
- get value vis = uint( excapp~Visible );
- call chain excapp~WorkBooks~Add, equals the following expressions
oleobj workbooks
workbooks = excapp~WorkBooks
workbooks~Add
The method call can return only the VARIANT type, and the appropriate assignment operators and type cast operators are used to convert data to basic Gentee types. Parameters of the COM objects methods call as well as the assigned values are automatically converted to the appropriate VARIANT types. The following Gentee types can be used - uint, int, ulong, long, float, double, str, VARIANT.
Use the oleobj.release method in order to release the COM object; otherwise, the COM object is released when the variable is deleted; also the object is released when the variable is bound with another COM object. Have a look at the example of using the COM object
include : $"...\olecom.g"
func ole_example
{
oleobj excapp
excapp.createobj( "Excel.Application", "" )
excapp.flgs = $FOLEOBJ_INT
excapp~Visible = 1
excapp~WorkBooks~Add
excapp~Cells( 3, 2 ) = "Hello World!"
}
The oleobj object has properties, as follows:
- uint flgs are flags. Flags value can be set or obtained; the property can contain the $FOLEOBJ_INT flag, i.e. when transmitting data to the COM object the unsigned Gentee type of uint is automatically converted to the signed type of VARIANT( VT_I4 )
- uint errfunc is an error handling function. A function address can be assigned to this property, so using the COM object this function will be called as long as an error occurs; furthermore, this function must have a parameter of the uint type, that contains an error code.
All child objects automatically inherit the flgs property as well as the errfunc property.
Related links | Source |