Example: RSIDemoComponent
This example uses a COM component included in the IDL distribution. The RSIDemoComponent is included purely for demonstration purposes, and does not perform any useful work beyond illustrating how IDLcomIDispatch objects are created and used.
The RSIDemoComponent is contained in a file named RSIDemoComponent.dll located in the examples\doc\bridges\COM subdirectory of the IDL distribution. Before attempting to execute this example, make sure the component is registered on your system as described in Registering COM Components on a Windows Machine.
There are three objects defined by the RSIDemoComponent. The example begins by using RSIDemoObj1, which has the program ID:
and the class ID:
Example Code
This complete example, IDispatchDemo.pro, is located in the examples\doc\bridges\COM subdirectory of the IDL distribution. It develops an IDL procedure called IDispatchDemo that illustrates use of the RSIDemoComponent. Run the example procedure by entering IDispatchDemo at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT IDispatchDemo.pro.
- Begin by creating an IDLcomIDispatch object from the COM object. You can use either the class ID or the program ID. Remember that if you use the class ID, you must remove the braces ( { } ) and replace the hyphens with underscores.
- The COM object implements the
GetCLSIDmethod, which returns the class ID for the component. You can retrieve this value in and IDL variable and print it. The string should be'{A77BC2B2-88EC-4D2A-B2B3-F556ACB52E52}'. - The COM object has a property named
MessageStr. To retrieve the value of theMessageStrproperty, enter: - You can also set the
MessageStrproperty of the object and display it using the object'sDisplayMessageStrmethod, which displays the value of theMessageStrproperty in a Windows dialog: - The
Msg2InParamsmethod takes two input parameters and concatenates them into a single string. Executing the following commands should cause IDL to print'The value is: 25'. - To view all known information about the IDLcomIDispatch object, including its dynamic subclass name and the names of its methods, use the IDL HELP command with the OBJECTS keyword:
- The
GetIndexObject()method returns an object reference to one of the following three possible objects: - All three objects have the
GetCLSIDmethod. You can use this method to verify that the desired object was returned. The output of the following commands should be '{13AB135D-A361-4A14-B165-785B03AB5023}'. - Remember to destroy a retrieved object when you are finished with it:
- Next, use the COM object's
GetArrayOfObjects()method to return a vector of object references toRSIDemoObj1,RSIDemoObj2, andRSIDemoObj3, respectively. The number of elements in the vector is returned in the first parameter; the result should3. - Since each object implements the
GetCLSIDmethod, you could loop through all the object references and get its class ID: - Remember to destroy object references when you are finished with them:
obj1 = OBJ_NEW( $ 'IDLCOMIDispatch$PROGID$RSIDemoComponent_RSIDemoObj1')or (with Class ID):
obj1 = OBJ_NEW( $ 'IDLCOMIDispatch$CLSID$A77BC2B2_88EC_4D2A_B2B3_F556ACB52E52')
strCLSID = obj1->GetCLSID() PRINT, strCLSIDNote
The GetCLSID method returns the class identifier of the object using the standard COM separators ( - ).
FOR i = 0, cItems-1 do begin objCLSID = objs[i] -> GetCLSID() PRINT, 'Object[',i,'] CLSID: ', objCLSID ENDFOR