IT-Berater: Theo Gottwald (IT-Consultant) > PureBasic Tipps and Tricks

COMate PLUS for PureBasic (COM via OLE Automation)


Theo Gottwald:

--- Quote ---COMate is a small source code utility (written in Purebasic) which allows for the easy creation of automation controllers. It is based upon a translation of the DispHelper source code (written in c) but upgraded to offer a true Visual Basic experience in the way that we invoke COM object methods and get/set properties etc.  (The idea of a COM property is another Visual Basic simplification to aid readability of source code etc. To all intents and purposes a property is simply a method function used to access some private variable or other.)

Download from here:

--- End quote ---
Download COMate Plus (Free)

--- Quote ---Here we list COMate's most important features and offer up a few words of explanation where appropriate.
An oop interface. 
COMate wraps it's entire operation up within two easy to use classes; one for dealing with the basic COM objects and the other for enumerating collections (more on this later). You can see the main COMate class in action in the code above in which we utilised two instances of the COMateObject class.

(For those with a detailed knowledge of automation, the underlying iDispatch object pointers are 'embedded' within these COMate objects.)
Method / property parameters are encoded in a very natural way within the command strings.
Before passing parameters to a COM method/property, COMate will take it's best guess as to the type of each parameter unless the user includes a type modifier in the command string.

For example, use of the 'As Boolean' modifier in the command string "Visible = 1 As Boolean" will ensure that the value of 1 is converted to the underlying boolean type (#Variant_True in this case).

'BYREF' is supported for individual parameters for compatibility with many VB ActiveX components.
Method/property calls can embed a chain of property-gets, each of which return a subobject etc.
This is similar to DispHelper.
Command strings can include escape characters in the form $xxxx where xxxx represents a 4 hexadecimal digit character code.
E.g. $0027 would insert a ' character into the string.
Enumeration of collections.
Many COM objects expose collections of objects (or variants) which COMate can retrieve through instances of it's COMateEnumObject class.
ActiveX support.
Active X controls can be hosted within an application and controlled through the standard COMate classes. There are functions for registering and un-registering OCX libraries.
Support for receiving 'events' sent from COM objects.
Particularly relevant for ActiveX controls.
Facility for setting 'design-time' read-only properties at run-time for those ActiveX controls which check the ambient 'user mode'.
Some controls have 'read only' properties which are not intended to be altered at run-time. COMate allows us to set such properties at run-time.
Automatic freeing of all strings (unlike DispHelper).
Completely threadsafe.
More accurately, COMate is as threadsafe as the underlying components being used!
Full threaded error reporting.
Access to error codes (HRESULT values) and, where possible, error descriptions in simple text format.

In particular, if two threads are utilising the same object instance then each will have separate error reporting facilities

--- End quote ---

Example Code:

--- Code: ---XIncludeFile "COMatePLUS.pbi"

Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")

If ExcelObject
    If ExcelObject\SetProperty("Visible = #True") = #S_OK
        WorkBook = ExcelObject\GetObjectProperty("Workbooks\Add")
            If WorkBook
                ExcelObject\SetProperty("Cells(1,1) = 'Hello'")
                ExcelObject\SetProperty("Cells(1,2) = 'from'")
                ExcelObject\SetProperty("Cells(1,3) = 'COMate!'")
    MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
--- End code ---

Original Post in the PureBasic Forum


[0] Message Index

Go to full version