Difference between revisions of "Zh/Documentation/DevGuide/ProUNO/Bridge/Mapping of Simple Types"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (New page: {{Documentation/DevGuide/ProUNOTOC/Zh |ProUNO2c=block |ABridgeSvcMgr=block |ABridgeTM=block |ABridgeDM=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/ProUNO/Bridge/Default M...)
 
m
 
(3 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
|NextPage=Zh/Documentation/DevGuide/ProUNO/Bridge/Mapping of Hyper and Decimal
 
|NextPage=Zh/Documentation/DevGuide/ProUNO/Bridge/Mapping of Hyper and Decimal
 
}}
 
}}
[[en:Documentation/DevGuide/ProUNO/Bridge/Mapping of Simple Types]]
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/Bridge/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:简单类型的映射}}
 
{{DISPLAYTITLE:简单类型的映射}}
  
Many languages have equivalents for the IDL simple types, such as integer and floating point types. Some languages, however, may not support all these types. For example, JScript is a typeless language and only recognizes a general number type. Internally, it uses four byte signed integer values and double values to represent a number. When a UNO method is called that takes a float as an argument, and that value is at some point returned to the caller, then the values may differ slightly. This is because the bridge converts the double to a float, which is eventually converted back to a double.
+
许多语言都拥有与 IDL 简单类型等同的内容,如整数类型和浮点类型。但是,有些语言可能不支持所有这些类型。例如,JScript 是一种无类型语言,只能识别一般的数字类型。在内部,其使用四字节有符号整数值和双精度值表示一个数值。当调用将 float 作为参数的 UNO 方法并且在某点将值返回调用程序时,值可能稍有不同。这是因为桥将双精度数转换成了浮点数,最后又将浮点数转换成了双精度数。
  
If a UNO method takes an any as argument and the implementation expects a certain type within the any, then the bridge is not always able to provide the expected value. Assuming, that a UNO method takes an any that is supposed to contain a short and the method is to be called from JScript, then the bridge will provide an any containing a four byte integer. This may result in an exception from the initiator of the call The solution is to use a Value Object ([[Documentation/DevGuide/ProUNO/Bridge/Value Objects|Value Objects]]).
 
  
Unlike Automation, there are unsigned integer types in UNO. To provide a positive value that exceeds the maximum value of the corresponding signed type, you have to use the corresponding negative value. For example, to call the following UNO function in VB with the value 32768 (0x8000) you need to pass -32768 .
+
如果 UNO 方法将 any 作为参数,并且实现需要 any 内的某一类型,则桥就不一定总是能够提供所需要的值。假定 UNO 方法接受包含短整数的 any 且要从 Jscript 调用该方法,则桥将提供一个包含四字节整数的 any。这可能会导致调用的发起者端出现异常。解决方案是使用值对象  ([[Documentation/DevGuide/ProUNO/Bridge/Value Objects|专业 UNO - UNO 语言绑定 - Automation 桥 - 类型映射 - 值对象]])。
 +
 
 +
 
 +
与 Automation 不同,UNO 中存在无符号整数类型。如果提供的正值超出有符号类型的最大值,就必须使用对应的负值。例如,在 VB 中调用以下 UNO 函数,当传递值为 32768 (0x8000) 时就需要传递 -32768。
  
 
   //UNO IDL
 
   //UNO IDL
Line 24: Line 26:
 
   obj.foo(val)
 
   obj.foo(val)
  
The rule for calculating the negative equivalent is:
+
 
 +
计算所对应负值的规则为:
  
 
   signed_value = unsigned_value - (max_unsigned +1)
 
   signed_value = unsigned_value - (max_unsigned +1)
  
In the preceding example, unsigned_value is the value that we want to pass, and which is 32768. This value is one too many for the VB type Integer, that is why we have to provide a negative value. max_unsigned has the value 65535 for a two byte integer. So the equation is
+
 
 +
在前面示例中,unsigned_value 是我们要传递的值 32768。对于 VB 类型整数,该值太大超出了可以表示的范围。这就是我们为什么必须提供一个负值的原因,对于二字节整数,max_unsigned 的值为 65535。因此,计算方程为
  
 
   -32768 = 32768 - (65535 + 1)
 
   -32768 = 32768 - (65535 + 1)
  
Alternatively you can use a type with a greater value range. The Automation bridge will then perform a narrowing conversion.
+
 
 +
此外,您也可以使用值的范围更大的类型。然后,Automation 桥将执行一次收缩转换。
  
 
   Dim val As Long 'four byte signed integer
 
   Dim val As Long 'four byte signed integer
Line 38: Line 43:
 
   obj.foo(val)'expects a two byte unsigned int
 
   obj.foo(val)'expects a two byte unsigned int
  
For more information about conversions see chapter [[Documentation/DevGuide/ProUNO/Bridge/Conversion Mappings|Conversion Mappings]].
+
 
 +
有关转换的详细信息,请参阅 [[Zh/Documentation/DevGuide/ProUNO/Bridge/Conversion Mappings|专业 UNO - UNO 语言绑定 - Automation 桥 - 类型映射 - 转换映射]] 一章。
  
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developer's Guide/Professional UNO]]
+
[[Category:文档/开发者指南/专业 UNO]]

Latest revision as of 03:06, 14 May 2009



许多语言都拥有与 IDL 简单类型等同的内容,如整数类型和浮点类型。但是,有些语言可能不支持所有这些类型。例如,JScript 是一种无类型语言,只能识别一般的数字类型。在内部,其使用四字节有符号整数值和双精度值表示一个数值。当调用将 float 作为参数的 UNO 方法并且在某点将值返回调用程序时,值可能稍有不同。这是因为桥将双精度数转换成了浮点数,最后又将浮点数转换成了双精度数。


如果 UNO 方法将 any 作为参数,并且实现需要 any 内的某一类型,则桥就不一定总是能够提供所需要的值。假定 UNO 方法接受包含短整数的 any 且要从 Jscript 调用该方法,则桥将提供一个包含四字节整数的 any。这可能会导致调用的发起者端出现异常。解决方案是使用值对象 (专业 UNO - UNO 语言绑定 - Automation 桥 - 类型映射 - 值对象)。


与 Automation 不同,UNO 中存在无符号整数类型。如果提供的正值超出有符号类型的最大值,就必须使用对应的负值。例如,在 VB 中调用以下 UNO 函数,当传递值为 32768 (0x8000) 时就需要传递 -32768。

 //UNO IDL
 void foo(unsigned short value);
 'VB
 Dim val As Integer 'two byte signed integer
 val = -32768
 obj.foo(val)


计算所对应负值的规则为:

 signed_value = unsigned_value - (max_unsigned +1)


在前面示例中,unsigned_value 是我们要传递的值 32768。对于 VB 类型整数,该值太大超出了可以表示的范围。这就是我们为什么必须提供一个负值的原因,对于二字节整数,max_unsigned 的值为 65535。因此,计算方程为

 -32768 = 32768 - (65535 + 1)


此外,您也可以使用值的范围更大的类型。然后,Automation 桥将执行一次收缩转换。

 Dim val As Long 'four byte signed integer
 val = 32768
 obj.foo(val)'expects a two byte unsigned int


有关转换的详细信息,请参阅 专业 UNO - UNO 语言绑定 - Automation 桥 - 类型映射 - 转换映射 一章。

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages