Difference between revisions of "Documentation/DevGuide/ProUNO/Bridge/Value Objects"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
m
Line 14: Line 14:
  
 
A Value Object exposes four functions that can be accessed through <code>IDispatch</code>. These are:
 
A Value Object exposes four functions that can be accessed through <code>IDispatch</code>. These are:
 
+
<source lang="idl">
 
   void Set( [in]VARIANT type, [in]VARIANT value);
 
   void Set( [in]VARIANT type, [in]VARIANT value);
 
+
</source>
 
Assigns a type and a value.
 
Assigns a type and a value.
 
+
<source lang="idl">
 
   void Get( [out,retval] VARIANT* val);
 
   void Get( [out,retval] VARIANT* val);
 
+
</source>
 
Returns the value contained in the object. Get is used when the Value Object was used as inout or out parameter.
 
Returns the value contained in the object. Get is used when the Value Object was used as inout or out parameter.
 
+
<source lang="idl">
 
   void InitOutParam();
 
   void InitOutParam();
 
+
</source>
 
Tells the object that it is used as out parameter.
 
Tells the object that it is used as out parameter.
 
+
<source lang="idl">
 
   void InitInOutParam( [in]VARIANT type, [in]VARIANT value);
 
   void InitInOutParam( [in]VARIANT type, [in]VARIANT value);
 
+
</source>
 
Tells the object that it is used as inout parameter and passes the value for the in parameter, as well as the type.
 
Tells the object that it is used as inout parameter and passes the value for the in parameter, as well as the type.
  
Line 79: Line 79:
  
 
To show that the value is a sequence, put brackets before the names, for example:
 
To show that the value is a sequence, put brackets before the names, for example:
 
+
<source lang="idl">
 
   []char - sequence<char>
 
   []char - sequence<char>
 
   [][]char - sequence < sequence <char > >  
 
   [][]char - sequence < sequence <char > >  
 
   [][][]char - sequence < sequence < sequence < char > > >
 
   [][][]char - sequence < sequence < sequence < char > > >
 
+
</source>
 
The <code>Value Objects</code> are provided by the bridge and can be obtained from the service manager object. The service manager is a registered COM component with the ProgId “com.sun.star.ServiceManager” ([[Documentation/DevGuide/ProUNO/Bridge/The Service Manager Component|The Service Manager Component]]). For example:
 
The <code>Value Objects</code> are provided by the bridge and can be obtained from the service manager object. The service manager is a registered COM component with the ProgId “com.sun.star.ServiceManager” ([[Documentation/DevGuide/ProUNO/Bridge/The Service Manager Component|The Service Manager Component]]). For example:
 
+
<source lang="javascript">
 
   // JScript
 
   // JScript
 
   var valueObject= objSericeManager.Bridge_GetValueObject();
 
   var valueObject= objSericeManager.Bridge_GetValueObject();
 
+
</source>
 
To use a <code>Value Object</code> as in parameter, specify the type and pass the value to the object:
 
To use a <code>Value Object</code> as in parameter, specify the type and pass the value to the object:
 
+
<source lang="idl">
 
   // UNO IDL
 
   // UNO IDL
 
   void doSomething( [in] sequence< short > ar);
 
   void doSomething( [in] sequence< short > ar);
 
+
</source>
 +
<source lang="javascript">
 
   // JScript
 
   // JScript
 
   var value= objServiceManager.Bridge_GetValueObject();
 
   var value= objServiceManager.Bridge_GetValueObject();
Line 99: Line 100:
 
   value.Set("[]short",array);
 
   value.Set("[]short",array);
 
   object.doSomething( value);
 
   object.doSomething( value);
 
+
</source>
 
In the previous example, the <code>Value Object</code> was defined to be a sequence of short values. The array could also contain <code>Value Objects</code> again:
 
In the previous example, the <code>Value Object</code> was defined to be a sequence of short values. The array could also contain <code>Value Objects</code> again:
 
+
<source lang="javascript">
 
   var value1= objServiceManager.Bridge_GetValueObject();
 
   var value1= objServiceManager.Bridge_GetValueObject();
 
   var value2= objServiceManager.Bridge_GetValueObject();
 
   var value2= objServiceManager.Bridge_GetValueObject();
Line 112: Line 113:
 
   allValue.Set("[]short“, array);
 
   allValue.Set("[]short“, array);
 
   object.doSomething( allValue);
 
   object.doSomething( allValue);
 
+
</source>
 
If a function takes an out parameter, tell the <code>Value Object</code> like this:
 
If a function takes an out parameter, tell the <code>Value Object</code> like this:
 
+
<source lang="idl">
 
   // UNO IDL
 
   // UNO IDL
 
   void doSomething( [out] long);
 
   void doSomething( [out] long);
 
+
</source>
 
+
<source lang="javascript">
 
   // JScript
 
   // JScript
 
   var value= objServiceManager.Bridge_GetValueObject();
 
   var value= objServiceManager.Bridge_GetValueObject();
Line 124: Line 125:
 
   object.doSomething( value);
 
   object.doSomething( value);
 
   var out= value.Get();
 
   var out= value.Get();
 
+
</source>
 
When the <code>Value Object</code> is an <code>inout</code> parameter, it needs to know the type and value as well:
 
When the <code>Value Object</code> is an <code>inout</code> parameter, it needs to know the type and value as well:
 
+
<source lang="idl">
 
   //UNO IDL
 
   //UNO IDL
 
   void doSomething( [inout] long);
 
   void doSomething( [inout] long);
 
+
</source>
 
+
<source lang="javascript">
 
   //JScript
 
   //JScript
 
   var value= objServiceManager.Bridge_GetValueObject();
 
   var value= objServiceManager.Bridge_GetValueObject();
Line 136: Line 137:
 
   object.doSomething(value);
 
   object.doSomething(value);
 
   var out= value.Get();
 
   var out= value.Get();
 
+
</source>
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Professional UNO]]
 
[[Category:Documentation/Developer's Guide/Professional UNO]]

Revision as of 14:50, 22 October 2009



A Value Object is an Automation object which can be obtained from the bridge. It can hold a value and a type description, hence it resembles a UNO any or a VARIANT. A Value Object can stand in for all kinds of arguments in a call to a UNO method from a automation language. A Value Object is used when the bridge needs additional information for the parameter conversion. This is the case when a UNO method takes an any as argument. In many cases, however, one can do without a Value Object if one provides an argument which maps exactly to the expected UNO type according to the default mapping. For example, a UNO method takes an any as argument which is expected to contain a short. Then it would be sufficient to provide a Long in Visual Basic. But in JScript there are no types and implicitly a four byte integer would be passed to the call. Then the any would not contain a short and the call may fail. In that case the Value Object would guarantee the proper conversion.

A Value Object also enables in/out and out parameter in languages which only know in-parameters in functions. JScript is a particular case because one can use Array objects as well as Value Objects for those parameters.

A Value Object exposes four functions that can be accessed through IDispatch. These are:

  void Set( [in]VARIANT type, [in]VARIANT value);

Assigns a type and a value.

  void Get( [out,retval] VARIANT* val);

Returns the value contained in the object. Get is used when the Value Object was used as inout or out parameter.

  void InitOutParam();

Tells the object that it is used as out parameter.

  void InitInOutParam( [in]VARIANT type, [in]VARIANT value);

Tells the object that it is used as inout parameter and passes the value for the in parameter, as well as the type.

When the Value Object is used as in or inout parameter then specify the type of the value. The names of types correspond to the names used in UNO IDL, except for the “object” name. The following table shows what types can be specified.

Name (used with Value Object) UNO IDL
char char
boolean boolean
byte byte
unsigned unsigned byte
short short
unsigned short unsigned short
long long
unsigned long unsigned long
string string
float float
double double
any any
object some UNO interface

To show that the value is a sequence, put brackets before the names, for example:

  []char - sequence<char>
  [][]char - sequence < sequence <char > > 
  [][][]char - sequence < sequence < sequence < char > > >

The Value Objects are provided by the bridge and can be obtained from the service manager object. The service manager is a registered COM component with the ProgId “com.sun.star.ServiceManager” (The Service Manager Component). For example:

  // JScript
  var valueObject= objSericeManager.Bridge_GetValueObject();

To use a Value Object as in parameter, specify the type and pass the value to the object:

  // UNO IDL
  void doSomething( [in] sequence< short > ar);
  // JScript
  var value= objServiceManager.Bridge_GetValueObject();
  var array= new Array(1,2,3);
  value.Set("[]short",array);
  object.doSomething( value);

In the previous example, the Value Object was defined to be a sequence of short values. The array could also contain Value Objects again:

  var value1= objServiceManager.Bridge_GetValueObject();
  var value2= objServiceManager.Bridge_GetValueObject();
  value1.Set("short“, 100);
  value2.Set("short", 111);
  var array= new Array();
  array[0]= value1;
  array[1]= value2;
  var allValue= objServiceManager.Bridge_GetValueObject();
  allValue.Set("[]short, array);
  object.doSomething( allValue);

If a function takes an out parameter, tell the Value Object like this:

  // UNO IDL
  void doSomething( [out] long);
  // JScript
  var value= objServiceManager.Bridge_GetValueObject();
  value.InitOutParam();
  object.doSomething( value);
  var out= value.Get();

When the Value Object is an inout parameter, it needs to know the type and value as well:

  //UNO IDL
  void doSomething( [inout] long);
  //JScript
  var value= objServiceManager.Bridge_GetValueObject();
  value.InitInOutParam("long", 123);
  object.doSomething(value);
  var out= value.Get();
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages