pvComObject is a variant property which returns a reference to the external COM object in the form of an IDispatch pointer.
Setting this property to the correct IDispatch* value connects a DataFlex wrapper object to its corresponding external COM object and increments the COM object's reference count.
Below is an example of creating a cComStdFont object and attaching it to an existing OLE font object using the pvComObject property. The code sample assumes the existence of the Calendar ActiveX control (oCalendar1) from the COM sample application.
// create an instance of OLE Font wrapper class...
Object oFont is a cComStdFont
Procedure SetFontUnderline Variant vFont Boolean bMode
// bind our wrapper Object to the passed IDispatch*
Set pvComObject of oFont to vFont
// now we can change the title font...
Set ComUnderline of oFont To bMode
End_Procedure
End_Object
// checkbox to underline the calendar's title
Object oUnderlineTitle_chkbx is a Checkbox
Set Location to 10 10
Procedure OnChange
Variant vFont
Boolean bIsComObjectCreated
// test If the calendar COM Object is active.
Get IsComObjectCreated of oCalendar1 to bIsComObjectCreated
If (bIsComObjectCreated) Begin
// Get an IDispatch* to the calendar's Title font
Get ComTitleFont of oCalendar1 to vFont
// change the font by attaching it to our generic COM
// font Object..
Send SetFontUnderline vFont (Checked_State(Self))
End
End_Procedure
End_Object
// checkbox to underline the calendar's day text
Object oUnderlineDays_chkbx is a Checkbox
Set Location to 10 20
Procedure OnChange
Variant vFont
Boolean bIsComObjectCreated
Get IsComObjectCreated of oCalendar1 to bIsComObjectCreated
If (bIsComObjectCreated) Begin
// Get an IDispatch* to the calendar's Day font
Get ComDayFont of oCalendar1 to vFont
// change the font by attaching it to our generic COM
// font Object..
Send SetFontUnderline vFont (Checked_State(Self))
End
End_Procedure
End_Object
Notice that in the above example, the object oFont is dynamically connected to font Automation objects by setting the pvComObject property. This is done by passing the font's IDispatch* value to the SetFontUnderline method where it is used to set pvComObject.
Changing the pvComObject property or setting it to NULL (using the NullComObject function) automatically releases any reference to the IDispatch pointed to by the old property value. Destroying the DataFlex wrapper object also automatically releases the reference to the COM object.
This property is automatically assigned and released when sending CreateComObject and ReleaseComObject.
The DataFlex runtime protects against potential corruption of any IDispatch* variant value. This protection is required for DataFlex's COM object reference counting.
Once any Variant property or variable is assigned and IDispatch* value, it cannot be used to store a value of any other type. Doing so would raise an "Illegal type conversion" error.
Performing pointer arithmetic or comparison expressions for variant variables containing an IDispatch* also raises a runtime error.
The helper functions IsNullComObject and IsSameComObject can be used to perform any operations that you would normally require on variants containing IDispatch* values.
Programming with COM – General Topics