home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _f03ae9cb7caf5581594898f8380bad40 < prev    next >
Text File  |  2000-03-23  |  23KB  |  477 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Win32::OLE::Variant - Create and modify OLE VARIANT variables</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Win32::OLE::Variant - Create and modify OLE VARIANT variables</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <UL>
  26.  
  27.         <LI><A HREF="#functions">Functions</A></LI>
  28.         <LI><A HREF="#methods">Methods</A></LI>
  29.         <LI><A HREF="#overloading">Overloading</A></LI>
  30.         <LI><A HREF="#class variables">Class Variables</A></LI>
  31.         <LI><A HREF="#constants">Constants</A></LI>
  32.         <LI><A HREF="#variants">Variants</A></LI>
  33.         <LI><A HREF="#variant arrays">Variant arrays</A></LI>
  34.         <LI><A HREF="#variants by reference">Variants by reference</A></LI>
  35.     </UL>
  36.  
  37.     <LI><A HREF="#authors/copyright">AUTHORS/COPYRIGHT</A></LI>
  38. </UL>
  39. <!-- INDEX END -->
  40.  
  41. <HR>
  42. <P>
  43. <H1><A NAME="name">NAME</A></H1>
  44. <P>Win32::OLE::Variant - Create and modify OLE VARIANT variables</P>
  45. <P>
  46. <HR>
  47. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  48. <UL>
  49. <LI>Windows</LI>
  50. </UL>
  51. <HR>
  52. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  53. <PRE>
  54.         use Win32::OLE::Variant;
  55.         my $var = Variant(VT_DATE, 'Jan 1,1970');
  56.         $OleObject->{value} = $var;
  57.         $OleObject->Method($var);</PRE>
  58. <P>
  59. <HR>
  60. <H1><A NAME="description">DESCRIPTION</A></H1>
  61. <P>The IDispatch interface used by the Perl OLE module uses a universal
  62. argument type called VARIANT.  This is basically an object containing
  63. a data type and the actual data value.  The data type is specified by
  64. the VT_xxx constants.</P>
  65. <P>
  66. <H2><A NAME="functions">Functions</A></H2>
  67. <DL>
  68. <DT><STRONG><A NAME="item_Variant">Variant(TYPE, DATA)</A></STRONG><BR>
  69. <DD>
  70. This is just a function alias of the <CODE>Win32::OLE::Variant-</CODE>new()>
  71. method (see below).  This function is exported by default.
  72. <P></P></DL>
  73. <P>
  74. <H2><A NAME="methods">Methods</A></H2>
  75. <DL>
  76. <DT><STRONG><A NAME="item_new">new(TYPE, DATA)</A></STRONG><BR>
  77. <DD>
  78. This method returns a Win32::OLE::Variant object of the specified
  79. TYPE that contains the given DATA.  The Win32::OLE::Variant object
  80. can be used to specify data types other than IV, NV or PV (which are
  81. supported transparently).  See <EM>Variants</EM> below for details.
  82. <P>For VT_EMPTY and VT_NULL variants, the DATA argument may be omitted.
  83. For all non-VT_ARRAY variants DATA specifies the initial value.</P>
  84. <P>To create a SAFEARRAY variant, you have to specify the VT_ARRAY flag in
  85. addition to the variant base type of the array elemnts.  In this cases
  86. DATA must be a list specifying the dimensions of the array.  Each element
  87. can be either an element count (indices 0 to count-1) or an array
  88. reference pointing to the lower and upper array bounds of this dimension:</P>
  89. <PRE>
  90.         my $Array = Win32::OLE::Variant->new(VT_ARRAY|VT_R8, [1,2], 2);</PRE>
  91. <P>This creates a 2-dimensional SAFEARRAY of doubles with 4 elements:
  92. (1,0), (1,1), (2,0) and (2,1).</P>
  93. <P>A special case is the the creation of one-dimensional VT_UI1 arrays with
  94. a string DATA argument:</P>
  95. <PRE>
  96.         my $String = Variant(VT_ARRAY|VT_UI1, "String");</PRE>
  97. <P>This creates a 6 element character array initialized to ``String''.  For
  98. backward compatibility VT_UI1 with a string initializer automatically
  99. implies VT_ARRAY.  The next line is equivalent to the previous example:</P>
  100. <PRE>
  101.         my $String = Variant(VT_UI1, "String");</PRE>
  102. <P>If you really need a single character VT_UI1 variant, you have to create
  103. it using a numeric intializer:</P>
  104. <PRE>
  105.         my $Char = Variant(VT_UI1, ord('A'));</PRE>
  106. <P></P>
  107. <DT><STRONG><A NAME="item_As"><CODE>As(TYPE)</CODE></A></STRONG><BR>
  108. <DD>
  109. <A HREF="#item_As"><CODE>As</CODE></A> converts the VARIANT to the new type before converting to a
  110. Perl value.  This take the current LCID setting into account.  For
  111. example a string might contain a ',' as the decimal point character.
  112. Using <CODE>$variant-</CODE>As(VT_R8)> will correctly return the floating
  113. point value.
  114. <P>The underlying variant object is NOT changed by this method.</P>
  115. <P></P>
  116. <DT><STRONG><A NAME="item_ChangeType"><CODE>ChangeType(TYPE)</CODE></A></STRONG><BR>
  117. <DD>
  118. This method changes the type of the contained VARIANT in place.  It
  119. returns the object itself, not the converted value.
  120. <P></P>
  121. <DT><STRONG><A NAME="item_Copy"><CODE>Copy([DIM])</CODE></A></STRONG><BR>
  122. <DD>
  123. This method creates a copy of the object.  If the original variant had
  124. the VT_BYREF bit set then the new object will contain a copy of the
  125. referenced data and not a reference to the same old data.  The new
  126. object will not have the VT_BYREF bit set.
  127. <PRE>
  128.         my $Var = Variant(VT_I4|VT_ARRAY|VT_BYREF, [1,5], 3);
  129.         my $Copy = $Var->Copy;</PRE>
  130. <P>The type of <CODE>$Copy</CODE> is now VT_I4|VT_ARRAY and the value is a copy of
  131. the other SAFEARRAY.  Changes to elements of <CODE>$Var</CODE> will not be reflected
  132. in <CODE>$Copy</CODE> and vice versa.</P>
  133. <P>The <A HREF="#item_Copy"><CODE>Copy</CODE></A> method can also be used to extract a single element of a
  134. VT_ARRAY | VT_VARIANT object.  In this case the array indices must be
  135. specified as a list DIM:</P>
  136. <PRE>
  137.         my $Int = $Var->Copy(1, 2);</PRE>
  138. <P><CODE>$Int</CODE> is now a VT_I4 Variant object containing the value of element (1,2).</P>
  139. <P></P>
  140. <DT><STRONG><A NAME="item_Currency">Currency([FORMAT[, LCID]])</A></STRONG><BR>
  141. <DD>
  142. This method converts the VARIANT value into a formatted curency string.  The
  143. FORMAT can be either an integer constant or a hash reference.  Valid constants
  144. are 0 and LOCALE_NOUSEROVERRIDE.  You get the value of LOCALE_NOUSEROVERRIDE
  145. from the Win32::OLE::NLS module:
  146. <PRE>
  147.         use Win32::OLE::NLS qw(:LOCALE);</PRE>
  148. <P>LOCALE_NOUSEROVERRIDE tells the method to use the system default currency
  149. format for the specified locale, disregarding any changes that might have
  150. been made through the control panel application.</P>
  151. <P>The hash reference could contain the following keys:</P>
  152. <PRE>
  153.         NumDigits       number of fractional digits
  154.         LeadingZero     whether to use leading zeroes in decimal fields
  155.         Grouping        size of each group of digits to the left of the decimal
  156.         DecimalSep      decimal separator string
  157.         ThousandSep     thousand separator string
  158.         NegativeOrder   see L<Win32::OLE::NLS/LOCALE_ICURRENCY>
  159.         PositiveOrder   see L<Win32::OLE::NLS/LOCALE_INEGCURR>
  160.         CurrencySymbol  currency symbol string</PRE>
  161. <P>For example:</P>
  162. <PRE>
  163.         use Win32::OLE::Variant;
  164.         use Win32::OLE::NLS qw(:DEFAULT :LANG :SUBLANG :DATE :TIME);
  165.         my $lcidGerman = MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL));
  166.         my $v = Variant(VT_CY, "-922337203685477.5808");
  167.         print $v->Currency({CurrencySymbol => "Tuits"}, $lcidGerman), "\n";</PRE>
  168. <P>will print:</P>
  169. <PRE>
  170.         -922.337.203.685.477,58 Tuits</PRE>
  171. <P></P>
  172. <DT><STRONG><A NAME="item_Date">Date([FORMAT[, LCID]])</A></STRONG><BR>
  173. <DD>
  174. Converts the VARIANT into a formatted date string.  FORMAT can be either
  175. one of the following integer constants or a format string:
  176. <PRE>
  177.         LOCALE_NOUSEROVERRIDE   system default date format for this locale
  178.         DATE_SHORTDATE          use the short date format (default)
  179.         DATE_LONGDATE           use the long date format
  180.         DATE_YEARMONTH          use the year/month format
  181.         DATE_USE_ALT_CALENDAR   use the alternate calendar, if one exists
  182.         DATE_LTRREADING         left-to-right reading order layout
  183.         DATE_RTLREADING         right-to left reading order layout</PRE>
  184. <P>The constants are available from the Win32::OLE::NLS module:</P>
  185. <PRE>
  186.         use Win32::OLE::NLS qw(:LOCALE :DATE);</PRE>
  187. <P>The following elements can be used to construct a date format string.
  188. Characters must be specified exactly as given below (e.g. ``dd'' <STRONG>not</STRONG> ``DD'').
  189. Spaces can be inserted anywhere between formating codes, other verbatim
  190. text should be included in single quotes.</P>
  191. <PRE>
  192.         d       day of month
  193.         dd      day of month with leading zero for single-digit days
  194.         ddd     day of week: three-letter abbreviation (LOCALE_SABBREVDAYNAME)
  195.         dddd    day of week: full name (LOCALE_SDAYNAME)
  196.         M       month
  197.         MM      month with leading zero for single-digit months
  198.         MMM     month: three-letter abbreviation (LOCALE_SABBREVMONTHNAME)
  199.         MMMM    month: full name (LOCALE_SMONTHNAME)
  200.         y       year as last two digits
  201.         yy      year as last two digits with leading zero for years less than 10
  202.         yyyy    year represented by full four digits
  203.         gg      period/era string</PRE>
  204. <P>For example:</P>
  205. <PRE>
  206.         my $v = Variant(VT_DATE, "April 1 99");
  207.         print $v->Date(DATE_LONGDATE), "\n";
  208.         print $v->Date("ddd',' MMM dd yy"), "\n";</PRE>
  209. <P>will print:</P>
  210. <PRE>
  211.         Thursday, April 01, 1999
  212.         Thu, Apr 01 99</PRE>
  213. <P></P>
  214. <DT><STRONG><A NAME="item_Dim"><CODE>Dim()</CODE></A></STRONG><BR>
  215. <DD>
  216. Returns a list of array bounds for a VT_ARRAY variant.  The list contains
  217. an array reference for each dimension of the variant's SAFEARRAY.  This
  218. reference points to an array containing the lower and upper bounds for
  219. this dimension.  For example:
  220. <PRE>
  221.         my @Dim = $Var->Dim;</PRE>
  222. <P>Now <CODE>@Dim</CODE> contains the following list: <CODE>([1,5], [0,2])</CODE>.</P>
  223. <P></P>
  224. <DT><STRONG><A NAME="item_Get"><CODE>Get(DIM)</CODE></A></STRONG><BR>
  225. <DD>
  226. For normal variants <A HREF="#item_Get"><CODE>Get</CODE></A> returns the value of the variant, just like the
  227. <A HREF="#item_Value"><CODE>Value</CODE></A> method.  For VT_ARRAY variants <A HREF="#item_Get"><CODE>Get</CODE></A> retrieves the value of a single
  228. array element.  In this case <CODE>DIM</CODE> must be a list of array indices.  E.g.
  229. <PRE>
  230.         my $Val = $Var->Get(2,0);</PRE>
  231. <P>As a special case for one dimensional VT_UI1|VT_ARRAY variants the <A HREF="#item_Get"><CODE>Get</CODE></A>
  232. method without arguments returns the character array as a Perl string.</P>
  233. <PRE>
  234.         print $String->Get, "\n";</PRE>
  235. <P></P>
  236. <DT><STRONG><A NAME="item_LastError"><CODE>LastError()</CODE></A></STRONG><BR>
  237. <DD>
  238. The use of the <CODE>Win32::OLE::Variant-</CODE>LastError()> method is deprecated.
  239. Please use the <CODE>Win32::OLE-</CODE>LastError()> class method instead.
  240. <P></P>
  241. <DT><STRONG><A NAME="item_Number">Number([FORMAT[, LCID]])</A></STRONG><BR>
  242. <DD>
  243. This method converts the VARIANT value into a formatted number string.  The
  244. FORMAT can be either an integer constant or a hash reference.  Valid constants
  245. are 0 and LOCALE_NOUSEROVERRIDE.  You get the value of LOCALE_NOUSEROVERRIDE
  246. from the Win32::OLE::NLS module:
  247. <PRE>
  248.         use Win32::OLE::NLS qw(:LOCALE);</PRE>
  249. <P>LOCALE_NOUSEROVERRIDE tells the method to use the system default number
  250. format for the specified locale, disregarding any changes that might have
  251. been made through the control panel application.</P>
  252. <P>The hash reference could contain the following keys:</P>
  253. <PRE>
  254.         NumDigits       number of fractional digits
  255.         LeadingZero     whether to use leading zeroes in decimal fields
  256.         Grouping        size of each group of digits to the left of the decimal
  257.         DecimalSep      decimal separator string
  258.         ThousandSep     thousand separator string
  259.         NegativeOrder   see L<Win32::OLE::NLS/LOCALE_INEGNUMBER></PRE>
  260. <P></P>
  261. <DT><STRONG><A NAME="item_Put">Put(DIM, VALUE)</A></STRONG><BR>
  262. <DD>
  263. The <A HREF="#item_Put"><CODE>Put</CODE></A> method is used to assign a new value to a variant.  The value will
  264. be coerced into the current type of the variant.  E.g.:
  265. <PRE>
  266.         my $Var = Variant(VT_I4, 42);
  267.         $Var->Put(3.1415);</PRE>
  268. <P>This changes the value of the variant to <CODE>3</CODE> because the type is VT_I4.</P>
  269. <P>For VT_ARRAY type variants the indices for each dimension of the contained
  270. SAFEARRAY must be specified in front of the new value:</P>
  271. <PRE>
  272.         $Array->Put(1, 1, 2.7);</PRE>
  273. <P>It is also possible to assign values to *every* element of the SAFEARRAY at
  274. once using a single <A HREF="#item_Put"><CODE>Put()</CODE></A> method call:</P>
  275. <PRE>
  276.         $Array->Put([[1,2], [3,4]]);</PRE>
  277. <P>In this case the argument to <A HREF="#item_Put"><CODE>Put()</CODE></A> must be an array reference and the
  278. dimensions of the Perl list-of-lists must match the dimensions of the
  279. SAFEARRAY exactly.</P>
  280. <P>The are a few special cases for one-dimensional VT_UI1 arrays: The VALUE
  281. can be specified as a string instead of a number.  This will set the selected
  282. character to the first character of the string or to '\0' if the string was
  283. empty:</P>
  284. <PRE>
  285.         my $String = Variant(VT_UI1|VT_ARRAY, "ABCDE");
  286.         $String->Put(1, "123");
  287.         $String->Put(3, ord('Z'));
  288.         $String->Put(4, '');</PRE>
  289. <P>This will set the value of <CODE>$String</CODE> to <CODE>"A1CZ\0"</CODE>.  If the index is omitted
  290. then the string is copied to the value completely.  The string is truncated
  291. if it is longer than the size of the VT_UI1 array.  The result will be padded
  292. with '\0's if the string is shorter:</P>
  293. <PRE>
  294.         $String->Put("String");</PRE>
  295. <P>Now <CODE>$String</CODE> contains the value ``Strin''.</P>
  296. <P><A HREF="#item_Put"><CODE>Put</CODE></A> returns the Variant object itself so that multiple <A HREF="#item_Put"><CODE>Put</CODE></A> calls can be
  297. chained together:</P>
  298. <PRE>
  299.         $Array->Put(0,0,$First_value)->Put(0,1,$Another_value);</PRE>
  300. <P></P>
  301. <DT><STRONG><A NAME="item_Time">Time([FORMAT[, LCID]])</A></STRONG><BR>
  302. <DD>
  303. Converts the VARIANT into a formatted time string.  FORMAT can be either
  304. one of the following integer constants or a format string:
  305. <PRE>
  306.         LOCALE_NOUSEROVERRIDE   system default time format for this locale
  307.         TIME_NOMINUTESORSECONDS don't use minutes or seconds
  308.         TIME_NOSECONDS          don't use seconds
  309.         TIME_NOTIMEMARKER       don't use a time marker
  310.         TIME_FORCE24HOURFORMAT  always use a 24-hour time format</PRE>
  311. <P>The constants are available from the Win32::OLE::NLS module:</P>
  312. <PRE>
  313.         use Win32::OLE::NLS qw(:LOCALE :TIME);</PRE>
  314. <P>The following elements can be used to construct a time format string.
  315. Characters must be specified exactly as given below (e.g. ``dd'' <STRONG>not</STRONG> ``DD'').
  316. Spaces can be inserted anywhere between formating codes, other verbatim
  317. text should be included in single quotes.</P>
  318. <PRE>
  319.         h       hours; 12-hour clock
  320.         hh      hours with leading zero for single-digit hours; 12-hour clock
  321.         H       hours; 24-hour clock
  322.         HH      hours with leading zero for single-digit hours; 24-hour clock
  323.         m       minutes
  324.         mm      minutes with leading zero for single-digit minutes
  325.         s       seconds
  326.         ss      seconds with leading zero for single-digit seconds
  327.         t       one character time marker string, such as A or P
  328.         tt      multicharacter time marker string, such as AM or PM</PRE>
  329. <P>For example:</P>
  330. <PRE>
  331.         my $v = Variant(VT_DATE, "April 1 99 2:23 pm");
  332.         print $v->Time, "\n";
  333.         print $v->Time(TIME_FORCE24HOURFORMAT|TIME_NOTIMEMARKER), "\n";
  334.         print $v->Time("hh.mm.ss tt"), "\n";</PRE>
  335. <P>will print:</P>
  336. <PRE>
  337.         2:23:00 PM
  338.         14:23:00
  339.         02.23.00 PM</PRE>
  340. <P></P>
  341. <DT><STRONG><A NAME="item_Type"><CODE>Type()</CODE></A></STRONG><BR>
  342. <DD>
  343. The <A HREF="#item_Type"><CODE>Type</CODE></A> method returns the variant type of the contained VARIANT.
  344. <P></P>
  345. <DT><STRONG><A NAME="item_Unicode"><CODE>Unicode()</CODE></A></STRONG><BR>
  346. <DD>
  347. The <A HREF="#item_Unicode"><CODE>Unicode</CODE></A> method returns a <CODE>Unicode::String</CODE> object.  This contains
  348. the BSTR value of the variant in network byte order.  If the variant is
  349. not currently in VT_BSTR format then a VT_BSTR copy will be produced first.
  350. <P></P>
  351. <DT><STRONG><A NAME="item_Value"><CODE>Value()</CODE></A></STRONG><BR>
  352. <DD>
  353. The <A HREF="#item_Value"><CODE>Value</CODE></A> method returns the value of the VARIANT as a Perl value.  The
  354. conversion is performed in the same manner as all return values of
  355. Win32::OLE method calls are converted.
  356. <P></P></DL>
  357. <P>
  358. <H2><A NAME="overloading">Overloading</A></H2>
  359. <P>The Win32::OLE::Variant package has overloaded the conversion to
  360. string and number formats.  Therefore variant objects can be used in
  361. arithmetic and string operations without applying the <A HREF="#item_Value"><CODE>Value</CODE></A>
  362. method first.</P>
  363. <P>
  364. <H2><A NAME="class variables">Class Variables</A></H2>
  365. <P>The Win32::OLE::Variant class used to have its own set of class variables
  366. like <CODE>$CP</CODE>, <CODE>$LCID</CODE> and <CODE>$Warn</CODE>.  In version 0.1003 and later of the
  367. Win32::OLE module these variables have been eleminated.  Now the settings
  368. of Win32::OLE are used by the Win32::OLE::Variant module too.  Please read
  369. the documentation of the <CODE>Win32::OLE-&gt;Option</CODE> class method.</P>
  370. <P>
  371. <H2><A NAME="constants">Constants</A></H2>
  372. <P>These constants are exported by default:</P>
  373. <PRE>
  374.         VT_EMPTY
  375.         VT_NULL
  376.         VT_I2
  377.         VT_I4
  378.         VT_R4
  379.         VT_R8
  380.         VT_CY
  381.         VT_DATE
  382.         VT_BSTR
  383.         VT_DISPATCH
  384.         VT_ERROR
  385.         VT_BOOL
  386.         VT_VARIANT
  387.         VT_UNKNOWN
  388.         VT_DECIMAL
  389.         VT_UI1</PRE>
  390. <PRE>
  391.         VT_ARRAY
  392.         VT_BYREF</PRE>
  393. <P>VT_DECIMAL is not on the official list of allowable OLE Automation
  394. datatypes.  But even Microsoft ADO seems to sometimes return values
  395. of Recordset fields in VT_DECIMAL format.</P>
  396. <P>
  397. <H2><A NAME="variants">Variants</A></H2>
  398. <P>A Variant is a data type that is used to pass data between OLE
  399. connections.</P>
  400. <P>The default behavior is to convert each perl scalar variable into
  401. an OLE Variant according to the internal perl representation.
  402. The following type correspondence holds:</P>
  403. <PRE>
  404.         C type          Perl type       OLE type
  405.         ------          ---------       --------
  406.           int              IV            VT_I4
  407.         double             NV            VT_R8
  408.         char *             PV            VT_BSTR
  409.         void *           ref to AV       VT_ARRAY
  410.            ?              undef          VT_ERROR
  411.            ?        Win32::OLE object    VT_DISPATCH</PRE>
  412. <P>Note that VT_BSTR is a wide character or Unicode string.  This presents a
  413. problem if you want to pass in binary data as a parameter as 0x00 is
  414. inserted between all the bytes in your data.  The <A HREF="#item_Variant"><CODE>Variant()</CODE></A> method
  415. provides a solution to this.  With Variants the script writer can specify
  416. the OLE variant type that the parameter should be converted to.  Currently
  417. supported types are:</P>
  418. <PRE>
  419.         VT_UI1     unsigned char
  420.         VT_I2      signed int (2 bytes)
  421.         VT_I4      signed int (4 bytes)
  422.         VT_R4      float      (4 bytes)
  423.         VT_R8      float      (8 bytes)
  424.         VT_DATE    OLE Date
  425.         VT_BSTR    OLE String
  426.         VT_CY      OLE Currency
  427.         VT_BOOL    OLE Boolean</PRE>
  428. <P>When VT_DATE and VT_CY objects are created, the input parameter is treated
  429. as a Perl string type, which is then converted to VT_BSTR, and finally to
  430. VT_DATE of VT_CY using the <CODE>VariantChangeType()</CODE> OLE API function.
  431. See <A HREF="../../../../site/lib/Win32/OLE.html#examples">EXAMPLES in the Win32::OLE manpage</A> for how these types can be used.</P>
  432. <P>
  433. <H2><A NAME="variant arrays">Variant arrays</A></H2>
  434. <P>A variant can not only contain a single value but also a multi-dimensional
  435. array of values (called a SAFEARRAY).  In this case the VT_ARRAY flag must
  436. be added to the base variant type, e.g. <CODE>VT_I4 | VT_ARRAY</CODE> for an array of
  437. integers.  The VT_EMPTY and VT_NULL types are invalid for SAFEARRAYs.  It
  438. is possible to create an array of variants: <CODE>VT_VARIANT | VT_ARRAY</CODE>.  In this
  439. case each element of the array can have a different type (including VT_EMPTY
  440. and VT_NULL).  The elements of a VT_VARIANT SAFEARRAY cannot have either of the
  441. VT_ARRAY or VT_BYREF flags set.</P>
  442. <P>The lower and upper bounds for each dimension can be specified separately.
  443. They do not have to have all the same lower bound (unlike Perl's arrays).</P>
  444. <P>
  445. <H2><A NAME="variants by reference">Variants by reference</A></H2>
  446. <P>Some OLE servers expect parameters passed by reference so that they
  447. can be changed in the method call.  This allows methods to easily
  448. return multiple values.  There is preliminary support for this in
  449. the Win32::OLE::Variant module:</P>
  450. <PRE>
  451.         my $x = Variant(VT_I4|VT_BYREF, 0);
  452.         my $y = Variant(VT_I4|VT_BYREF, 0);
  453.         $Corel->GetSize($x, $y);
  454.         print "Size is $x by $y\n";</PRE>
  455. <P>After the <CODE>GetSize</CODE> method call <CODE>$x</CODE> and <CODE>$y</CODE> will be set to
  456. the respective sizes.  They will still be variants.  In the print
  457. statement the overloading converts them to string representation
  458. automatically.</P>
  459. <P>VT_BYREF is now supported for all variant types (including SAFEARRAYs).
  460. It can also be used to pass an OLE object by reference:</P>
  461. <PRE>
  462.         my $Results = $App->CreateResultsObject;
  463.         $Object->Method(Variant(VT_DISPATCH|VT_BYREF, $Results));</PRE>
  464. <P>
  465. <HR>
  466. <H1><A NAME="authors/copyright">AUTHORS/COPYRIGHT</A></H1>
  467. <P>This module is part of the Win32::OLE distribution.</P>
  468. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  469. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  470. <STRONG><P CLASS=block> Win32::OLE::Variant - Create and modify OLE VARIANT variables</P></STRONG>
  471. </TD></TR>
  472. </TABLE>
  473.  
  474. </BODY>
  475.  
  476. </HTML>
  477.