libwin32-0.26 >
0.1502
との差分
Win32::OLE 0.1502 と 0.26 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | ||
4 | 5 | =head1 NAME |
5 | 6 | |
6 | ||
7 | Win32::OLE - OLEオートメーション拡張 | |
7 | 8 | |
8 | Win32::OLE - OLE Automation extensions | |
9 | ||
10 | =end original | |
11 | ||
12 | Win32::OLE - OLE オートメーション拡張 | |
13 | ||
14 | 9 | =head1 SYNOPSIS |
15 | 10 | |
16 | 11 | $ex = Win32::OLE->new('Excel.Application') or die "oops\n"; |
17 | 12 | $ex->Amethod("arg")->Bmethod->{'Property'} = "foo"; |
18 | 13 | $ex->Cmethod(undef,undef,$Arg3); |
19 | 14 | $ex->Dmethod($RequiredArg1, {NamedArg1 => $Value1, NamedArg2 => $Value2}); |
20 | 15 | |
21 | 16 | $wd = Win32::OLE->GetObject("D:\\Data\\Message.doc"); |
22 | 17 | $xl = Win32::OLE->GetActiveObject("Excel.Application"); |
23 | 18 | |
24 | 19 | =head1 DESCRIPTION |
25 | 20 | |
26 | ||
21 | このモジュールはPerlからのOLEオートメーションへのインターフェースを提供します。 | |
22 | OLEオートメーションはVisualBasicのようなスクリプトの能力を提供し、強力な拡張性とPerlスクリプトから数多くのWin32アプリケーションを制御する能力を提供します。 | |
27 | 23 | |
28 | ||
24 | Win32::OLEモジュールはIDispatchインターフェースを独占的に使用します。 カスタムOLEインターフェースにアクセスすることはできません。 OLEインベントとOCXは現在のところサポートされていません。 | |
29 | OLE Automation brings VisualBasic like scripting capabilities and | |
30 | offers powerful extensibility and the ability to control many Win32 | |
31 | applications from Perl scripts. | |
32 | 25 | |
33 | ||
26 | 実際には、これはもはや厳密には正しくありません。 このモジュールはOLEイベントをB<アルファ>レベルでサポートをしています。 これはあまりテストされていませんし、インタフェース仕様は将来変更される可能性があります。 | |
34 | 27 | |
35 | このモジュールは Perl からの OLE オートメーションへのインターフェースを | |
36 | 提供します。 | |
37 | OLE オートメーションは VisualBasic のようなスクリプトの能力を提供し、 | |
38 | 強力な拡張性と Perl スクリプトから数多くの Win32 アプリケーションを | |
39 | 制御する能力を提供します。 | |
40 | ||
41 | =begin original | |
42 | ||
43 | The Win32::OLE module uses the IDispatch interface exclusively. It is | |
44 | not possible to access a custom OLE interface. OLE events and OCX's are | |
45 | currently not supported. | |
46 | ||
47 | =end original | |
48 | ||
49 | Win32::OLE モジュールはもっぱら IDispatch インターフェースを使用します。 | |
50 | カスタム OLE インターフェースにアクセスすることはできません。 | |
51 | OLE インベントと OCX には現在のところ対応していません。 | |
52 | ||
53 | =begin original | |
54 | ||
55 | Actually, that's no longer strictly true. This module now contains | |
56 | B<ALPHA> level support for OLE events. This is largely untested and the | |
57 | specific interface might still change in the future. | |
58 | ||
59 | =end original | |
60 | ||
61 | 実際には、これは厳密には正しくありません。 | |
62 | このモジュールは OLE イベントに B<アルファ> レベルで対応しています。 | |
63 | これはあまりテストされていませんし、インタフェース仕様は将来 | |
64 | 変更される可能性があります。 | |
65 | ||
66 | 28 | =head2 Methods |
67 | 29 | |
68 | (メソッド) | |
69 | ||
70 | 30 | =over 8 |
71 | 31 | |
72 | 32 | =item Win32::OLE->new(PROGID[, DESTRUCTOR]) |
73 | 33 | |
74 | ||
34 | new() クラス・メソッドはOLEオートメーション・オブジェクトの新しいインスタンスを開始します。 | |
35 | このオブジェクトのリファレンスか、もし作成が失敗すればundefを返します。 | |
75 | 36 | |
76 | ||
37 | PROGID 引数は必要なアプリケーションのI<OLEプログラムID>またはI<クラスID>でなければなりません。 オプションのDESTRUCTORにはDESTROYのようなメソッドを指定します。 これはCODEリファレンスまたはOLEメソッド名の入った文字列のどちらかにすることができます。 これはPerlプログラムが死ぬ(die)するときに、OLEアプリケーションをきれいに終らせるために使われます。 | |
77 | It returns a reference to this object or C<undef> if the creation failed. | |
78 | 38 | |
79 | ||
39 | DCOMを通じてリモート・サーバーにオブジェクトを作成するためには、PROGIDのところに配列リファレンスを使うことができます。 参照される配列にはマシン名とI<プログラムID>またはI<クラスID>が入らなければなりません。 例えば: | |
80 | 40 | |
81 | new() クラスメソッドは OLE オートメーションオブジェクトの新しい | |
82 | インスタンスを開始します。 | |
83 | このオブジェクトのリファレンスか、もし作成が失敗すれば C<undef> を返します。 | |
84 | ||
85 | =begin original | |
86 | ||
87 | The PROGID argument must be either the OLE I<program id> or the I<class id> | |
88 | of the required application. The optional DESTRUCTOR specifies a DESTROY-like | |
89 | method. This can be either a CODE reference or a string containing an OLE | |
90 | method name. It can be used to cleanly terminate OLE applications in case the | |
91 | Perl program dies. | |
92 | ||
93 | =end original | |
94 | ||
95 | PROGID 引数は必要なアプリケーションの OLE I<プログラム ID> または | |
96 | I<クラス ID> でなければなりません。 | |
97 | オプションの DESTRUCTOR には DESTROY のようなメソッドを指定します。 | |
98 | これは CODE リファレンスまたは OLE メソッド名の入った文字列のどちらかに | |
99 | することができます。 | |
100 | これは Perl プログラムが die するときに、OLE アプリケーションを | |
101 | きれいに終らせるために使われます。 | |
102 | ||
103 | =begin original | |
104 | ||
105 | To create an object via DCOM on a remote server you can use an array | |
106 | reference in place of PROGID. The referenced array must contain the | |
107 | machine name and the I<program id> or I<class id>. For example: | |
108 | ||
109 | =end original | |
110 | ||
111 | DCOM を通じてリモートサーバーにオブジェクトを作成するためには、PROGID の | |
112 | ところに配列リファレンスを使えます。 | |
113 | 参照される配列にはマシン名と I<プログラム ID> または I<クラス ID> が | |
114 | 入らなければなりません。 | |
115 | 例えば: | |
116 | ||
117 | 41 | my $obj = Win32::OLE->new(['my.machine.com', 'Program.Id']); |
118 | 42 | |
119 | ||
43 | PROGIDがI<プログラムID>であれば、Win32::OLEはローカルに対応するI<クラスID>を解決しようとします。 もしローカルにI<プログラムID>が登録されていなければ、リモート・レジストリが問い合わせられます。 これはローカルなプロセスがリモート・レジストリに読み込みアクセスをもっているときにのみ成功します。 もっとも安全な(そしても最も速い)方法は、C<クラスID>を直接指定することです。 | |
120 | 44 | |
121 | If the PROGID is a I<program id> then Win32::OLE will try to resolve the | |
122 | corresponding I<class id> locally. If the I<program id> is not registered | |
123 | locally then the remote registry is queried. This will only succeed if | |
124 | the local process has read access to the remote registry. The safest | |
125 | (and fastest) method is to specify the C<class id> directly. | |
126 | ||
127 | =end original | |
128 | ||
129 | PROGID が I<プログラム ID> であれば、Win32::OLE はローカルに対応する | |
130 | I<クラス ID> を解決しようとします。 | |
131 | もしローカルに I<プログラム ID> が登録されていなければ、リモートレジストリが | |
132 | 問い合わせられます。 | |
133 | これはローカルなプロセスがリモートレジストリに読み込みアクセスを | |
134 | もっているときにのみ成功します。 | |
135 | もっとも安全な(そしても最も速い)方法は、C<クラス ID> を直接指定することです。 | |
136 | ||
137 | 45 | =item Win32::OLE->EnumAllObjects([CALLBACK]) |
138 | 46 | |
139 | ||
47 | このクラス・メソッドは現在存在するWin32::OLEオブジェクトの数を返します。 オプションで各オブジェクトへのCALLBACK関数を呼ぶこともできます: | |
140 | 48 | |
141 | This class method returns the number Win32::OLE objects currently in | |
142 | existance. It will call the optional CALLBACK function for each of | |
143 | these objects: | |
144 | ||
145 | =end original | |
146 | ||
147 | このクラスメソッドは現在存在する Win32::OLE オブジェクトの数を返します。 | |
148 | オプションで各オブジェクトへの CALLBACK 関数を呼ぶこともできます: | |
149 | ||
150 | 49 | $Count = Win32::OLE->EnumAllObjects(sub { |
151 | 50 | my $Object = shift; |
152 | 51 | my $Class = Win32::OLE->QueryObjectType($Object); |
153 | 52 | printf "# Object=%s Class=%s\n", $Object, $Class; |
154 | 53 | }); |
155 | 54 | |
156 | ||
55 | EnumAllObjects() メソッドは主にデバッグのためのツールです。 これは例えば、すべての外部コメンクションが適切に破壊されているかをチェックするためにENDブロックに入れて使うことができます。 | |
157 | 56 | |
158 | The EnumAllObjects() method is primarily a debugging tool. It can be | |
159 | used e.g. in an END block to check if all external connections have | |
160 | been properly destroyed. | |
161 | ||
162 | =end original | |
163 | ||
164 | EnumAllObjects() メソッドは主にデバッグのためのツールです。 | |
165 | これは例えば、すべての外部コメンクションが適切に破壊されているかを | |
166 | チェックするために END ブロックに入れて使えます。 | |
167 | ||
168 | 57 | =item Win32::OLE->FreeUnusedLibraries() |
169 | 58 | |
170 | ||
59 | FreeUnusedLibraries() クラス・メソッドは使われていないOLEリソースのすべてをアンロードします。 これらは破壊されたすべての存在しているオブジェクトのクラスのライブラリです。 オブジェクト・ライブラリのアンロードは、長時間とても多くのB<異なる>オブジェクトを繰り返し、インスタンス生成するプロセスを実行したときにだけ本当に重要です。 | |
171 | 60 | |
172 | ||
61 | Visual Basicで実装されたオブジェクトはこの機能についてバグを持っているかもしれないことに注意してください; 実際に彼らのクリーンアップ・コードを実行するまではアンロード可能にすることを拒みます。 その時点でDLLをアンロードすることは典型的には、アクセス・バイオレーションを発生させます。 この問題の可能性はSpinMessageLoop() メソッドを呼び出し、2,3秒sleep()することにより減らすことができます。 | |
173 | resources. These are the libraries of those classes of which all | |
174 | existing objects have been destroyed. The unloading of object | |
175 | libraries is really only important for long running processes that | |
176 | might instantiate a huge number of B<different> objects over time. | |
177 | 62 | |
178 | =end original | |
179 | ||
180 | FreeUnusedLibraries() クラスメソッドは全ての使われていない OLE リソースを | |
181 | アンロードします。 | |
182 | これらは存在しているオブジェクトのすべてが破壊されたクラスのライブラリです。 | |
183 | オブジェクトライブラリのアンロードは、長時間とても多くの B<異なる> | |
184 | オブジェクトを繰り返し、インスタンス生成するプロセスを実行したときにだけ | |
185 | 本当に重要です。 | |
186 | ||
187 | =begin original | |
188 | ||
189 | Be aware that objects implemented in Visual Basic have a buggy | |
190 | implementation of this functionality: They pretend to be unloadable | |
191 | while they are actually still running their cleanup code. Unloading | |
192 | the DLL at that moment typically produces an access violation. The | |
193 | probability for this problem can be reduced by calling the | |
194 | SpinMessageLoop() method and sleep()ing for a few seconds. | |
195 | ||
196 | =end original | |
197 | ||
198 | Visual Basic で実装されたオブジェクトはこの機能についてバグを | |
199 | 持っているかもしれないことに注意してください。 | |
200 | 実際に彼らのクリーンアップコードを実行するまではアンロード可能に | |
201 | することを拒みます。 | |
202 | その時点でDLLをアンロードすることは典型的には、アクセスバイオレーションを | |
203 | 発生させます。 | |
204 | この問題の可能性は SpinMessageLoop() メソッドを呼び出し、2, 3秒 | |
205 | sleep() することにより減らすことができます。 | |
206 | ||
207 | 63 | =item Win32::OLE->GetActiveObject(CLASS[, DESTRUCTOR]) |
208 | 64 | |
209 | ||
65 | GetActiveObject() クラスメソッドは指定されたOLEオートメーション・サーバーの動いているインスタンスへのOLEリファレンスを返します。 もしサーバーが現在アクティブでなければ、C<undef>を返します。 そのクラス登録さえもしていなければ、croakします。 オプションのDESTRUCTORメソッドはメソッド名、あるいはコード・リファレンスをとります。 このオブジェクトへの最後のリファレンスが失われるときに実行されます。 一般的にあなたが起動したのではないアプリケーションを止めることは一般的にはC<無作法>だと考えられます。 | |
210 | 66 | |
211 | The GetActiveObject() class method returns an OLE reference to a | |
212 | running instance of the specified OLE automation server. It returns | |
213 | C<undef> if the server is not currently active. It will croak if | |
214 | the class is not even registered. The optional DESTRUCTOR method takes | |
215 | either a method name or a code reference. It is executed when the last | |
216 | reference to this object goes away. It is generally considered C<impolite> | |
217 | to stop applications that you did not start yourself. | |
218 | ||
219 | =end original | |
220 | ||
221 | GetActiveObject() クラスメソッドは指定された OLE オートメーションサーバーの | |
222 | 動いているインスタンスへの OLE リファレンスを返します。 | |
223 | もしサーバーが現在アクティブでなければ、C<undef> を返します。 | |
224 | そのクラス登録さえもしていなければ、croak します。 | |
225 | オプションの DESTRUCTOR メソッドはメソッド名、あるいはコードリファレンスを | |
226 | とります。 | |
227 | このオブジェクトへの最後のリファレンスが失われるときに実行されます。 | |
228 | 一般的にあなたが起動したのではないアプリケーションを止めることは | |
229 | 一般的には無作法だと考えられます。 | |
230 | ||
231 | 67 | =item Win32::OLE->GetObject(MONIKER[, DESTRUCTOR]) |
232 | 68 | |
233 | ||
69 | GetObject() クラスメソッドは指定されたオブジェクトへのOLEリファレンスを返します。 そのオブジェクトはパス名で指定され、オプションで後ろにエクスクラメーション・マーク '!'によって区切られた追加の要素サブコンポーネントがつきます。 オプションのDESTRUCTOR引数はnew() やGetActiveObject()と同じ意味を持ちます。 | |
234 | 70 | |
235 | The GetObject() class method returns an OLE reference to the specified | |
236 | object. The object is specified by a pathname optionally followed by | |
237 | additional item subcomponent separated by exclamation marks '!'. The | |
238 | optional DESTRUCTOR argument has the same semantics as the DESTRUCTOR in | |
239 | new() or GetActiveObject(). | |
240 | ||
241 | =end original | |
242 | ||
243 | GetObject() クラスメソッドは指定されたオブジェクトへの OLE リファレンスを | |
244 | 返します。 | |
245 | そのオブジェクトはパス名で指定され、オプションで後ろに | |
246 | エクスクラメーションマーク '!'によって区切られた追加の要素 | |
247 | サブコンポーネントがつきます。 | |
248 | オプションの DESTRUCTOR 引数は new() や GetActiveObject() と | |
249 | 同じ意味を持ちます。 | |
250 | ||
251 | 71 | =item Win32::OLE->Initialize([COINIT]) |
252 | 72 | |
253 | ||
73 | Initialize() クラス・メソッドはPerlスレッドのための代わりのアパートメント・モデルを指定するために使うことができます。 これは最初のOLEオブジェクトが作成されるB<前に>呼ばれなければなりません。 もしC<Win32::OLE::Const>モジュールが使われていれば、Initialize() メソッドの呼出しは最初のC<Win32::OLE::Const>モジュールのためのC<use>ステートメントの前のBEGINブロックでされなければなりません。 | |
254 | 74 | |
255 | ||
75 | COINITへの正しい値は以下の通りです: | |
256 | apartment model for the Perl thread. It must be called B<before> the | |
257 | first OLE object is created. If the C<Win32::OLE::Const> module is | |
258 | used then the call to the Initialize() method must be made from a BEGIN | |
259 | block before the first C<use> statement for the C<Win32::OLE::Const> | |
260 | module. | |
261 | 76 | |
262 | ||
77 | Win32::OLE::COINIT_APARTMENTTHREADED - 単一スレッド | |
263 | ||
264 | Initialize() クラスメソッドは Perl スレッドのための代わりの | |
265 | アパートメントモデルを指定するために使えます。 | |
266 | これは最初の OLE オブジェクトが作成される B<前> に呼ばれなければなりません。 | |
267 | もし C<Win32::OLE::Const> モジュールが使われていれば、Initialize() メソッドの | |
268 | 呼び出しは最初の C<Win32::OLE::Const> モジュールのための C<use> | |
269 | ステートメントの前の BEGIN ブロックでされなければなりません。 | |
270 | ||
271 | =begin original | |
272 | ||
273 | Valid values for COINIT are: | |
274 | ||
275 | =end original | |
276 | ||
277 | COINTへの正しい値は以下の通りです: | |
278 | ||
279 | =begin original | |
280 | ||
281 | Win32::OLE::COINIT_APARTMENTTHREADED - single threaded | |
282 | Win32::OLE::COINIT_MULTITHREADED - the default | |
283 | Win32::OLE::COINIT_OLEINITIALIZE - single threaded, additional OLE stuff | |
284 | ||
285 | =end original | |
286 | ||
287 | Win32::OLE::COINIT_APARTMENTTHREADED - シングルスレッド | |
288 | 78 | Win32::OLE::COINIT_MULTITHREADED - デフォルト |
289 | Win32::OLE::COINIT_OLEINITIALIZE - | |
79 | Win32::OLE::COINIT_OLEINITIALIZE - 単一スレッド、追加のOLE機能 | |
290 | 80 | |
291 | ||
81 | COINIT_OLEINITIALIZE はOLEオブジェクトが、通常のCOMサブシステムでは利用できない、追加のOLEコンパウンド・ドキュメント技術を使っているさいに、ときおり必要になります(例えばMAPIセッションはこれが必要なようです)。 | |
82 | COINIT_OLEINITIALIZE と COINIT_APARTMENTTHREADED は隠れたトップ・レベル・ウィンドウとPerlプロセスのためのメッセージ・キューを作成します。 これは他のアプリケーションとの問題を発生させるかもしれません;というのもPerlは通常そのメッセージ・キューを処理しないからです。 つまりアプリケーション間で同期型通信(DDEイニシエーションのような)を使っているプログラムはPerlが他のOLEメソッド呼出し/プロパティ・アクセスをおこすか、終了するまで止まってしまうかもしれません。 | |
83 | これは InstallShieldセットアップやシェル関連から発生する多くの事柄にあてはまります。 デフォルトのCOINIT_MULTITHREADEDモデルを使うことができないのであれば、C<Win32::OLE-E<gt>SpinMessageLoop> と C<Win32::OLE-E<gt>Uninitialize> メソッドを使ってみてください。 | |
292 | 84 | |
293 | COINIT_OLEINITIALIZE is sometimes needed when an OLE object uses | |
294 | additional OLE compound document technologies not available from the | |
295 | normal COM subsystem (for example MAPI.Session seems to require it). | |
296 | Both COINIT_OLEINITIALIZE and COINIT_APARTMENTTHREADED create a hidden | |
297 | top level window and a message queue for the Perl process. This may | |
298 | create problems with other application, because Perl normally doesn't | |
299 | process its message queue. This means programs using synchronous | |
300 | communication between applications (such as DDE initiation), may hang | |
301 | until Perl makes another OLE method call/property access or terminates. | |
302 | This applies to InstallShield setups and many things started to shell | |
303 | associations. Please try to utilize the C<Win32::OLE-E<gt>SpinMessageLoop> | |
304 | and C<Win32::OLE-E<gt>Uninitialize> methods if you can not use the default | |
305 | COINIT_MULTITHREADED model. | |
306 | ||
307 | =end original | |
308 | ||
309 | COINIT_OLEINITIALIZE は OLE オブジェクトが、通常の COM サブシステムでは | |
310 | 利用できない、追加の OLE コンパウンドドキュメント技術を使っているさいに、 | |
311 | ときおり必要になります(例えば MAPI セッションはこれが必要なようです)。 | |
312 | COINIT_OLEINITIALIZE と COINIT_APARTMENTTHREADED は隠れたトップレベル | |
313 | ウィンドウと Perl プロセスのためのメッセージキューを作成します。 | |
314 | これは他のアプリケーションとの問題を発生させるかもしれません。 | |
315 | というのも Perl は通常そのメッセージキューを処理しないからです。 | |
316 | つまりアプリケーション間で同期型通信(DDE イニシエーションのような)を | |
317 | 使っているプログラムは Perl が他の OLE メソッド呼び出し/プロパティアクセスを | |
318 | おこすか、終了するまで止まってしまうかもしれません。 | |
319 | これは InstallShield セットアップやシェル関連から発生する多くの事柄に | |
320 | あてはまります。 | |
321 | デフォルトの COINIT_MULTITHREADED モデルを使うことができないのであれば、 | |
322 | C<Win32::OLE-E<gt>SpinMessageLoop> と C<Win32::OLE-E<gt>Uninitialize> | |
323 | メソッドをを使ってみてください。 | |
324 | ||
325 | 85 | =item OBJECT->Invoke(METHOD[, ARGS]) |
326 | 86 | |
327 | ||
87 | Invoke() オブジェクト・メソッドはOLEメソッドを呼び出す代替方法です。 これは通常C<$OBJECT->METHOD(@ARGS)>と同じです。 この関数は METHOD名にPerl変数名として正しくない文字(例えば外国の文字)が入っているときに使わなければなりません。 もしデフォルトのメソッドがライブラリで名前を与えられていなくても、そのオブジェクトのデフォルトのメソッドを呼び出すために使うことができます。 この場合には<undef>またはC<''>をメソッド名として使います。 OLEオブジェクト・ネイティブのInvoke()メソッドを(もしそのようなものがあったとして)呼び出すためには、以下のようにします: | |
328 | 88 | |
329 | The Invoke() object method is an alternate way to invoke OLE | |
330 | methods. It is normally equivalent to C<$OBJECT->METHOD(@ARGS)>. This | |
331 | function must be used if the METHOD name contains characters not valid | |
332 | in a Perl variable name (like foreign language characters). It can | |
333 | also be used to invoke the default method of an object even if the | |
334 | default method has not been given a name in the type library. In this | |
335 | case use <undef> or C<''> as the method name. To invoke an OLE objects | |
336 | native Invoke() method (if such a thing exists), please use: | |
337 | ||
338 | =end original | |
339 | ||
340 | Invoke() オブジェクトメソッドは OLE メソッドを呼び出す代替方法です。 | |
341 | これは通常 C<$OBJECT-E<gt>METHOD(@ARGS)> と同じです。 | |
342 | この関数は METHOD 名に Perl 変数名として正しくない文字 (例えば外国の文字) が | |
343 | 入っているときに使わなければなりません。 | |
344 | もしデフォルトのメソッドがライブラリで名前を与えられていなくても、その | |
345 | オブジェクトのデフォルトのメソッドを呼び出すために使えます。 | |
346 | この場合には C<undef> または C<''> をメソッド名として使います。 | |
347 | OLE オブジェクトネイティブの Invoke() メソッドを (もしそのようなものが | |
348 | あったとして) 呼び出すためには、以下のようにします: | |
349 | ||
350 | 89 | $Object->Invoke('Invoke', @Args); |
351 | 90 | |
352 | 91 | =item Win32::OLE->LastError() |
353 | 92 | |
354 | ||
93 | LastError() クラス・メソッドは最後に記録されたOLEエラーを返します。 これはC<$!>変数のように2つの値を持ちます:数値コンテキストではそれはエラー番号を返し、文字列コンテキストではそれはエラーメッセージを返します。 エラー番号は符号付きのHRESULTの値です。 符号なしの16進定数を符号付きの HRESULTに変換するためには L<HRESULT(ERROR)>関数を使ってください。 | |
355 | 94 | |
356 | ||
95 | 最後のOLEエラーは、後の正常なOLE呼出しによって自動的にリセットされます。 数値は明示的に呼び出すことによって設定することができます(それは文字列の値を捨てます): | |
357 | error. This is a dual value like the C<$!> variable: in a numeric | |
358 | context it returns the error number and in a string context it returns | |
359 | the error message. The error number is a signed HRESULT value. Please | |
360 | use the L<HRESULT(ERROR)> function to convert an unsigned hexadecimal | |
361 | constant to a signed HRESULT. | |
362 | 96 | |
363 | =end original | |
364 | ||
365 | LastError() クラスメソッドは最後に記録された OLE エラーを返します。 | |
366 | これは C<$!> 変数のように二つの値を持ちます: 数値コンテキストでは | |
367 | エラー番号を返し、文字列コンテキストではエラーメッセージを返します。 | |
368 | エラー番号は符号付きの HRESULT の値です。 | |
369 | 符号なしの 16 進定数を符号付きの HRESULT に変換するためには | |
370 | L<HRESULT(ERROR)> 関数を使ってください。 | |
371 | ||
372 | =begin original | |
373 | ||
374 | The last OLE error is automatically reset by a successful OLE | |
375 | call. The numeric value can also explicitly be set by a call (which will | |
376 | discard the string value): | |
377 | ||
378 | =end original | |
379 | ||
380 | 最後の OLE エラーは、後の正常な OLE 呼び出しによって自動的にリセットされます。 | |
381 | 数値は明示的に呼び出すことによって設定することができます(それは文字列の値を | |
382 | 捨てます): | |
383 | ||
384 | 97 | Win32::OLE->LastError(0); |
385 | 98 | |
386 | 99 | =item OBJECT->LetProperty(NAME,ARGS,VALUE) |
387 | 100 | |
388 | ||
101 | Win32::OLEでは、ハッシュの書き方を使ったプロパティ設定はVisual BasicのC<Set>と同じです(I<参照渡し>による代入): | |
389 | 102 | |
390 | In Win32::OLE property assignment using the hash syntax is equivalent | |
391 | to the Visual Basic C<Set> syntax (I<by reference> assignment): | |
392 | ||
393 | =end original | |
394 | ||
395 | Win32::OLE では、ハッシュの書き方を使ったプロパティ設定は Visual Basic の | |
396 | Set と同じです(I<リファレンスによる> 代入): | |
397 | ||
398 | 103 | $Object->{Property} = $OtherObject; |
399 | 104 | |
400 | ||
105 | はこのVisual Basic ステートメントに対応します: | |
401 | 106 | |
402 | corresponds to this Visual Basic statement: | |
403 | ||
404 | =end original | |
405 | ||
406 | これは以下の Visual Basic ステートメントに対応します: | |
407 | ||
408 | 107 | Set Object.Property = OtherObject |
409 | 108 | |
410 | ||
109 | 以下のようなVisual Basic C<Let> ステートメントのI<値渡し>による扱いを得るには: | |
411 | 110 | |
412 | To get the I<by value> treatment of the Visual Basic C<Let> statement | |
413 | ||
414 | =end original | |
415 | ||
416 | Visual Basic の C<Let> ステートメントの I<値による> 扱いを得るには: | |
417 | ||
418 | 111 | Object.Property = OtherObject |
419 | 112 | |
420 | ||
113 | PerlではLetProperty() オブジェクト・メソッドを使わなければなりません: | |
421 | 114 | |
422 | you have to use the LetProperty() object method in Perl: | |
423 | ||
424 | =end original | |
425 | ||
426 | Perl では LetProperty() オブジェクトメソッドを使う必要があります: | |
427 | ||
428 | 115 | $Object->LetProperty($Property, $OtherObject); |
429 | 116 | |
430 | =begin original | |
431 | ||
432 | LetProperty() also supports optional arguments for the property assignment. | |
433 | See L<OBJECT->SetProperty(NAME,ARGS,VALUE)> for details. | |
434 | ||
435 | =end original | |
436 | ||
437 | 117 | LetProperty() はプロパティ設定のためのオプションの引数もサポートしています。 |
438 | 詳しくは | |
118 | 詳しくはL<OBJECT->SetProperty(NAME,ARGS,VALUE)>を参照してください。 | |
439 | 119 | |
440 | 120 | =item Win32::OLE->MessageLoop() |
441 | 121 | |
442 | ||
122 | MessageLoop() クラス・メソッドは標準のWindowsメッセージループを実行し、QuitMessageLoop() クラスメソッドが呼ばれるまで、メッセージを処理します。 これはOLEイベントを待つために使われます。 | |
443 | 123 | |
444 | The MessageLoop() class method will run a standard Windows message | |
445 | loop, dispatching messages until the QuitMessageLoop() class method is | |
446 | called. It is used to wait for OLE events. | |
447 | ||
448 | =end original | |
449 | ||
450 | MessageLoop() クラスメソッドは標準の Windows メッセージループを実行し、 | |
451 | QuitMessageLoop() クラスメソッドが呼ばれるまで、メッセージを処理します。 | |
452 | これは OLE イベントを待つために使われます。 | |
453 | ||
454 | 124 | =item Win32::OLE->Option(OPTION) |
455 | 125 | |
456 | ||
126 | Option() クラス・メソッドはL<Module Options>を検査し、変更するために使うことができます。 1つだけ引数を指定すると、そのオプションの値を取り出します: | |
457 | 127 | |
458 | The Option() class method can be used to inspect and modify | |
459 | L<Module Options>. The single argument form retrieves the value of | |
460 | an option: | |
461 | ||
462 | =end original | |
463 | ||
464 | Option() クラスメソッドは L<Module Options> を検査し、変更するために | |
465 | 使えます。 | |
466 | 一つだけ引数を指定すると、そのオプションの値を取り出します: | |
467 | ||
468 | 128 | my $CP = Win32::OLE->Option('CP'); |
469 | 129 | |
470 | ||
130 | 一回の呼出しで複数のオプションを同時に設定することもできます: | |
471 | 131 | |
472 | A single call can be used to set multiple options simultaneously: | |
473 | ||
474 | =end original | |
475 | ||
476 | 一回の呼び出しで複数のオプションを同時に設定することもできます。 | |
477 | ||
478 | 132 | Win32::OLE->Option(CP => CP_ACP, Warn => 3); |
479 | 133 | |
480 | 134 | =item Win32::OLE->QueryObjectType(OBJECT) |
481 | 135 | |
482 | ||
136 | QueryObjectType() クラス・メソッドはタイプ・ライブラリ名とオブジェクト・クラス名のリストを返します。 スカラ・コンテキストではクラス名だけを返します。 タイプ情報が使えなければ、C<undef>を返します。 | |
483 | 137 | |
484 | The QueryObjectType() class method returns a list of the type library | |
485 | name and the objects class name. In a scalar context it returns the | |
486 | class name only. It returns C<undef> when the type information is not | |
487 | available. | |
488 | ||
489 | =end original | |
490 | ||
491 | QueryObjectType() クラスメソッドはタイプライブラリ名と | |
492 | オブジェクトクラス名のリストを返します。 | |
493 | スカラコンテキストではそれはクラス名だけを返します。 | |
494 | タイプ情報が使えなければ、C<undef> を返します。 | |
495 | ||
496 | 138 | =item Win32::OLE->QuitMessageLoop() |
497 | 139 | |
498 | ||
140 | QuitMessageLoop() クラス・メソッドは(ユーザー・レベルで)"Quit"メッセージを現在のスレッド・メッセージ・ループにポストします。 QuitMessageLoop() は典型的にはイベント・ハンドラから呼ばれます。 MessageLoop() クラス・メソッドは、この"Quit"メソッドを受け取ると、戻ります。 | |
499 | 141 | |
500 | The QuitMessageLoop() class method posts a (user-level) "Quit" message | |
501 | to the current threads message loop. QuitMessageLoop() is typically | |
502 | called from an event handler. The MessageLoop() class method will | |
503 | return when it receives this "Quit" method. | |
504 | ||
505 | =end original | |
506 | ||
507 | QuitMessageLoop() クラスメソッドは(ユーザーレベルで) "Quit" メッセージを | |
508 | 現在のスレッドメッセージループにポストします。 | |
509 | QuitMessageLoop() は典型的にはイベントハンドラから呼ばれます。 | |
510 | MessageLoop() クラスメソッドは、この "Quit" メソッドを受け取ると、戻ります。 | |
511 | ||
512 | 142 | =item OBJECT->SetProperty(NAME,ARGS,VALUE) |
513 | 143 | |
514 | ||
144 | SetProperty() メソッドはハッシュの書き方をサポートしていないプロパティを引数の値に変更することができます。 以下のハッシュ形式は: | |
515 | 145 | |
516 | The SetProperty() method allows to modify properties with arguments, | |
517 | which is not supported by the hash syntax. The hash form | |
518 | ||
519 | =end original | |
520 | ||
521 | SetProperty() メソッドはハッシュの書き方をサポートしていないプロパティを | |
522 | 引数の値に変更できます。 | |
523 | ハッシュ形式は以下の通りです | |
524 | ||
525 | 146 | $Object->{Property} = $Value; |
526 | 147 | |
527 | ||
148 | これは以下のものと同じです: | |
528 | 149 | |
529 | is equivalent to | |
530 | ||
531 | =end original | |
532 | ||
533 | これは以下のものと同じです | |
534 | ||
535 | 150 | $Object->SetProperty('Property', $Value); |
536 | 151 | |
537 | =begin original | |
538 | ||
539 | Arguments must be specified between the property name and the new value: | |
540 | ||
541 | =end original | |
542 | ||
543 | 152 | 引数はプロパティ名と新しい値の間に指定されなければなりません: |
544 | 153 | |
545 | 154 | $Object->SetProperty('Property', @Args, $Value); |
546 | 155 | |
547 | ||
156 | 新しい値はSetProperty()への最後の引数でなければならないので、この関数で"名前付き引数"の書き方を使うことはできません。 | |
548 | 157 | |
549 | ||
158 | このメソッドはSetProperty()と呼ばれるネイティブなOLEオブジェクト・メソッドを隠してしまいます。 | |
550 | ||
159 | そのネイティブなメソッドはInvoke() メソッドを使って呼び出すことができます: | |
551 | 160 | |
552 | =end original | |
553 | ||
554 | 新しい値は SetProperty() への最後の引数でなければならないので、この関数で | |
555 | 「名前付き引数」の書き方を使うことはできません。 | |
556 | ||
557 | =begin original | |
558 | ||
559 | This method hides any native OLE object method called SetProperty(). | |
560 | The native method will still be available through the Invoke() method: | |
561 | ||
562 | =end original | |
563 | ||
564 | このメソッドは SetProperty() と呼ばれるネイティブな OLE オブジェクト | |
565 | メソッドを隠してしまいます。 | |
566 | そのネイティブなメソッドは Invoke() メソッドを使って呼び出すことができます: | |
567 | ||
568 | 161 | $Object->Invoke('SetProperty', @Args); |
569 | 162 | |
570 | 163 | =item Win32::OLE->SpinMessageLoop |
571 | 164 | |
572 | ||
165 | このクラス・メソッドはすべてのメッセージ・キューに保留されているメッセージを取り出し、対応するWindowsプロシ?ジャーに処理させます。 このメソッドはCOINIT_MULTITHREADEDモデルを使っていないときにだけ必要になります。 | |
166 | すべてのOLEメソッド呼出しとプロパティ・アクセスは自動的にメッセージ・キューを処理します。 | |
573 | 167 | |
574 | This class method retrieves all pending messages from the message queue | |
575 | and dispatches them to their respective window procedures. Calling this | |
576 | method is only necessary when not using the COINIT_MULTITHREADED model. | |
577 | All OLE method calls and property accesses automatically process the | |
578 | message queue. | |
579 | ||
580 | =end original | |
581 | ||
582 | このクラスメソッドはすべてのメッセージキューに保留されている | |
583 | メッセージを取り出し、対応する Windows プロシ−ジャーに処理させます。 | |
584 | このメソッドは COINIT_MULTITHREADED モデルを使っていないときにだけ | |
585 | 必要になります。 | |
586 | すべての OLE メソッド呼び出しとプロパティアクセスは自動的に | |
587 | メッセージキューを処理します。 | |
588 | ||
589 | 168 | =item Win32::OLE->Uninitialize |
590 | 169 | |
591 | ||
170 | Uninitialize() クラス・メソッドはOLEサブシステムを消去します。 これは単一スレッド分離のためのOLEによって作られた隠れたトップ・レベル・ウィンドウも破壊します。 これを呼び出した後には、すべてのOLEオブジェクトが無効になります! | |
171 | Uninitialize()でOLEを終了させた後、再びInitialize() クラス・メソッドを異なる分離モデルで呼び出すことは可能です。 | |
592 | 172 | |
593 | The Uninitialize() class method uninitializes the OLE subsystem. It | |
594 | also destroys the hidden top level window created by OLE for single | |
595 | threaded apartments. All OLE objects will become invalid after this call! | |
596 | It is possible to call the Initialize() class method again with a different | |
597 | apartment model after shutting down OLE with Uninitialize(). | |
598 | ||
599 | =end original | |
600 | ||
601 | Uninitialize() クラスメソッドは OLE サブシステムの反初期化をします。 | |
602 | これはシングルスレッド分離のための OLE によって作られた隠れた | |
603 | トップレベルウィンドウを破壊もします。 | |
604 | これを呼び出した後には、すべての OLE オブジェクトが不適切になります! | |
605 | Uninitialize() で OLE を終了させた後、再び Initialize() クラスメソッドを | |
606 | 異なる分離モデルで呼び出すことは可能です。 | |
607 | ||
608 | 173 | =item Win32::OLE->WithEvents(OBJECT[, HANDLER[, INTERFACE]]) |
609 | 174 | |
610 | ||
175 | このクラス・メソッドはOBJECTによって指定されたイベントの発火を有効化および無効化できます。 HANDLERが指定されなければ、イベントは接続されません。 いくつかのオブジェクトではWin32::OLEは自動的に正しいイベント・インターフェースを判定できません。 その場合、 INTERFACE引数はOBJECTのCOCLASS名またはイベントDISPATCHインターフェースの名前のどちらかが入っていなければなりません。 Win32::OLEイベント・サポートの詳細な説明については下記のL<Events>セクションをお読みださい。 | |
611 | 176 | |
612 | This class method enables and disables the firing of events by the | |
613 | specified OBJECT. If no HANDLER is specified, then events are | |
614 | disconnected. For some objects Win32::OLE is not able to | |
615 | automatically determine the correct event interface. In this case the | |
616 | INTERFACE argument must contain either the COCLASS name of the OBJECT | |
617 | or the name of the event DISPATCH interface. Please read the L<Events> | |
618 | section below for detailed explanation of the Win32::OLE event | |
619 | support. | |
620 | ||
621 | =end original | |
622 | ||
623 | このクラスメソッドは OBJECT によって指定されたイベントを発火させるのを | |
624 | 可能にも不可能にもできます。 | |
625 | HANDLER が指定されなければ、イベントは接続されません。 | |
626 | いくつかのオブジェクトでは Win32::OLE は自動的に正しい | |
627 | イベントインターフェースを判定できません。 | |
628 | その場合、INTERFACE 引数は OBJECT の COCLASS 名またはイベント | |
629 | DISPATCH インターフェースの名前のどちらかが入っていなければなりません。 | |
630 | Win32::OLE イベントサポートの詳細な説明については下記の | |
631 | L</Events> セクションをお読みださい。 | |
632 | ||
633 | 177 | =back |
634 | 178 | |
635 | ||
179 | PerlがWin32::OLEパッケージでメソッド名を見つけられなかった場合、それは自動的にOLEメソッドの名前として使われ、このメソッド呼出しはOLEサーバーによって処理されます。 | |
636 | 180 | |
637 | ||
181 | このモジュールには1つの特別な方法が組み込まれています: もしメソッドまたはプロパティ名がOLEオブジェクトによって解決されなければ、オブジェクトのデフォルト・メソッドがそのメソッド名を第1引数として呼ばれます。 そこで | |
638 | is automatically used as the name of an OLE method and this method call | |
639 | is dispatched to the OLE server. | |
640 | 182 | |
641 | =end original | |
642 | ||
643 | Perl が Win32::OLE パッケージでメソッド名を見つけられなかった場合、それは | |
644 | 自動的に OLE メソッドの名前として使われます。 | |
645 | そしてこのメソッド呼び出しは OLE サーバーによって処理されます。 | |
646 | ||
647 | =begin original | |
648 | ||
649 | There is one special hack built into the module: If a method or property | |
650 | name could not be resolved with the OLE object, then the default method | |
651 | of the object is called with the method name as its first parameter. So | |
652 | ||
653 | =end original | |
654 | ||
655 | このモジュールには一つの特別な方法が組み込まれています。 | |
656 | もしメソッドまたはプロパティ名が OLE オブジェクトによって解決されなければ、 | |
657 | オブジェクトのデフォルトメソッドがそのメソッド名を第1引数として呼ばれます。 | |
658 | そこで | |
659 | ||
660 | 183 | my $Sheet = $Worksheets->Table1; |
661 | ||
662 | =begin original | |
663 | ||
664 | or | |
665 | ||
666 | =end original | |
667 | ||
668 | 184 | または |
669 | ||
670 | 185 | my $Sheet = $Worksheets->{Table1}; |
671 | 186 | |
672 | ||
187 | は以下のように解決されます: | |
673 | 188 | |
674 | is resolved as | |
675 | ||
676 | =end original | |
677 | ||
678 | は以下のように解決されます | |
679 | ||
680 | 189 | my $Sheet = $Worksheet->Item('Table1'); |
681 | 190 | |
682 | ||
191 | $WorksheeetsオブジェクトがC<Table1>メソッドまたはプロパティを持っていない場合です。 この方法はタイプ・ライブラリではメソッドに名前をつけないコレクションのデフォルト・メソッドを呼び出すために導入されています。 "名無しの"デフォルト・メソッドを呼び出す推奨される方法は以下の通りです: | |
683 | 192 | |
684 | provided that the $Worksheets object doesnot have a C<Table1> method | |
685 | or property. This hack has been introduced to call the default method | |
686 | of collections which did not name the method in their type library. The | |
687 | recommended way to call the "unnamed" default method is: | |
688 | ||
689 | =end original | |
690 | ||
691 | $Worksheeets オブジェクトが C<Table1> メソッドまたはプロパティを | |
692 | 持っていない場合です。 | |
693 | この方法はタイプライブラリではメソッドに名前をつけないコレクションの | |
694 | デフォルトメソッドを呼び出すために導入されています。 | |
695 | 「名無しの」デフォルトメソッドを呼び出す推奨される方法は以下の通りです: | |
696 | ||
697 | 193 | my $Sheet = $Worksheets->Invoke('', 'Table1'); |
698 | 194 | |
699 | ||
195 | この特殊な方法はC<use strict 'subs'>の元では使えません。 | |
700 | 196 | |
701 | This special hack is disabled under C<use strict 'subs';>. | |
702 | ||
703 | =end original | |
704 | ||
705 | この特殊な方法は C<use strict 'subs'> の元では使えません。 | |
706 | ||
707 | 197 | =head2 Object methods and properties |
708 | 198 | |
709 | (オブジェクトメソッドとプロパティ | |
199 | new() メソッドによって返されるオブジェクトは、特定のOLEクラスのためのドキュメントで説明されているのと同じ形式で、メソッドを呼び出したり、プロパティを取り出したりするのに使うことができます。 (例えばMicrosoft ExcelドキュメントはOLEアクセスのために公開されているプロパティやメソッドを持ったオブジェクト階層について説明しています。) | |
710 | 200 | |
711 | ||
201 | メソッド呼出しでのオプションのパラメータはC<undef>をプレースホルダとして使うことによって省略することができます。 オプションのパラメータの順序はOLEサーバー・アプリケーションの後のバージョンでは変更されてしまうかもしれないので、よりよい方法は名前付き引数を使うことです。 名前付きパラメータはハッシュへのリファレンスをメソッド呼出しのへの最後のパラメータとして指定することでできます。 | |
712 | 202 | |
713 | ||
203 | プロパティはハッシュの書き方を使って取得、設定するすることができ、メソッドは通常のperlメソッド呼出しの書き方で呼び出すことができます。 C<keys>関数とC<each>関数はオブジェクトのプロパティを列挙するために使うことができます。 | |
714 | ||
204 | プロパティは常に書込可能そして、読込可能でさえあるわけではないことに注意してください(時には未定義である間は読み込んだときに例外を起こすこともあります)。 | |
715 | in the documentation for the particular OLE class (eg. Microsoft | |
716 | Excel documentation describes the object hierarchy along with the | |
717 | properties and methods exposed for OLE access). | |
718 | 205 | |
719 | ||
206 | もしメソッドやプロパティが埋め込まれたOLEオブジェクトを返すのであれば、メソッドとプロパティ・アクセスは以下の例にあるようにチェーンされます。 | |
720 | 207 | |
721 | new() メソッドによって返されるオブジェクトは、特定の OLE クラスのための | |
722 | ドキュメントで説明されているのと同じ形式で、メソッドを呼び出したり、 | |
723 | プロパティを取り出したりするのに使えます。 | |
724 | (例えば Microsoft Excel ドキュメントは OLE アクセスのために公開されている | |
725 | プロパティやメソッドを持ったオブジェクト階層について説明しています)。 | |
726 | ||
727 | =begin original | |
728 | ||
729 | Optional parameters on method calls can be omitted by using C<undef> | |
730 | as a placeholder. A better way is to use named arguments, as the | |
731 | order of optional parameters may change in later versions of the OLE | |
732 | server application. Named parameters can be specified in a reference | |
733 | to a hash as the last parameter to a method call. | |
734 | ||
735 | =end original | |
736 | ||
737 | メソッド呼び出しでのオプションのパラメータは C<undef> をプレースホルダとして | |
738 | 使うことによって省略できます。 | |
739 | オプションのパラメータの順序は OLE サーバーアプリケーションの後の | |
740 | バージョンでは変更されてしまうかもしれないので、よりよい方法は名前付き | |
741 | 引数を使うことです。 | |
742 | 名前付きパラメータはハッシュへのリファレンスをメソッド呼び出しのへの | |
743 | 最後のパラメータとして指定することでできます。 | |
744 | ||
745 | =begin original | |
746 | ||
747 | Properties can be retrieved or set using hash syntax, while methods | |
748 | can be invoked with the usual perl method call syntax. The C<keys> | |
749 | and C<each> functions can be used to enumerate an object's properties. | |
750 | Beware that a property is not always writable or even readable (sometimes | |
751 | raising exceptions when read while being undefined). | |
752 | ||
753 | =end original | |
754 | ||
755 | プロパティはハッシュの書き方を使って取得、設定できます。 | |
756 | メソッドは通常のperlメソッド呼び出しの書き方で呼び出すことができます。 | |
757 | C<keys> と C<each> 関数はオブジェクトのプロパティを列挙するために | |
758 | 使えます。 | |
759 | プロパティは常に書込可能そして、読込可能でさえあるわけではないことに | |
760 | 注意してください | |
761 | (時には未定義である間は読み込んだときに例外を起こすこともあります)。 | |
762 | ||
763 | =begin original | |
764 | ||
765 | If a method or property returns an embedded OLE object, method | |
766 | and property access can be chained as shown in the examples below. | |
767 | ||
768 | =end original | |
769 | ||
770 | もしメソッドやプロパティが埋め込まれた OLE オブジェクトを返すのであれば、 | |
771 | メソッドとプロパティアクセスは以下の例にあるようにチェーンされます。 | |
772 | ||
773 | 208 | =head2 Functions |
774 | 209 | |
775 | (関数) | |
776 | ||
777 | =begin original | |
778 | ||
779 | The following functions are not exported by default. | |
780 | ||
781 | =end original | |
782 | ||
783 | 210 | 以下の関数はデフォルトではエクスポートされません。 |
784 | 211 | |
785 | 212 | =over 8 |
786 | 213 | |
787 | 214 | =item HRESULT(ERROR) |
788 | 215 | |
789 | ||
216 | HRESULT() 関数は符号なしの数値を符号付きのOLEによって内部的に使われるようなHRESULTエラー値に変換します。 これはPerlが全ての16進数定数を符号なしとして扱うために必要です。 最後のOLE関数が"Member not found'' (0x80020003)"を返したかどうかをチェックしたい場合は、以下のようにすることができます: | |
790 | 217 | |
791 | The HRESULT() function converts an unsigned number into a signed HRESULT | |
792 | error value as used by OLE internally. This is necessary because Perl | |
793 | treats all hexadecimal constants as unsigned. To check if the last OLE | |
794 | function returned "Member not found" (0x80020003) you can write: | |
795 | ||
796 | =end original | |
797 | ||
798 | HRESULT() 関数は符号なしの数値を符号付きの OLE によって内部的に使われるような | |
799 | HRESULT エラー値に変換します。 | |
800 | これは Perl が全ての 16 進数定数を符号なしとして扱うために必要です。 | |
801 | 最後の OLE 関数が "Member not found" (0x80020003) を返したかどうかを | |
802 | チェックしたければ、以下のようにすることができます: | |
803 | ||
804 | 218 | if (Win32::OLE->LastError == HRESULT(0x80020003)) { |
805 | # | |
219 | # ここにエラー処理を書く | |
806 | 220 | } |
807 | 221 | |
808 | 222 | =item in(COLLECTION) |
809 | 223 | |
810 | ||
224 | もしCOLLECTION がOLEコレクンション・オブジェクトであれば、C<in $COLLECTION> は、そのコレクションのすべての要素のリストを返します。 これはC<Win32::OLE::Enum->All($COLLECTION)>のショートカットです。 これは一般的にC<foreach>ループで使われます: | |
811 | 225 | |
812 | If COLLECTION is an OLE collection object then C<in $COLLECTION> | |
813 | returns a list of all members of the collection. This is a shortcut | |
814 | for C<Win32::OLE::Enum->All($COLLECTION)>. It is most commonly used in | |
815 | a C<foreach> loop: | |
816 | ||
817 | =end original | |
818 | ||
819 | もし COLLECTION が OLE コレクンションオブジェクトであれば、 | |
820 | C<in $COLLECTION> は、そのコレクションのすべての要素のリストを返します。 | |
821 | これは C<Win32::OLE::Enum-E<gt>All($COLLECTION)> のショートカットです。 | |
822 | これは一般的に C<foreach> ループで使われます: | |
823 | ||
824 | 226 | foreach my $value (in $collection) { |
825 | # | |
227 | # $valueを使って何かする | |
826 | 228 | } |
827 | 229 | |
828 | 230 | =item valof(OBJECT) |
829 | 231 | |
830 | ||
232 | Perl OLE の通常の代入は、単にその OLE オブジェクトへの新しいリファレンスを作ります。 valof() 関数は明示的にオブジェクト(デフォルト・メソッドを通じた)とオブジェトの値を区別します。 | |
831 | 233 | |
832 | Normal assignment of Perl OLE objects creates just another reference | |
833 | to the OLE object. The valof() function explictly dereferences the | |
834 | object (through the default method) and returns the value of the object. | |
835 | ||
836 | =end original | |
837 | ||
838 | Perl OLE オブジェクトの通常の代入は他の OLE オブジェクトへの他の | |
839 | リファレンスを作成します。 | |
840 | valof() 関数は明示的にオブジェクト(デフォルトメソッドを通じた)と | |
841 | オブジェクトの値を区別します。 | |
842 | ||
843 | 234 | my $RefOf = $Object; |
844 | 235 | my $ValOf = valof $Object; |
845 | 236 | $Object->{Value} = $NewValue; |
846 | 237 | |
847 | ||
238 | ここで$ValOfはまだ古い値を持っているのに、$RefOf はまだ$Objectへのリファレンスなので、$NewValue を解決します。 | |
848 | 239 | |
849 | ||
240 | valof() 関数はWin32::OLE::VariantオブジェクトをPerl変数に変換するためにも使うことができます。 | |
850 | resolve to the $NewValue because it is still a reference to | |
851 | $Object. | |
852 | 241 | |
853 | =end original | |
854 | ||
855 | いまや $ValOf はまだ古い値を持っているのに、$RefOf はまだ $Object への | |
856 | リファレンスなので、$NewValue を解決します。 | |
857 | ||
858 | =begin original | |
859 | ||
860 | The valof() function can also be used to convert Win32::OLE::Variant | |
861 | objects to Perl values. | |
862 | ||
863 | =end original | |
864 | ||
865 | valof() 関数は Win32::OLE::Variant オブジェクトを Perl 変数に | |
866 | 変換するためにも使えます。 | |
867 | ||
868 | 242 | =item with(OBJECT, PROPERTYNAME => VALUE, ...) |
869 | 243 | |
870 | = | |
244 | この関数はあるオブジェクトの複数のプロパティを設定するための簡単な方法を提供します。 これは後ろについている各組合わせに対してC<$OBJECT->{PROPERTYNAME} = $VALUE> を繰り返しおこないます。 | |
871 | 245 | |
872 | This function provides a concise way to set the values of multiple | |
873 | properties of an object. It iterates over its arguments doing | |
874 | C<$OBJECT->{PROPERTYNAME} = $VALUE> on each trailing pair. | |
875 | ||
876 | =end original | |
877 | ||
878 | この関数はあるオブジェクトの複数のプロパティを設定するための簡単な方法を | |
879 | 提供します。 | |
880 | これは後ろについている各組合わせに対して | |
881 | C<$OBJECT-E<gt>{PROPERTYNAME} = $VALUE> を繰り返しおこないます。 | |
882 | ||
883 | 246 | =back |
884 | 247 | |
885 | 248 | =head2 Overloading |
886 | 249 | |
887 | ||
250 | Win32::OLEオブジェクトはブール値、数値、文字列コンテキストで使われたときにはいつでも、自動的にそれらの値に変換するためにオーバーロードすることができます。 これはデフォルトでは有効ではありません。 OVERLOAD疑似エクスポートを通して要求する必要があります: | |
888 | 251 | |
889 | =begin original | |
890 | ||
891 | The Win32::OLE objects can be overloaded to automatically convert to | |
892 | their values whenever they are used in a bool, numeric or string | |
893 | context. This is not enabled by default. You have to request it | |
894 | through the OVERLOAD pseudoexport: | |
895 | ||
896 | =end original | |
897 | ||
898 | Win32::OLE オブジェクトはブール値、数値、文字列コンテキストで | |
899 | 使われたときにはいつでも、自動的にそれらの値に変換するために | |
900 | オーバーロードできます。 | |
901 | これはデフォルトでは可能ではありません。 | |
902 | OVERLOAD 疑似エクスポートを通して要求する必要があります: | |
903 | ||
904 | 252 | use Win32::OLE qw(in valof with OVERLOAD); |
905 | 253 | |
906 | ||
254 | 例えばデバッグのためにC<overload::StrVal()>メソッドを使って、元のオブジェクト(C<Win32::OLE=0xDEADBEEF>) の文字列表現を取得することもできます: | |
907 | 255 | |
908 | You can still get the original string representation of an object | |
909 | (C<Win32::OLE=0xDEADBEEF>), e.g. for debugging, by using the | |
910 | C<overload::StrVal()> method: | |
911 | ||
912 | =end original | |
913 | ||
914 | 例えばデバッグのために C<overload::StrVal()> メソッドを使って、元の | |
915 | オブジェクトの文字列表現 (C<Win32::OLE=0xDEADBEEF>) を取得することもできます: | |
916 | ||
917 | 256 | print overload::StrVal($object), "\n"; |
918 | 257 | |
919 | ||
258 | C<OVERLOAD>はグローバルな設定であることに注意してください。 もしなんらかのモジュールがWin32::OLEオーバーロードを可能にすると、それはどこでも有効です。 | |
920 | 259 | |
921 | Please note that C<OVERLOAD> is a global setting. If any module enables | |
922 | Win32::OLE overloading then it's active everywhere. | |
923 | ||
924 | =end original | |
925 | ||
926 | C<OVERLOAD> はグローバルな設定であることに注意してください。 | |
927 | もしなんらかのモジュールが Win32::OLE オーバーロードを可能にすると、 | |
928 | それはいつでも有効です。 | |
929 | ||
930 | 260 | =head2 Events |
931 | 261 | |
932 | ||
262 | Win32::OLEモジュールは今はB<アルファ>レベルのイベント・サポートを持っています。 このサポートはPerlが単一スレッド分離レベルで実行しているときにだけ利用できます。 これはC<EVENTS>疑似インポートを使うことによって、とても簡単に保証することができます: | |
933 | 263 | |
934 | =begin original | |
935 | ||
936 | The Win32::OLE module now contains B<ALPHA> level event support. This | |
937 | support is only available when Perl is running in a single threaded | |
938 | apartment. This can most easily be assured by using the C<EVENTS> | |
939 | pseudo-import: | |
940 | ||
941 | =end original | |
942 | ||
943 | Win32::OLE モジュールは今は B<アルファ> レベルのイベントサポートを | |
944 | 持っています。 | |
945 | このサポートは Perl がシングルスレッド分離レベルで実行しているときにだけ | |
946 | 利用できます。 | |
947 | これはとても簡単に C<EVENTS> 疑似インポートを使うことによって、 | |
948 | 保証することができます: | |
949 | ||
950 | 264 | use Win32::OLE qw(EVENTS); |
951 | 265 | |
952 | =begin original | |
953 | ||
954 | which implicitly does something like: | |
955 | ||
956 | =end original | |
957 | ||
958 | 266 | これは暗黙のうちに以下のようなことをしています: |
959 | 267 | |
960 | 268 | use Win32::OLE; |
961 | 269 | Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE); |
962 | 270 | |
963 | ||
271 | 現在のOLEイベントへのインターフェースは実験的なものであると考えられ、変更されやすいものです。 通常のOLEアプリケーションでは予定通りに機能しますが、OLE制御イベントはまだうまく機能していないようです。 | |
964 | 272 | |
965 | ||
273 | イベントはWin32::OLE->WithEvents() クラス・メソッドを通して、OLEオブジェクトのために明示的に可能にされなければなりません。 Win32::OLEモジュールはオブジェクトのデフォルト・イベント・ソースを判定するために IProvideClassInfo2 インターフェースを利用しています。 このインターフェースがサポートされていなければ、ユーザは WithEvents()メソッドで明示的にイベント・ソースの名前を指定しなければなりません。 オブジェクトのクラス名を3番目のパラメータとして指定することも可能です。 この場合、Win32::OLEは、このCOCLASSのためのデフォルト・ソース・インターフェースを見つけようとします。 | |
966 | and is subject to change. It works as expected for normal OLE | |
967 | applications, but OLE control events often don't seem to work yet. | |
968 | 274 | |
969 | ||
275 | Win32::OLE->WithEvents() へのHANDLER引数はCODEリファレンスまたはパッケージ名のどちらかにすることができます。 前者の場合、すべてのイベントはこの特定の関数を呼び出します。 この関数への最初の 2 つの引数はOBJECTそのものとイベントの名前になります。 残りの引数はイベントによります: | |
970 | 276 | |
971 | 現在の OLE イベントへのインターフェースは実験的なものであると考えられ、 | |
972 | 変更されやすいものです。 | |
973 | 通常の OLE アプリケーションでは予定通りに機能しますが、OLE 制御イベントは | |
974 | まだうまく機能していないようです。 | |
975 | ||
976 | =begin original | |
977 | ||
978 | Events must be enabled explicitly for an OLE object through the | |
979 | Win32::OLE->WithEvents() class method. The Win32::OLE module uses the | |
980 | IProvideClassInfo2 interface to determine the default event source of | |
981 | the object. If this interface is not supported, then the user must | |
982 | specify the name of the event source explicitly in the WithEvents() | |
983 | method call. It is also possible to specify the class name of the | |
984 | object as the third parameter. In this case Win32::OLE will try to | |
985 | look up the default source interface for this COCLASS. | |
986 | ||
987 | =end original | |
988 | ||
989 | イベントは Win32::OLE->WithEvents() クラスメソッドを通して、 | |
990 | OLE オブジェクトのために明示的に可能にされなければなりません。 | |
991 | Win32::OLE モジュールはオブジェクトのデフォルトイベントソースを | |
992 | 判定するために IProvideClassInfo2 インターフェースを利用しています。 | |
993 | このインターフェースがサポートされていなければ、ユーザは | |
994 | WithEvents() メソッドで明示的にイベントソースの名前を | |
995 | 指定しなければなりません。 | |
996 | オブジェクトのクラス名を 3 番目のパラメータとして指定することも可能です。 | |
997 | この場合、Win32::OLE は、この COCLASS のための | |
998 | デフォルトソースインターフェースを見つけようとします。 | |
999 | ||
1000 | =begin original | |
1001 | ||
1002 | The HANDLER argument to Win32::OLE->WithEvents() can either be a CODE | |
1003 | reference or a package name. In the first case, all events will invoke | |
1004 | this particular function. The first two arguments to this function will | |
1005 | be the OBJECT itself and the name of the event. The remaining arguments | |
1006 | will be event specific. | |
1007 | ||
1008 | =end original | |
1009 | ||
1010 | Win32::OLE->WithEvents() への HANDLER 引数は CODE リファレンスまたは | |
1011 | パッケージ名のどちらかにすることができます。 | |
1012 | 前者の場合、すべてのイベントはこの特定の関数を呼び出します。 | |
1013 | この関数への最初の二つの引数は OBJECT そのものとイベントの名前になります。 | |
1014 | 残りの引数はイベントによります: | |
1015 | ||
1016 | 277 | sub Event { |
1017 | 278 | my ($Obj,$Event,@Args) = @_; |
1018 | 279 | print "Event triggered: '$Event'\n"; |
1019 | 280 | } |
1020 | 281 | Win32::OLE->WithEvents($Obj, \&Event); |
1021 | 282 | |
1022 | ||
283 | またはHANDLER引数でパッケージ名を指定することができます。 OBJECTがイベントを発火したとき、Win32::OLEは、このパッケージでイベントと同じ名前の関数を見つけようとします。 この関数はOBJECTを最初の引数とし、イベント特有のパラメータが後ろについて呼び出されます: | |
1023 | 284 | |
1024 | Alternatively the HANDLER argument can specify a package name. When the | |
1025 | OBJECT fires an event, Win32::OLE will try to find a function of the same | |
1026 | name as the event in this package. This function will be called with the | |
1027 | OBJECT as the first argument followed again by the event specific parameters: | |
1028 | ||
1029 | =end original | |
1030 | ||
1031 | 代わりに HANDLER 引数がパッケージ名を指定できます。 | |
1032 | OBJECT がイベントを発火したとき、Win32::OLE は、このパッケージでイベントと | |
1033 | 同じ名前の関数を見つけようとします。 | |
1034 | この関数は OBJECT を最初の引数とし、イベント特有のパラメータが後ろについて | |
1035 | 呼び出されます: | |
1036 | ||
1037 | 285 | package MyEvents; |
1038 | 286 | sub EventName1 { |
1039 | 287 | my ($Obj,@Args) = @_; |
1040 | 288 | print "EventName1 event triggered\n"; |
1041 | 289 | } |
1042 | 290 | |
1043 | 291 | package main; |
1044 | 292 | Win32::OLE->WithEvents($Obj, 'MyEvents', 'IEventInterface'); |
1045 | 293 | |
1046 | ||
294 | Win32::OLEがイベント名の関数を見つけなければ、何も起こりません。 | |
1047 | 295 | |
1048 | I | |
296 | I<参照渡しで>渡されたイベント・パラメータは特別に扱われます。 これらは対応するPerlデータ型に変換されず、 Win32::OLE::Variantオブジェクトとして渡されます。 これらのオブジェクトにPut()メソッドの助けを借りて新しい値を代入することができます。 この値はイベント関数が戻るとき、オブジェクトに戻されます: | |
1049 | happens. | |
1050 | 297 | |
1051 | =end original | |
1052 | ||
1053 | Win32::OLE がイベント名の関数を見つけなければ、何も起こりません。 | |
1054 | ||
1055 | ||
1056 | =begin original | |
1057 | ||
1058 | Event parameters passed I<by reference> are handled specially. They are not | |
1059 | converted to the corresponding Perl datatype but passed as Win32::OLE::Variant | |
1060 | objects. You can assign a new value to these objects with the help of the | |
1061 | Put() method. This value will be passed back to the object when the event | |
1062 | function returns: | |
1063 | ||
1064 | =end original | |
1065 | ||
1066 | I<リファレンスによって> 渡されたイベントパラメータは特別に扱われます。 | |
1067 | これらは対応する Perl データ型に変換されず、 | |
1068 | Win32::OLE::Variant オブジェクトとして渡されます。 | |
1069 | これらのオブジェクトに Put() メソッドの助けを借りて新しい値を | |
1070 | 代入できます。 | |
1071 | この値はイベント関数が戻るとき、オブジェクトに戻されます: | |
1072 | ||
1073 | 298 | package MyEvents; |
1074 | 299 | sub BeforeClose { |
1075 | 300 | my ($self,$Cancel) = @_; |
1076 | 301 | $Cancel->Put(1) unless $MayClose; |
1077 | 302 | } |
1078 | 303 | |
1079 | ||
304 | $Cancelへの直接の代入は元の値に何も影響を与えないので、オブジェクトにアクションを閉じるのを中止させるように命令しません。 | |
1080 | 305 | |
1081 | Direct assignment to $Cancel would have no effect on the original value and | |
1082 | would therefore not command the object to abort the closing action. | |
1083 | ||
1084 | =end original | |
1085 | ||
1086 | $Cancel への直接の代入は元の値に何も影響を与えません。 | |
1087 | そしてこのためオブジェクトにアクションを閉じるのを中止させるように命令しません。 | |
1088 | ||
1089 | 306 | =head2 Module Options |
1090 | 307 | |
1091 | ||
308 | 以下のモジュール・オプションはC<Win32::OLE->Option>クラスメソッドでアクセス、変更することができます。 Win32::OLEモジュールの始めのころのバージョンでは、これらのオプションはクラス変数として直接操作されました。 この方法は現在では非推奨です。 | |
1092 | 309 | |
1093 | =begin original | |
1094 | ||
1095 | The following module options can be accessed and modified with the | |
1096 | C<Win32::OLE->Option> class method. In earlier versions of the Win32::OLE | |
1097 | module these options were manipulated directly as class variables. This | |
1098 | practice is now deprecated. | |
1099 | ||
1100 | =end original | |
1101 | ||
1102 | 以下のモジュールオプションは C<Win32::OLE-E<gt>Option> クラスメソッドで | |
1103 | アクセス、変更できます。 | |
1104 | Win32::OLE モジュールの始めのころのバージョンでは、これらのオプションは | |
1105 | クラス変数として直接操作されました。 | |
1106 | この実装は今では廃止予定です: | |
1107 | ||
1108 | 310 | =over 8 |
1109 | 311 | |
1110 | 312 | =item CP |
1111 | 313 | |
1112 | ||
314 | この変数はPerl文字列とOLEインターフェースによって使われるUnicode文字列の間のすべての変換によって使われるコードページの決定に使われます。 デフォルトの値はCP_ACPで、これはデフォルトのANSIコードページです。 他に可能な値は、CP_OEMCP, CP_MACCP, CP_UTF7, CP_UTF8です。 これらの定数はデフォルトではエクスポートされません。 | |
1113 | 315 | |
1114 | This variable is used to determine the codepage used by all | |
1115 | translations between Perl strings and Unicode strings used by the OLE | |
1116 | interface. The default value is CP_ACP, which is the default ANSI | |
1117 | codepage. Other possible values are CP_OEMCP, CP_MACCP, CP_UTF7 and | |
1118 | CP_UTF8. These constants are not exported by default. | |
1119 | ||
1120 | =end original | |
1121 | ||
1122 | この変数は Perl 文字列と OLE インターフェースによって使われる Unicode 文字列の | |
1123 | 間のすべての変換によって使われるコードページです。 | |
1124 | デフォルトの値は CP_ACP です。 | |
1125 | これはデフォルトの ANSI コードページです。 | |
1126 | 他に可能な値は、CP_OEMCP, CP_MACCP, CP_UTF7, CP_UTF8 です。 | |
1127 | これらの定数はデフォルトではエクスポートされません。 | |
1128 | ||
1129 | 316 | =item LCID |
1130 | 317 | |
1131 | ||
318 | この変数は全てのOLE呼出しに使われるロケール識別子を制御します。 | |
319 | これはデフォルトではLOCALE_NEUTRALに設定されます。 他のロケール関連情報についてはL<Win32::OLE::NLS> モジュールをチェックしてください。 | |
1132 | 320 | |
1133 | ||
321 | =item Variant | |
1134 | It is set to LOCALE_NEUTRAL by default. Please check the | |
1135 | L<Win32::OLE::NLS> module for other locale related information. | |
1136 | 322 | |
1137 | ||
323 | このオプションは、メソッド呼び出しやプロパティアクセサが VT_CY 型と VT_DECIMAL 型を返すときにどのように返すかを制御します。 デフォルトでは VT_CY 型は文字列に変換され、 VT_DECIMAL 型は浮動小数点数に変換されます。 C<Variant> オプションが有効の場合、 | |
324 | これらの値は VT_DATE 型や VT_ERROR と同様に Win32::OLE::Variant 型で返されます。 Win32::OLE::Variant モジュールも読み込まれている場合、文字列と数値のコンテキストでは全ての値は以前と同じ振る舞いをするはずです。 | |
1138 | 325 | |
1139 | ||
326 | C<Variant> の振る舞いがデフォルトになっていない唯一の理由は、すでにあるプログラムを壊す可能性のある互換性の無い変更だからです。 | |
1140 | それはデフォルトでは LOCALE_NEUTRAL に設定されます。 | |
1141 | 他のロケール関連情報については L<Win32::OLE::NLS> モジュールを | |
1142 | チェックしてください。 | |
1143 | 327 | |
1144 | 328 | =item Warn |
1145 | 329 | |
1146 | ||
330 | この変数はエラーが発生したときのWin32::OLEモジュールの動きを決定します。 有効な値は以下の通りです: | |
1147 | 331 | |
1148 | ||
332 | 0 エラーを無視; undefを返す | |
1149 | ||
333 | 1 $^Wが設定されていれば(-w オプション)Carp::carp | |
334 | 2 常にCarp::carp | |
335 | 3 Carp::croak | |
1150 | 336 | |
1151 | ||
337 | (Carp行/モジュール情報を無し)エラー番号とメッセージはC<Win32::OLE->LastError> クラス・メソッドを通して利用することができます。 | |
1152 | 338 | |
1153 | ||
339 | またはWarnオプションにCODEリファレンスを設定することもできます。 例えば: | |
1154 | 適切な値は以下の通りです: | |
1155 | 340 | |
1156 | =begin original | |
1157 | ||
1158 | 0 Ignore error, return undef | |
1159 | 1 Carp::carp if $^W is set (-w option) | |
1160 | 2 always Carp::carp | |
1161 | 3 Carp::croak | |
1162 | ||
1163 | =end original | |
1164 | ||
1165 | 0 エラーを無視して undef を返す | |
1166 | 1 $^W が設定されていれば(-w オプション)Carp::carp | |
1167 | 2 常に Carp::carp | |
1168 | 3 Carp::croak | |
1169 | ||
1170 | =begin original | |
1171 | ||
1172 | The error number and message (without Carp line/module info) are | |
1173 | available through the C<Win32::OLE->LastError> class method. | |
1174 | ||
1175 | =end original | |
1176 | ||
1177 | エラー番号とメッセージ(Carp 行/モジュール情報は無し)は | |
1178 | C<Win32::OLE->LastError> クラスメソッドを通して利用できます。 | |
1179 | ||
1180 | =begin original | |
1181 | ||
1182 | Alternatively the Warn option can be set to a CODE reference. E.g. | |
1183 | ||
1184 | =end original | |
1185 | ||
1186 | 代わりに CODE リファレンスに Warn オプションを設定できます。 | |
1187 | 例えば | |
1188 | ||
1189 | 341 | Win32::OLE->Option(Warn => 3); |
1190 | 342 | |
1191 | ||
343 | これは以下のものと同じです: | |
1192 | 344 | |
1193 | is equivalent to | |
1194 | ||
1195 | =end original | |
1196 | ||
1197 | これは以下のものと同じです。 | |
1198 | ||
1199 | 345 | Win32::OLE->Option(Warn => \&Carp::croak); |
1200 | 346 | |
1201 | ||
347 | これはVisualBasicのC<On Error Goto Label>構造をエミュレートするために使うことさえもできます: | |
1202 | 348 | |
1203 | This can even be used to emulate the VisualBasic C<On Error Goto | |
1204 | Label> construct: | |
1205 | ||
1206 | =end original | |
1207 | ||
1208 | これは VisualBasic の C<On Error Goto Label> 構造をエミュレートするために | |
1209 | 使うことさえもできます: | |
1210 | ||
1211 | 349 | Win32::OLE->Option(Warn => sub {goto CheckError}); |
1212 | # | |
350 | # ここに通常のOLEコードを書く | |
1213 | 351 | |
1214 | 352 | CheckError: |
1215 | # | |
353 | # ここにエラー処理コードを書く | |
1216 | 354 | |
1217 | 355 | =item _NewEnum |
1218 | 356 | |
1219 | ||
357 | このオプションはコレクション・オブジェクトのための追加の列挙子のサポートを可能にします。 C<_NewEnum>オプションが設定されたとき、すべてのコレクションは1つの追加のプロパティである C<_NewEnum>を受け取ります。 このプロパティの値はコレクションのすべての要素が入った配列へのリファレンスになります。 このオプションはC<Data::Dumper>やオブジェクト・ツリー・ブラウザのような自動的なツリー構造横断プログラムと一緒に使うときに便利でしょう。 このオプションの値は1(有効)または0(無効、デフォルト)でなければなりません。 | |
1220 | 358 | |
1221 | This option enables additional enumeration support for collection | |
1222 | objects. When the C<_NewEnum> option is set, all collections will | |
1223 | receive one additional property: C<_NewEnum>. The value of this | |
1224 | property will be a reference to an array containing all the elements | |
1225 | of the collection. This option can be useful when used in conjunction | |
1226 | with an automatic tree traversal program, like C<Data::Dumper> or an | |
1227 | object tree browser. The value of this option should be either 1 | |
1228 | (enabled) or 0 (disabled, default). | |
1229 | ||
1230 | =end original | |
1231 | ||
1232 | このオプションはコレクションオブジェクトのための追加の列挙子のサポートを | |
1233 | 可能にします。 | |
1234 | _C<NewEnum> オプションが設定されたとき、すべてのコレクションは一つの | |
1235 | 追加のプロパティ: C<_NewEnum> を受け取ります。 | |
1236 | このプロパティの値はコレクションのすべての要素が入った配列への | |
1237 | リファレンスになります。 | |
1238 | このオプションは C<Data::Dumper> やオブジェクトツリーブラウザのような | |
1239 | 自動的なツリー構造横断プログラムと一緒に使うときに便利でしょう。 | |
1240 | このオプションの値は1(有効)または0(無効、デフォルト)でなければなりません。 | |
1241 | ||
1242 | 359 | Win32::OLE->Option(_NewEnum => 1); |
1243 | 360 | # ... |
1244 | 361 | my @sheets = @{$Excel->Worksheets->{_NewEnum}}; |
1245 | 362 | |
1246 | ||
363 | 通常のアプリケーション・コードでは、これは以下のように書いた方がよいでしょう: | |
1247 | 364 | |
1248 | In normal application code, this would be better written as: | |
1249 | ||
1250 | =end original | |
1251 | ||
1252 | 通常のアプリケーションコードでは、これは以下のように書いた方がよいでしょう: | |
1253 | ||
1254 | 365 | use Win32::OLE qw(in); |
1255 | 366 | # ... |
1256 | 367 | my @sheets = in $Excel->Worksheets; |
1257 | 368 | |
1258 | 369 | =item _Unique |
1259 | 370 | |
1260 | ||
371 | C<_Unique> オプションはWin32::OLEがネイティブのCOM/OLEオブジェクトと1対1のマッピングを維持することを保証します。 このオプションがないと、元になっている同じCOMオブジェクトのために異なるWin32::OLEオブジェクトを取得し、同じプロパティを重複して問い合わせることになりかねません。 | |
1261 | 372 | |
1262 | ||
373 | ユニーク・プロキシーを使うと、特定のノードを既に訪れたことを理解するためのツリー構造横断アルゴリズムは簡単になります。 このオプションは高くつきます: Win32::OLEがすべての存在するオブジェクトと対応するプロキシーのグローバルなハッシュと維持しなければならなりません。 オブジェクトがプロセスの外側に、あるいは異なるコンピュータにあったりしたら、COMオブジェクトの識別子チェックも同様に高価になりかねません。 このためこのオプションはプログラムがデバッガで実行されるのでなければ、デフォルトではオフです。 | |
1263 | one-to-one mapping between Win32::OLE objects and the native COM/OLE | |
1264 | objects. Without this option, you can query the same property twice | |
1265 | and get two different Win32::OLE objects for the same underlying COM | |
1266 | object. | |
1267 | 374 | |
1268 | ||
375 | 残念ながら、このオプションは常に助けになるわけではありません。 いくつかのプログラムは同じプロパティであってさえも、何度も聞くと新しいCOMオブジェクトを返すことがあります(特にコレクションについては)。 この場合、これらのオブジェクトが事実上同じであると見分けるためにWin32::OLEができることは何もありません(というのもそれはCOMレベルではないからです)。 | |
1269 | 376 | |
1270 | C<_Unique> オプションは | |
377 | C<_Unique> オプションは1(有効)または0(無効、デフォルト)のどちらかに設定できます。 | |
1271 | 1 対 1 のマッピングを維持することを保証します。 | |
1272 | このオプションがないと、元になっている同じ COM オブジェクトのために異なる | |
1273 | Win32::OLE オブジェクトを取得し、同じプロパティを重複して | |
1274 | 問い合わせることになりかねません。 | |
1275 | 378 | |
1276 | =begin original | |
1277 | ||
1278 | Using a unique proxy makes life easier for tree traversal algorithms | |
1279 | to recognize they already visited a particular node. This option | |
1280 | comes at a price: Win32::OLE has to maintain a global hash of all | |
1281 | outstanding objects and their corresponding proxies. Identity checks | |
1282 | on COM objects can also be expensive if the objects reside | |
1283 | out-of-process or even on a different computer. Therefore this option | |
1284 | is off by default unless the program is being run in the debugger. | |
1285 | ||
1286 | =end original | |
1287 | ||
1288 | ユニークプロキシーを使うと、特定のノードを既に訪れたことを | |
1289 | 理解するためのツリー構造横断アルゴリズムは簡単になります。 | |
1290 | このオプションは大きな犠牲を払います: Win32::OLE がすべての存在する | |
1291 | オブジェクトと対応するプロキシーのグローバルなハッシュと | |
1292 | 維持しなければなりません。 | |
1293 | オブジェクトがプロセスの外側に、あるいは異なるコンピュータにあったりしたら、 | |
1294 | COM オブジェクトの識別子チェックも同様に高価になりかねません。 | |
1295 | このためこのオプションはプログラムがデバッガで実行されるのでなければ、 | |
1296 | デフォルトではオフです。 | |
1297 | ||
1298 | =begin original | |
1299 | ||
1300 | Unfortunately, this option doesn't always help. Some programs will | |
1301 | return new COM objects for even the same property when asked for it | |
1302 | multiple times (especially for collections). In this case, there is | |
1303 | nothing Win32::OLE can do to detect that these objects are in fact | |
1304 | identical (because they aren't at the COM level). | |
1305 | ||
1306 | =end original | |
1307 | ||
1308 | 残念ながら、このオプションは常に助けにはなりません。 | |
1309 | いくつかのプログラムは同じプロパティであってさえも、何度も聞くと新しい | |
1310 | COM オブジェクトを返すことがあります(特にコレクションについては)。 | |
1311 | この場合、これらのオブジェクトが事実上同じであると見分けるために | |
1312 | Win32::OLE ができることは何もありません(というのもそれは COM レベルでは | |
1313 | ないからです)。 | |
1314 | ||
1315 | =begin original | |
1316 | ||
1317 | The C<_Unique> option can be set to either 1 (enabled) or 0 (disabled, | |
1318 | default). | |
1319 | ||
1320 | =end original | |
1321 | ||
1322 | C<_Unique> オプションは1(有効)または0(無効、デフォルト)のどちらかに | |
1323 | 設定できます。 | |
1324 | ||
1325 | 379 | =back |
1326 | 380 | |
1327 | 381 | =head1 EXAMPLES |
1328 | 382 | |
1329 | ||
383 | これは簡単なMicrosoft Excelアプリケーションです。 | |
1330 | 384 | |
1331 | =begin original | |
1332 | ||
1333 | Here is a simple Microsoft Excel application. | |
1334 | ||
1335 | =end original | |
1336 | ||
1337 | これは簡単な Microsoft Excel アプリケーションです。 | |
1338 | ||
1339 | 385 | use Win32::OLE; |
1340 | 386 | |
1341 | 387 | # use existing instance if Excel is already running |
1342 | 388 | eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; |
1343 | 389 | die "Excel not installed" if $@; |
1344 | 390 | unless (defined $ex) { |
1345 | 391 | $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) |
1346 | 392 | or die "Oops, cannot start Excel"; |
1347 | 393 | } |
1348 | 394 | |
1349 | 395 | # get a new workbook |
1350 | 396 | $book = $ex->Workbooks->Add; |
1351 | 397 | |
1352 | 398 | # write to a particular cell |
1353 | 399 | $sheet = $book->Worksheets(1); |
1354 | 400 | $sheet->Cells(1,1)->{Value} = "foo"; |
1355 | 401 | |
1356 | 402 | # write a 2 rows by 3 columns range |
1357 | 403 | $sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ], |
1358 | 404 | [ 42, 'Perl', 3.1415 ]]; |
1359 | 405 | |
1360 | 406 | # print "XyzzyPerl" |
1361 | 407 | $array = $sheet->Range("A8:C9")->{Value}; |
1362 | 408 | for (@$array) { |
1363 | 409 | for (@$_) { |
1364 | 410 | print defined($_) ? "$_|" : "<undef>|"; |
1365 | 411 | } |
1366 | 412 | print "\n"; |
1367 | 413 | } |
1368 | 414 | |
1369 | 415 | # save and exit |
1370 | 416 | $book->SaveAs( 'test.xls' ); |
1371 | 417 | undef $book; |
1372 | 418 | undef $ex; |
1373 | 419 | |
1374 | ||
420 | Win32::OLE->newメソッドでデストラクタが指定されていることに注意してください。 これはPerlプログラムが死んだときでさえも、Excelが適切に終了されることを保証します。 そうでなければExcelのOLEインスタンスが開いたあとで、アプリケーションが死ぬとプロセス・リークになりかねません。 OLEオブジェクトが確実に適切に片づけられるようにするのはモジュール利用者の責任です! | |
1375 | 421 | |
1376 | ||
422 | 以下はVariantデータ型を使った例です。 | |
1377 | that Excel will shutdown properly even if the Perl program dies. Otherwise | |
1378 | there could be a process leak if your application dies after having opened | |
1379 | an OLE instance of Excel. It is the responsibility of the module user to | |
1380 | make sure that all OLE objects are cleaned up properly! | |
1381 | 423 | |
1382 | =end original | |
1383 | ||
1384 | Win32::OLE->new メソッドでデストラクタが指定されていることに | |
1385 | 注意してください。 | |
1386 | これは Perl プログラムが死んだときでさえも、Excel が適切に終了されることを | |
1387 | 保証します。 | |
1388 | そうでなければ Excel の OLE インスタンスが開いたあとで、アプリケーションが | |
1389 | die とプロセスリークになりかねません。 | |
1390 | OLE オブジェクトが確実に適切に片づけられるようにするのはモジュール利用者の | |
1391 | 責任です! | |
1392 | ||
1393 | =begin original | |
1394 | ||
1395 | Here is an example of using Variant data types. | |
1396 | ||
1397 | =end original | |
1398 | ||
1399 | 以下は Variant データ型を使った例です。 | |
1400 | ||
1401 | 424 | use Win32::OLE; |
1402 | 425 | use Win32::OLE::Variant; |
1403 | 426 | $ex = Win32::OLE->new('Excel.Application', \&OleQuit) or die "oops\n"; |
1404 | 427 | $ex->{Visible} = 1; |
1405 | 428 | $ex->Workbooks->Add; |
1406 | 429 | # should generate a warning under -w |
1407 | 430 | $ovR8 = Variant(VT_R8, "3 is a good number"); |
1408 | 431 | $ex->Range("A1")->{Value} = $ovR8; |
1409 | 432 | $ex->Range("A2")->{Value} = Variant(VT_DATE, 'Jan 1,1970'); |
1410 | 433 | |
1411 | 434 | sub OleQuit { |
1412 | 435 | my $self = shift; |
1413 | 436 | $self->Quit; |
1414 | 437 | } |
1415 | 438 | |
1416 | ||
439 | 上記では文字列は"3 is a good number"ではなく、"3"をセルA1に入れます。 セルA2は日付を持ちます: | |
1417 | 440 | |
1418 | ||
441 | 同様に、バイナリ・データでメソッドを呼び出すためには、以下のようにできます: | |
1419 | "3 is a good number". Cell A2 will contain the date. | |
1420 | 442 | |
1421 | =end original | |
1422 | ||
1423 | 上記では文字列は "3 is a good number" ではなく、"3" をセル A1 に入れます。 | |
1424 | セル A2 は日付を持ちます: | |
1425 | ||
1426 | =begin original | |
1427 | ||
1428 | Similarly, to invoke a method with some binary data, you can | |
1429 | do the following: | |
1430 | ||
1431 | =end original | |
1432 | ||
1433 | 同様に、バイナリデータでメソッドを呼び出すためには、以下のようにできます: | |
1434 | ||
1435 | 443 | $obj->Method( Variant(VT_UI1, "foo\000b\001a\002r") ); |
1436 | 444 | |
1437 | ||
445 | 以下のものは基本的にnew()とDESTROY()を除いたすべてを委任するラッパー・クラスです。 下記のラッパー・クラスは、アプリケーションが適切なクリーンアップなしに死ぬことが免れないときに、接続を適切に終らせるもう1つの方法です。 あなた自身のラッパーは、独自に確証したいメソッドをオーバーライドするといったように、おそらくあなたの扱いたい特定のOLEオブジェクトにより特化したようなことをするでしょう。 | |
1438 | 446 | |
1439 | Here is a wrapper class that basically delegates everything but | |
1440 | new() and DESTROY(). The wrapper class shown here is another way to | |
1441 | properly shut down connections if your application is liable to die | |
1442 | without proper cleanup. Your own wrappers will probably do something | |
1443 | more specific to the particular OLE object you may be dealing with, | |
1444 | like overriding the methods that you may wish to enhance with your | |
1445 | own. | |
1446 | ||
1447 | =end original | |
1448 | ||
1449 | 以下のものは基本的に new() と DESTROY() を除いたすべてを委任する | |
1450 | ラッパークラスです。 | |
1451 | 下記のラッパークラスは、アプリケーションが適切なクリーンアップなしに | |
1452 | 死ぬことが免れないときに、接続を適切に終らせるもう一つの方法です。 | |
1453 | あなた自身のラッパーは、独自に確証したいメソッドを | |
1454 | オーバーライドするといったように、おそらくあなたの扱いたい特定の | |
1455 | OLE オブジェクトにより特化したようなことをするでしょう。 | |
1456 | ||
1457 | 447 | package Excel; |
1458 | 448 | use Win32::OLE; |
1459 | 449 | |
1460 | 450 | sub new { |
1461 | 451 | my $s = {}; |
1462 | 452 | if ($s->{Ex} = Win32::OLE->new('Excel.Application')) { |
1463 | 453 | return bless $s, shift; |
1464 | 454 | } |
1465 | 455 | return undef; |
1466 | 456 | } |
1467 | 457 | |
1468 | 458 | sub DESTROY { |
1469 | 459 | my $s = shift; |
1470 | 460 | if (exists $s->{Ex}) { |
1471 | 461 | print "# closing connection\n"; |
1472 | 462 | $s->{Ex}->Quit; |
1473 | 463 | return undef; |
1474 | 464 | } |
1475 | 465 | } |
1476 | 466 | |
1477 | 467 | sub AUTOLOAD { |
1478 | 468 | my $s = shift; |
1479 | 469 | $AUTOLOAD =~ s/^.*:://; |
1480 | 470 | $s->{Ex}->$AUTOLOAD(@_); |
1481 | 471 | } |
1482 | 472 | |
1483 | 473 | 1; |
1484 | 474 | |
1485 | ||
475 | 上記のモジュールは、異常終了のさいに接続を閉じるように気をつけてくれる点を除いて、Win32::OLEとまったく同じように使うことができます。 | |
476 | この特定の例の効果はWin32::OLE::newのデストラクタ引数を使うことによって、より簡単に実現できるということに注意してください: | |
1486 | 477 | |
1487 | The above module can be used just like Win32::OLE, except that | |
1488 | it takes care of closing connections in case of abnormal exits. | |
1489 | Note that the effect of this specific example can be easier accomplished | |
1490 | using the optional destructor argument of Win32::OLE::new: | |
1491 | ||
1492 | =end original | |
1493 | ||
1494 | 上記のモジュールは、異常終了の際に接続を閉じるように気をつけてくれる点を | |
1495 | 除いて、Win32::OLE とまったく同じように使えます。 | |
1496 | この特定の例の効果は Win32::OLE::new のデストラクタ引数を使うことによって、 | |
1497 | より簡単に実現できるということに注意してください: | |
1498 | ||
1499 | 478 | my $Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}); |
1500 | 479 | |
1501 | ||
480 | 上記の例での委任は特化されたオブジェクトでのメソッド呼出しのさらなる継承への見方と同じではないことに注意してください。 詳細については L<perlobj>, L<perltoot>, L<perlbot>を参照してください。 | |
481 | 本当のサブクラス化(@ISAを設定することによって利用できることになる)も、以下のデモンストレーションのように可能です: | |
1502 | 482 | |
1503 | Note that the delegation shown in the earlier example is not the same as | |
1504 | true subclassing with respect to further inheritance of method calls in your | |
1505 | specialized object. See L<perlobj>, L<perltoot> and L<perlbot> for details. | |
1506 | True subclassing (available by setting C<@ISA>) is also feasible, | |
1507 | as the following example demonstrates: | |
1508 | ||
1509 | =end original | |
1510 | ||
1511 | 上記の例での委任は特化されたオブジェクトでのメソッド呼び出しのさらなる | |
1512 | 継承への見方と同じではないことに注意してください。 | |
1513 | 詳細については L<perlobj>, L<perltoot>, L<perlbot> をご覧ください。 | |
1514 | 本当のサブクラスか(C<@ISA> を設定することによって利用できることになる)も、 | |
1515 | 以下のデモンストレーションのように可能です: | |
1516 | ||
1517 | 483 | # |
1518 | 484 | # Add error reporting to Win32::OLE |
1519 | 485 | # |
1520 | 486 | |
1521 | 487 | package Win32::OLE::Strict; |
1522 | 488 | use Carp; |
1523 | 489 | use Win32::OLE; |
1524 | 490 | |
1525 | 491 | use strict qw(vars); |
1526 | 492 | use vars qw($AUTOLOAD @ISA); |
1527 | 493 | @ISA = qw(Win32::OLE); |
1528 | 494 | |
1529 | 495 | sub AUTOLOAD { |
1530 | 496 | my $obj = shift; |
1531 | 497 | $AUTOLOAD =~ s/^.*:://; |
1532 | 498 | my $meth = $AUTOLOAD; |
1533 | 499 | $AUTOLOAD = "SUPER::" . $AUTOLOAD; |
1534 | 500 | my $retval = $obj->$AUTOLOAD(@_); |
1535 | 501 | unless (defined($retval) || $AUTOLOAD eq 'DESTROY') { |
1536 | 502 | my $err = Win32::OLE::LastError(); |
1537 | 503 | croak(sprintf("$meth returned OLE error 0x%08x",$err)) |
1538 | 504 | if $err; |
1539 | 505 | } |
1540 | 506 | return $retval; |
1541 | 507 | } |
1542 | 508 | |
1543 | 509 | 1; |
1544 | 510 | |
1545 | ||
511 | このパッケージはコンストラクラnew()をWin32::OLEパッケージから継承しています。 パッケージについての情報がオブジェクトによってキャッシュされるためにWin32::OLEを再びblessすることはできないことに注意しすることは大切なことです。 常に正しいパッケージを通して、new() コンストラクタを呼び出してください! | |
1546 | 512 | |
1547 | This package inherits the constructor new() from the Win32::OLE | |
1548 | package. It is important to note that you cannot later rebless a | |
1549 | Win32::OLE object as some information about the package is cached by | |
1550 | the object. Always invoke the new() constructor through the right | |
1551 | package! | |
1552 | ||
1553 | =end original | |
1554 | ||
1555 | このパッケージはコンストラクラ new() を Win32::OLE パッケージから | |
1556 | 継承しています。 | |
1557 | パッケージについての情報がオブジェクトによってキャッシュされるために | |
1558 | Win32::OLE を再び bless することはできないことに注意しすることは | |
1559 | 大切なことです。 | |
1560 | 常に正しいパッケージを通して、new() コンストラクタを呼び出してください! | |
1561 | ||
1562 | =begin original | |
1563 | ||
1564 | Here's how the above class will be used: | |
1565 | ||
1566 | =end original | |
1567 | ||
1568 | 513 | 以下に上記のクラスがどのように使われるかを示します: |
1569 | 514 | |
1570 | 515 | use Win32::OLE::Strict; |
1571 | 516 | my $Excel = Win32::OLE::Strict->new('Excel.Application', 'Quit'); |
1572 | 517 | my $Books = $Excel->Workbooks; |
1573 | 518 | $Books->UnknownMethod(42); |
1574 | 519 | |
1575 | ||
520 | 上記のサンプルでUnknownMethod()を呼び出すと、それは以下のように捕らえられます: | |
1576 | 521 | |
1577 | In the sample above the call to UnknownMethod() will be caught with | |
1578 | ||
1579 | =end original | |
1580 | ||
1581 | 上記のサンプルで UnknownMethod() を呼び出すと、それは以下のように | |
1582 | 捕らえられます: | |
1583 | ||
1584 | 522 | UnknownMethod returned OLE error 0x80020009 at test.pl line 5 |
1585 | 523 | |
1586 | ||
524 | というのもWorkbooksオブジェクトは$ExcelオブジェクトからWin32::OLE::Strictクラスを継承しているからです。 | |
1587 | 525 | |
1588 | because the Workbooks object inherits the class C<Win32::OLE::Strict> from the | |
1589 | C<$Excel> object. | |
1590 | ||
1591 | =end original | |
1592 | ||
1593 | というのも Workbooks オブジェクトは C<$Excel> オブジェクトから | |
1594 | C<Win32::OLE::Strict> クラスを継承しているからです。 | |
1595 | ||
1596 | 526 | =head1 NOTES |
1597 | 527 | |
1598 | (注意) | |
1599 | ||
1600 | 528 | =head2 Hints for Microsoft Office automation |
1601 | 529 | |
1602 | (Microsoft Office オートメーションのためのヒント) | |
1603 | ||
1604 | 530 | =over 8 |
1605 | 531 | |
1606 | 532 | =item Documentation |
1607 | 533 | |
1608 | ||
534 | Office アプリケーションのオブジェクト・モデルは、多くのアプリケーションのためのVisual Basicリファレンス・ガイドで定義されています。 これらは典型的には、標準インストールによってデフォルトでインストールされません。 これらはセットアップ・プログラムをカスタム・インストール・オプションで実行することによって後から追加することができます。 | |
1609 | 535 | |
1610 | =begin original | |
1611 | ||
1612 | The object model for the Office applications is defined in the Visual Basic | |
1613 | reference guides for the various applications. These are typically not | |
1614 | installed by default during the standard installation. They can be added | |
1615 | later by rerunning the setup program with the custom install option. | |
1616 | ||
1617 | =end original | |
1618 | ||
1619 | Office アプリケーションのオブジェクトモデルは、多くのアプリケーションのための | |
1620 | Visual Basic リファレンスガイドで定義されています。 | |
1621 | これらは典型的には、標準インストールによってデフォルトで | |
1622 | インストールされません。 | |
1623 | これらはセットアッププログラムをカスタムインストールオプションで | |
1624 | 実行することによって後から追加できます。 | |
1625 | ||
1626 | 536 | =item Class, Method and Property names |
1627 | 537 | |
1628 | ||
538 | Officeのバージョンによっては名前は変更されています。 例えばOffice95ではApplicationはメソッドでしたが、Office97ではプロパティです。 このためOffice95オブジェクトに問い合わせたときには、keys %$object によるプロパティ名のリストには現れません。 | |
1629 | 539 | |
1630 | ||
540 | クラス名はそのオブジェクトを作るメソッド/プロパティ名と常に同じではありません。 例えばWorkbookメソッドはOffice95ではWorkbookオブジェクトを返しますが、Office97では_Workbookを返します。 | |
1631 | 541 | |
1632 | The names have been changed between different versions of Office. For | |
1633 | example C<Application> was a method in Office 95 and is a property in | |
1634 | Office97. Therefore it will not show up in the list of property names | |
1635 | C<keys %$object> when querying an Office 95 object. | |
1636 | ||
1637 | =end original | |
1638 | ||
1639 | Office のバージョンによっては名前は変更されています。 | |
1640 | 例えば Office95 では C<Application> はメソッドでしたが、Office97 では | |
1641 | プロパティです。 | |
1642 | このため Office95 オブジェクトに問い合わせたときには、C<keys %$object> による | |
1643 | プロパティ名のリストには現れません。 | |
1644 | ||
1645 | =begin original | |
1646 | ||
1647 | The class names are not always identical to the method/property names | |
1648 | producing the object. E.g. the C<Workbook> method returns an object of | |
1649 | type C<Workbook> in Office 95 and C<_Workbook> in Office 97. | |
1650 | ||
1651 | =end original | |
1652 | ||
1653 | クラス名はそのオブジェクトを作るメソッド/プロパティ名と常に | |
1654 | 同じではありません。 | |
1655 | 例えば C<Workbook> メソッドは Office95 では C<Workbook> オブジェクトを | |
1656 | 返しますが、Office97 では C<_Workbook> を返します。 | |
1657 | ||
1658 | 542 | =item Moniker (GetObject support) |
1659 | 543 | |
1660 | ||
544 | Officeアプリケーションはファイル・モニカだけを実装しているようです。 例えばGetObject("File.XLS!Sheet") を通してあるワークシート・オブジェクトを取り出すことはできないようです。 さらにExcel95ではモニカはWorkseetオブジェクトを開始し、 Excel97ではWorkbookオブジェクトを返します。 移植性のあるコードを書くためには、Win32::OLE:: QueryObjectType クラス・メソッドまたは$object->{Version} のどちらかかを使うことができます。 | |
1661 | 545 | |
1662 | =begin original | |
1663 | ||
1664 | Office applications seem to implement file monikers only. For example | |
1665 | it seems to be impossible to retrieve a specific worksheet object through | |
1666 | C<GetObject("File.XLS!Sheet")>. Furthermore, in Excel 95 the moniker starts | |
1667 | a Worksheet object and in Excel 97 it returns a Workbook object. You can use | |
1668 | either the Win32::OLE::QueryObjectType class method or the $object->{Version} | |
1669 | property to write portable code. | |
1670 | ||
1671 | =end original | |
1672 | ||
1673 | Office アプリケーションはファイルモニカだけを実装しているようです。 | |
1674 | 例えば C<GetObject("File.XLS!Sheet")> を通してあるワークシートオブジェクトを | |
1675 | 取り出すことはできないようです。 | |
1676 | さらに Excel95 ではモニカは Worksheet オブジェクトを開始し、Excel97 では | |
1677 | Workbook オブジェクトを返します。 | |
1678 | 移植性のあるコードを書くためには、Win32::OLE::QueryObjectType | |
1679 | クラスメソッドまたは $object->{Version} のどちらかかを使えます。 | |
1680 | ||
1681 | 546 | =item Enumeration of collection objects |
1682 | 547 | |
1683 | (コレクション | |
548 | 列挙は不完全にしか実装されていないようです。 Office95アプリケーションはReset()もClone()メソッドもサポートしていないようです。 Clone()メソッドはOffice97でも未実装です。 しかしながら、Visual Basicと同じようにコレクションを一通りみるためには、C<for each>構造が機能します。 | |
1684 | 549 | |
1685 | =begin original | |
1686 | ||
1687 | Enumerations seem to be incompletely implemented. Office 95 application don't | |
1688 | seem to support neither the Reset() nor the Clone() methods. The Clone() | |
1689 | method is still unimplemented in Office 97. A single walk through the | |
1690 | collection similar to Visual Basics C<for each> construct does work however. | |
1691 | ||
1692 | =end original | |
1693 | ||
1694 | 列挙は不完全にしか実装されていないようです。 | |
1695 | Office95 アプリケーションは Reset() も Clone() メソッドも | |
1696 | サポートしていないようです。 | |
1697 | Clone() メソッドは Office97 でも未実装です。 | |
1698 | しかしながら、Visual Basic の C<for each> 構造と同じようにコレクションを | |
1699 | 一通りみるのは動作します。 | |
1700 | ||
1701 | 550 | =item Localization |
1702 | 551 | |
1703 | ||
552 | Office97からMicrosoftはローカライズされたクラス、メソッド、プロパティ名を変更し、英語に戻しました。 日付と通貨引数はまだ地域特有の解釈の対象となっていることに注意してください。 Visual Basicがタイプ・ライブラリ特有のロケールを使うのに対し、PerlはすべてのOLEトランザクションのためにシステム・デフォルト・ロケールを利用します。 VisualBasic スクリプトは相対的な参照を指定するために文字列引数として"R1C1"を使うでしょう。 ドイツ語Windowsで実行されるPerlスクリプトは "Z1S1"を使わなければなりません。 移植性のあるスクリプトを書くためには、LCIDモジュール・オプションをEnglishロケールに設定してください。 この変数はOLEオブジェクトを作成した後に変更するべきではありません; 途中でロケールが変更されると、メソッドによっては出たらめに失敗するようです。 | |
1704 | 553 | |
1705 | =begin original | |
1706 | ||
1707 | Starting with Office 97 Microsoft has changed the localized class, method and | |
1708 | property names back into English. Note that string, date and currency | |
1709 | arguments are still subject to locale specific interpretation. Perl uses the | |
1710 | system default locale for all OLE transaction whereas Visual Basic uses a | |
1711 | type library specific locale. A Visual Basic script would use "R1C1" in string | |
1712 | arguments to specify relative references. A Perl script running on a German | |
1713 | language Windows would have to use "Z1S1". Set the LCID module option | |
1714 | to an English locale to write portable scripts. This variable should | |
1715 | not be changed after creating the OLE objects; some methods seem to randomly | |
1716 | fail if the locale is changed on the fly. | |
1717 | ||
1718 | =end original | |
1719 | ||
1720 | Office97 から Microsoft はローカライズされたクラス、メソッド、プロパティ名を | |
1721 | 変更し、英語に戻しました。 | |
1722 | 日付と通貨引数はまだ地域特有の解釈の対象となっていることに注意してください。 | |
1723 | Visual Basic がタイプライブラリ特有のロケールを使うのに対し、Perl は | |
1724 | すべての OLE トランザクションのためにシステムデフォルトロケールを | |
1725 | 利用します。 | |
1726 | VisualBasic スクリプトは相対的な参照を指定するために文字列引数として | |
1727 | "R1C1" を使うでしょう。 | |
1728 | ドイツ語 Windows で実行される Perl スクリプトは "Z1S1" を | |
1729 | 使わなければなりません。 | |
1730 | 移植性のあるスクリプトを書くためには、LCID モジュールオプションを | |
1731 | English ロケールに設定してください。 | |
1732 | この変数は OLE オブジェクトを作成した後に変更するべきではありません; | |
1733 | 途中でロケールが変更されると、メソッドによっては出たらめに失敗するようです。 | |
1734 | ||
1735 | 554 | =item SaveAs method in Word 97 doesn't work |
1736 | 555 | |
1737 | ||
556 | これはWord97でのバグであることがわかっています。 Word/Foxpro互換性欠如(incompatibility)のMS knowledge baseをご覧ください。 その問題はPerl OLEインターフェースにも同じようにあてはまります。 回避する方法はWordBasic互換のオブジェクトを使うことです。 しかしそれはネイティブなメソッドのすべてのオプションをサポートしているわけではありません。 | |
1738 | 557 | |
1739 | =begin original | |
1740 | ||
1741 | This is an known bug in Word 97. Search the MS knowledge base for Word / | |
1742 | Foxpro incompatibility. That problem applies to the Perl OLE interface as | |
1743 | well. A workaround is to use the WordBasic compatibility object. It doesn't | |
1744 | support all the options of the native method though. | |
1745 | ||
1746 | =end original | |
1747 | ||
1748 | これは Word97 でのバグであることがわかっています。 | |
1749 | Word / Foxpro の非非互換性については MS knowledge base を検索してください。 | |
1750 | その問題は Perl OLE インターフェースにも同じように当てはまります。 | |
1751 | 回避する方法は WordBasic 互換のオブジェクトを使うことです。 | |
1752 | しかしそれはネイティブなメソッドのすべてのオプションを | |
1753 | サポートしているわけではありません。 | |
1754 | ||
1755 | 558 | $Word->WordBasic->FileSaveAs($file); |
1756 | 559 | |
1757 | ||
560 | この問題はOffice97サービス・リリース1を提供することにより修正されるようです。 | |
1758 | 561 | |
1759 | The problem seems to be fixed by applying the Office 97 Service Release 1. | |
1760 | ||
1761 | =end original | |
1762 | ||
1763 | この問題は Office97 サービスリリース 1 を適用することにより | |
1764 | 修正されるようです。 | |
1765 | ||
1766 | 562 | =item Randomly failing method calls |
1767 | 563 | |
1768 | ||
564 | 選択/アクティブにされていないオブジェクトを変更することは時折、壊れやすいうです。 これらのほとんどの問題は、操作される前にグラフ/シート/ドキュメントを選択あるいは、アクティブにしておくことによりなくなるようです(まるで対話的なユーザーが自動的にしているかのように)。 | |
1769 | 565 | |
1770 | =begin original | |
1771 | ||
1772 | It seems like modifying objects that are not selected/activated is sometimes | |
1773 | fragile. Most of these problems go away if the chart/sheet/document is | |
1774 | selected or activated before being manipulated (just like an interactive | |
1775 | user would automatically do it). | |
1776 | ||
1777 | =end original | |
1778 | ||
1779 | 選択/アクティブにされていないオブジェクトを変更することは時折、 | |
1780 | 壊れやすいようです。 | |
1781 | これらのほとんどの問題は、操作される前にグラフ/シート/ドキュメントを | |
1782 | 選択あるいは、アクティブにしておくことによりなくなるようです(まるで対話的な | |
1783 | ユーザーが自動的にしているかのように)。 | |
1784 | ||
1785 | 566 | =back |
1786 | 567 | |
1787 | 568 | =head2 Incompatibilities |
1788 | 569 | |
1789 | ||
570 | Activewareによって(build306として)配布されたバージョンとはいくつかの点で互換性がありません。 | |
1790 | 571 | |
1791 | =begin original | |
1792 | ||
1793 | There are some incompatibilities with the version distributed by Activeware | |
1794 | (as of build 306). | |
1795 | ||
1796 | =end original | |
1797 | ||
1798 | Activeware によって(build 306 として)配布されたバージョンとはいくつかの点で | |
1799 | 互換性がありません。 | |
1800 | ||
1801 | 572 | =over 8 |
1802 | 573 | |
1803 | 574 | =item 1 |
1804 | 575 | |
1805 | ||
576 | パッケージの名前が"OLE"から"Win32::OLE"に変更されました。 | |
1806 | 577 | |
1807 | The package name has changed from "OLE" to "Win32::OLE". | |
1808 | ||
1809 | =end original | |
1810 | ||
1811 | パッケージの名前が "OLE" から "Win32::OLE" に変更されました。 | |
1812 | ||
1813 | 578 | =item 2 |
1814 | 579 | |
1815 | ||
580 | 古い名前が一時的に使えても、"Win32::OLEFoo"という形式の関数は、いまはすべて"Win32::OLE::Foo"です。 Win32::OLECreateObject() はWin32::OLE::CreateObject()に変更され、確立された名前付きのコンストラクタの書き方に向けてWin32::OLE::new()と呼ばれます。 | |
581 | 古い名前は非推奨と考えるべきで、次のバージョンでは削除されるでしょう。 | |
1816 | 582 | |
1817 | All functions of the form "Win32::OLEFoo" are now "Win32::OLE::Foo", | |
1818 | though the old names are temporarily accomodated. Win32::OLECreateObject() | |
1819 | was changed to Win32::OLE::CreateObject(), and is now called | |
1820 | Win32::OLE::new() bowing to established convention for naming constructors. | |
1821 | The old names should be considered deprecated, and will be removed in the | |
1822 | next version. | |
1823 | ||
1824 | =end original | |
1825 | ||
1826 | 古い名前が一時的に使えても、"Win32::OLEFoo" という形式の関数は、いまは | |
1827 | すべて "Win32::OLE::Foo" です。 | |
1828 | Win32::OLECreateObject() は Win32::OLE::CreateObject() に変更され、 | |
1829 | 確立された名前付きのコンストラクタの書き方に向けて Win32::OLE::new() と | |
1830 | 呼ばれます。 | |
1831 | 古い名前は廃止予定と考えるべきです; そして次のバージョンでは | |
1832 | 削除されるでしょう。 | |
1833 | ||
1834 | 583 | =item 3 |
1835 | 584 | |
1836 | ||
585 | パッケージ"OLE::Variant"は今では"Win32::OLE::Variant"です。 | |
1837 | 586 | |
1838 | Package "OLE::Variant" is now "Win32::OLE::Variant". | |
1839 | ||
1840 | =end original | |
1841 | ||
1842 | パッケージ "OLE::Varinat" は今では "Win32::OLE::Variant" です。 | |
1843 | ||
1844 | 587 | =item 4 |
1845 | 588 | |
1846 | ||
589 | Variant関数は新しく、デフォルトでエクスポートされます。 すべてのVT_XXXタイプ定数も同様です。 | |
1847 | 590 | |
1848 | The Variant function is new, and is exported by default. So are | |
1849 | all the VT_XXX type constants. | |
1850 | ||
1851 | =end original | |
1852 | ||
1853 | Variant 関数は新しく、デフォルトでエクスポートされます。 | |
1854 | すべての VT_XXX タイプ定数も同様です。 | |
1855 | ||
1856 | ||
1857 | 591 | =item 5 |
1858 | 592 | |
1859 | ||
593 | コレクション・オブジェクトのサポートはWin32::OLE::Enumパッケージに移りました。 C<keys %$object>メソッドは今はオブジェクトのプロパティを列挙するために使われます。 | |
1860 | 594 | |
1861 | The support for collection objects has been moved into the package | |
1862 | Win32::OLE::Enum. The C<keys %$object> method is now used to enumerate | |
1863 | the properties of the object. | |
1864 | ||
1865 | =end original | |
1866 | ||
1867 | コレクションオブジェクトのサポートは Win32::OLE::Enum パッケージに | |
1868 | 移りました。 | |
1869 | C<keys %$object> メソッドは今はオブジェクトのプロパティを列挙するために | |
1870 | 使われます。 | |
1871 | ||
1872 | 595 | =back |
1873 | 596 | |
1874 | 597 | =head2 Bugs and Limitations |
1875 | 598 | |
1876 | (バグと制約) | |
1877 | ||
1878 | 599 | =over 8 |
1879 | 600 | |
1880 | 601 | =item * |
1881 | 602 | |
1882 | ||
603 | Win32::OLEメソッドと同じ名前(Dispatch, Invoke, SetProperty, DESTROYなど)のネイティブなOLEメソッドを呼び出すためには、Invokeを使う必要があります: | |
1883 | 604 | |
1884 | To invoke a native OLE method with the same name as one of the | |
1885 | Win32::OLE methods (C<Dispatch>, C<Invoke>, C<SetProperty>, C<DESTROY>, | |
1886 | etc.), you have to use the C<Invoke> method: | |
1887 | ||
1888 | =end original | |
1889 | ||
1890 | Win32::OLE メソッドと同じ名前(C<Dispatch>, C<Invoke>, C<SetProperty>, | |
1891 | C<DESTROY> など)のネイティブな OLE メソッドを呼び出すためには、C<Invoke> を | |
1892 | 使う必要があります: | |
1893 | ||
1894 | 605 | $Object->Invoke('Dispatch', @AdditionalArgs); |
1895 | 606 | |
1896 | ||
607 | 同じことは Exporter や the Dynaloader でエクスポートされるモジュール、つまり C<export>, C<export_to_level>, C<import>, | |
1897 | ||
1898 | The same is true for names exported by the Exporter or the Dynaloader | |
1899 | modules, e.g.: C<export>, C<export_to_level>, C<import>, | |
1900 | 608 | C<_push_tags>, C<export_tags>, C<export_ok_tags>, C<export_fail>, |
1901 | 609 | C<require_version>, C<dl_load_flags>, |
1902 | 610 | C<croak>, C<bootstrap>, C<dl_findfile>, C<dl_expandspec>, |
1903 | 611 | C<dl_find_symbol_anywhere>, C<dl_load_file>, C<dl_find_symbol>, |
1904 | C<dl_undef_symbols>, C<dl_install_xsub> | |
612 | C<dl_undef_symbols>, C<dl_install_xsub>, C<dl_error> にもいえます。 | |
1905 | 613 | |
1906 | =end original | |
1907 | ||
1908 | 同じことが Exporter または Dynaloader モジュールによってエクスポートされる | |
1909 | 名前についてもあてはまります。 | |
1910 | 例えば: C<export>, C<export_to_level>, C<import>, | |
1911 | C<_push_tags>, C<export_tags>, C<export_ok_tags>, C<export_fail>, | |
1912 | C<require_version>, C<dl_load_flags>, | |
1913 | C<croak>, C<bootstrap>, C<dl_findfile>, C<dl_expandspec>, | |
1914 | C<dl_find_symbol_anywhere>, C<dl_load_file>, C<dl_find_symbol>, | |
1915 | C<dl_undef_symbols>, C<dl_install_xsub>, C<dl_error> | |
1916 | ||
1917 | 614 | =back |
1918 | 615 | |
1919 | 616 | =head1 SEE ALSO |
1920 | 617 | |
1921 | ||
618 | L<Win32::OLE::Const>, L<Win32::OLE::Enum>, L<Win32::OLE::NLS>, L<Win32::OLE::Variant> のドキュメントにはWin32上のPerlでのOLEサポートについての追加の情報が入っています。 | |
1922 | 619 | |
1923 | The documentation for L<Win32::OLE::Const>, L<Win32::OLE::Enum>, | |
1924 | L<Win32::OLE::NLS> and L<Win32::OLE::Variant> contains additional | |
1925 | information about OLE support for Perl on Win32. | |
1926 | ||
1927 | =end original | |
1928 | ||
1929 | L<Win32::OLE::Const>, L<Win32::OLE::Enum>, L<Win32::OLE::NLS>, | |
1930 | L<Win32::OLE::Variant> のドキュメントには Win32 上の Perl のための | |
1931 | 追加の OLE サポートについての情報が入っています。 | |
1932 | ||
1933 | 620 | =head1 AUTHORS |
1934 | 621 | |
1935 | 622 | Originally put together by the kind people at Hip and Activeware. |
1936 | 623 | |
1937 | 624 | Gurusamy Sarathy <gsar@activestate.com> subsequently fixed several |
1938 | 625 | major bugs, memory leaks, and reliability problems, along with some |
1939 | 626 | redesign of the code. |
1940 | 627 | |
1941 | 628 | Jan Dubois <jand@activestate.com> pitched in with yet more massive redesign, |
1942 | 629 | added support for named parameters, and other significant enhancements. |
1943 | 630 | He's been hacking on it ever since. |
1944 | 631 | |
1945 | 632 | Please send questions about problems with this module to the |
1946 | 633 | Perl-Win32-Users mailinglist at ActiveState.com. The mailinglist charter |
1947 | 634 | requests that you put an [OLE] tag somewhere on the subject line (for OLE |
1948 | 635 | related questions only, of course). |
1949 | 636 | |
1950 | 637 | =head1 COPYRIGHT |
1951 | 638 | |
1952 | 639 | (c) 1995 Microsoft Corporation. All rights reserved. |
1953 | 640 | Developed by ActiveWare Internet Corp., now known as |
1954 | 641 | ActiveState Tool Corp., http://www.ActiveState.com |
1955 | 642 | |
1956 | 643 | Other modifications Copyright (c) 1997-2000 by Gurusamy Sarathy |
1957 | 644 | <gsar@activestate.com> and Jan Dubois <jand@activestate.com> |
1958 | 645 | |
1959 | 646 | You may distribute under the terms of either the GNU General Public |
1960 | 647 | License or the Artistic License, as specified in the README file. |
1961 | 648 | |
1962 | 649 | =head1 VERSION |
1963 | 650 | |
1964 | Version 0.1 | |
651 | Version 0.1703 6 September 2005 | |
1965 | ||
1966 | =begin meta | |
1967 | ||
1968 | Translated: Hippo2000 <GCD00051@nifty.ne.jp> (0.14) | |
1969 | Updated: SHIRAKATA Kentaro <argrath@ub32.org> (0.1502) | |
1970 | Status: completed | |
1971 | ||
1972 | =end meta | |
1973 | 652 | |
1974 | 653 | =cut |