COM Access from Origin C
To allow communication with other software applications and with
hardware, OriginPro's implementation of Origin C supports Microsoft's
Component Object Model, or COM, programming. With COM support, Origin
C can be used for a multitude of operations. These include:
- Acquiring data
- Accessing a database, or
- "Driving" other applications (e.g. Microsoft Word
or Seagate Crystal Reports) by exposing their internal objects
through COM.
Examples of COM Access from Origin C
Many examples are provided with the product that demonstrate how
these uses are implemented.
How COM Access from Origin C is Implemented
Origin C uses the Object data type to represent all COM
(automation) objects. Any Object can be initalized in two ways:
| |
By getting objects from existing objects (usually as properties
or return values of methods). For example:
// Declare Excel objects
Object oExcel, oExcelWkbks;
// Create an Excel application object
oExcel = CreateObject("excel.application");
// Get the workbooks collection of the Excel object
oExcelWkbks = oExcel.Workbooks;
This sample code first creates an "excel.application"
object using the "CreateObject" function, and then
gets an object representing the collection of all workbooks
using the "Workbooks" property of the "excel.application"
object.
|
|
| |
By creating a new object using the "CreateObject"
function, as is standard in VBA. For example:
Object ocrs;
ocrs = CreateObject("ADODB.Recordset");
creates a new COM object of the type "ADODB.Recordset".
|
|
|