home *** CD-ROM | disk | FTP | other *** search
/ Tutto per Internet / Internet.iso / soft95 / Html / PerlW32 / oleauto.pod < prev    next >
Encoding:
Text File  |  1996-01-31  |  2.9 KB  |  88 lines

  1. =head1 NAME
  2.  
  3. oleauto - OLE Automation extensions
  4.  
  5. =head1 DESCRIPTION
  6.  
  7. OLE Automation provides Visual Basic-like scripting capabilities to
  8. Perl 5 under Windows NT or Windows 95, exploiting the object-oriented
  9. programming facilities of Perl 5.
  10.  
  11. The OLE Automation extensions have been completely rewritten since the
  12. previous major version of Perl for Win32 (09x), resulting in a much cleaner
  13. syntax and added support for embedded objects (no more MkOLEx
  14. kludges!). OCX's are currently not supported, nor are VBX's.
  15.  
  16. =head2 Syntax
  17.  
  18. A simple Microsoft Excel application:
  19.  
  20.     use OLE;
  21.  
  22.     $excel = CreateObject OLE 'Excel.Application.5'
  23.            or warn "Couldn't create new instance of Excel App!!";
  24.     $excel->Workbooks->Open( 'test.xls' );
  25.     $excel->Workbooks(1)->Worksheets('Sheet1')->Cells(1,2)->{Value} = 'foo';
  26.     $excel->Workbooks(1)->Worksheets('Sheet1')->Cells(1,2)->{Value} = 'bar';
  27.     $excel->Save();
  28.     $excel->Quit();
  29.  
  30. OLE Automation objects are created using the C<CreateObject> method of
  31. the C<OLE> module. The name of the class of OLE object to create is
  32. supplied as the only argument. On success, the handle to the object is
  33. returned, otherwise undef is returned.
  34.  
  35.     $object = CreateObject OLE $class
  36.         or warn "Couldn't create instant of $class!!\n";
  37.  
  38. To invoke methods or retrieve properties within the object, one then uses
  39. the standard Perl 5 O-O syntax. Arguments must be supplied in the
  40. correct order (usually in the order that they are listed in the
  41. documentation associated with a particular class. e.g. in the help
  42. files for Microsoft Excel).
  43.  
  44.     $object->wave();
  45.     $object->say_hello();
  46.  
  47. Properties are also accessible via the perl object's hash
  48. structure. Since the return value of a function cannot be treated as
  49. an lvalue, the hash is the only means by which we can modify an
  50. object's properties.
  51.  
  52.     print "I weigh this many pounds: ",
  53.         $object->{weight}, "\n";
  54.  
  55.     $object->{weight} -= 25;
  56.  
  57.     print "Hey, I lost 25 pounds, I now weigh this many pounds: ",
  58.         $object->{weight}, "\n";
  59.  
  60. If a method or a property returns an embedded OLE object, it can
  61. automatically be treated as a perl object itself. E.g.
  62.  
  63.     $object->dad->grandad->tell_old_war_stories();
  64.  
  65. ...will invoke the method C<tell_old_war_stories> in C<grandad> which is
  66. an embedded object within C<dad>, which itself is an embedded object
  67. in C<$object>. The same goes for properties:
  68.  
  69.     print "My girlfriend weighs this many pounds: ",
  70.         $object->girlfriend->{weight}, "\n";
  71.  
  72.     $object->girlfriend->{weight} -= 25;
  73.  
  74.     print "Hey, she lost 25 pounds, she now weigh this many pounds: ",
  75.         $object->girlfriend->{weight}, "\n";
  76.  
  77.  
  78. Simple as Pie!!
  79.  
  80. =head2 Note to previous users of NT Perl
  81.  
  82. Since the OLE Automation scheme has been completely revised, none of
  83. the former constructs have to be used. There is no need for C<MkOLEx>,
  84. and there is only one C<OLE> module for all OLE Automation objects
  85. (i.e. no need to use the module C<OLE::Word_Basic> etc).
  86.  
  87. =cut
  88.