Home : Using Dispatch Objects
Q37328 - HOWTO: Using Dispatch Objects

Using Dispatch Objects

 

When using Java to access COM objects, there are rare occasions when no suitable Java class is available via the Java proxies to wrap the COM object in. In this case, you can use a Dispatch object to manually invoke methods on the COM object.

For example, Excel has a CheckBox control, used for placing checkboxes on a spreadsheet. This object has no direct mapping in the Java proxies (the CheckBox object that is generated has a different use). Instead, we can use a Dispatch object to dynamically invoke its methods.

// "sheet" is the active sheet
OLEObject checkBoxObject = new OLEObject(sheet.oLEObjects("CheckBox_1"));
Dispatch checkBoxDispatch = new Dispatch(checkBoxObject.getObject());

// checkBoxDispatch is now a Dispatch object representing the checkbox named "CheckBox_1"
// use the "getPropertyByName(String Property)" function to get the boolean value of the checkbox
Boolean value = (Boolean)checkBoxDispatch.getPropertyByName("Value");

// use the "setPropertyByName(String Property, Object Value)" function to set the boolean value of the checkbox
AreaDispatch.setPropertyByName("Value", new Boolean(true));
Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 7/11/2006.
Last Modified by No Author Name Available!.
Article has been viewed 7352 times.
Rated 6 out of 10 based on 8 votes.
Print Article
Email Article