ɎȿȾȿɊȺɅɖɇɈȿ ȺȽȿɇɌɋɌȼɈ ɉɈ ɈȻɊȺɁɈȼȺɇɂɘ ȽɈɋɍȾȺɊɋɌȼȿɇɇɈȿ ɈȻɊȺɁɈȼȺɌȿɅɖɇɈȿ ɍɑɊȿɀȾȿɇɂȿ ȼɕɋɒȿȽɈ ɉɊɈɎȿɋɋɂɈɇȺɅɖɇɈȽɈ ɈȻɊȺɁɈȼȺɇɂə «ȼɈɊɈɇȿɀɋɄɂɃ ȽɈɋɍȾȺɊɋɌȼȿɇɇɕɃ ɍɇɂȼȿɊɋɂɌȿɌ» ɍɬɜɟɪɠɞɟɧɨ ɧɚɭɱɧɨ-ɦɟɬɨɞɢɱɟɫɤɢɦ ɫɨɜɟɬɨɦ ɮɚɤɭɥɶɬɟɬɚ ɩɪɢɤɥɚɞɧɨɣ ɦɚɬɟɦɚɬɢɤɢ, ɢɧɮɨɪɦɚɬɢɤɢ ɢ ɦɟɯɚɧɢɤɢ 14 ɦɚɹ 2007, ɩɪɨɬɨɤɨɥ ʋ 9
Ⱥɜɬɨɪɵ: Ɇ.Ⱥ. Ⱥɪɬɟɦɨɜ, Ⱥ.Ⱥ. ȼɚɯɬɢɧ, Ƚ.ɗ. ȼɨɳɢɧɫɤɚɹ, ȼ.Ƚ. Ɋɭɞɚɥɟɜ Ɋɟɰɟɧɡɟɧɬ ɡɚɜ. ɤɚɮ. ɉɢɂɌ ɮ-ɬɚ ɎɄɇ ȼȽɍ ɇ.Ⱥ. Ɍɸɤɚɱɟɜ
Ɉɫɧɨɜɵ ɋɈɆ-ɬɟɯɧɨɥɨɝɢɣ ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ
ɍɱɟɛɧɨɟ ɩɨɫɨɛɢɟ ɩɨɞɝɨɬɨɜɥɟɧɨ ɧɚ ɤɚɮɟɞɪɟ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ ɢ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɹ ɢɧɮɨɪɦɚɰɢɨɧɧɵɯ ɫɢɫɬɟɦ ɮɚɤɭɥɶɬɟɬɚ ɩɪɢɤɥɚɞɧɨɣ ɦɚɬɟɦɚɬɢɤɢ, ɢɧɮɨɪɦɚɬɢɤɢ ɢ ɦɟɯɚɧɢɤɢ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ.
ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ 2007
Ⱦɥɹ ɫɩɟɰɢɚɥɶɧɨɫɬɢ 010503 – Ɇɚɬɟɦɚɬɢɱɟɫɤɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɢ ɚɞɦɢɧɢɫɬɪɢɪɨɜɚɧɢɟ ɢɧɮɨɪɦɚɰɢɨɧɧɵɯ ɫɢɫɬɟɦ.
2
ɋɨɞɟɪɠɚɧɢɟ ȼɜɟɞɟɧɢɟ............................................................................................................. 5 I. Ɉɫɧɨɜɧɵɟ ɩɨɧɹɬɢɹ ɢ ɨɩɪɟɞɟɥɟɧɢɹ................................................................ 5 1.1. ɑɬɨ ɬɚɤɨɟ COM. Ɉɫɧɨɜɧɵɟ ɫɜɨɣɫɬɜɚ, ɨɬɥɢɱɚɸɳɢɟ COM ɨɬ ɈɈɉ ....... 5 1.2. Ɉɬɧɨɲɟɧɢɟ «Ʉɥɢɟɧɬ-ɫɟɪɜɟɪ» .................................................................... 7 1.3. ɍɧɢɤɚɥɶɧɨɫɬɶ ɤɨɦɩɨɧɟɧɬ. GUID, CLSID................................................. 7 1.4. Ⱦɨɫɬɭɩ ɤ ɤɨɦɩɨɧɟɧɬɚɦ. ɂɧɬɟɪɮɟɣɫɵ ....................................................... 9 1.5. ɂɟɪɚɪɯɢɹ ɢɧɬɟɪɮɟɣɫɨɜ. ɂɧɬɟɪɮɟɣɫ IUnknown ....................................... 9 1.6. ɉɨɪɬɚɬɢɜɧɨɫɬɶ ɢ ɤɨɦɦɭɧɢɤɚɛɟɥɶɧɨɫɬɶ COM. Ɋɟɝɢɫɬɪɚɰɢɹ COMɫɟɪɜɟɪɨɜ. ɋɢɫɬɟɦɧɵɣ ɪɟɟɫɬɪ Windows.......................................................... 12 II. Ɋɚɡɪɚɛɨɬɤɚ COM-ɫɟɪɜɟɪɨɜ ɜ Delphi.......................................................... 14 2.1. Ɋɚɡɪɚɛɨɬɤɚ ɢɧɬɟɪɮɟɣɫɚ ............................................................................ 14 2.2. Ɋɟɚɥɢɡɚɰɢɹ ɜɫɬɪɨɟɧɧɨɝɨ COM-ɫɟɪɜɟɪɚ.................................................. 15 2.3. Ɋɚɡɪɚɛɨɬɤɚ ɤɨɦɩɨɧɟɧɬɨɜ.......................................................................... 17 2.4. Ɋɚɡɪɟɲɟɧɢɟ ɧɟɨɞɧɨɡɧɚɱɧɨɫɬɢ ɦɟɬɨɞɨɜ .................................................. 19 2.5. Ⱦɟɥɟɝɢɪɨɜɚɧɢɟ ɢɧɬɟɪɮɟɣɫɚ ..................................................................... 20 2.6. Ƚɟɧɟɪɚɬɨɪ ɤɨɦɩɨɧɟɧɬɨɜ ........................................................................... 22 2.7. ɉɪɢɦɟɪ ɪɟɚɥɢɡɚɰɢɢ ɜɫɬɪɨɟɧɧɨɝɨ COM-ɫɟɪɜɟɪɚ ................................... 24 2.8. ȼɧɟɲɧɢɟ COM-ɫɟɪɜɟɪɵ........................................................................... 27 2.9. Ȼɟɡɨɩɚɫɧɵɟ ɦɚɫɫɢɜɵ (SafeArray) ............................................................ 28 2.10. Ɉɛɪɚɛɨɬɤɚ ɦɚɫɫɢɜɨɜ ɞɚɧɧɵɯ ................................................................. 29 2.10.1. ɋɨɡɞɚɧɢɟ ɫɟɪɜɟɪɚ................................................................................. 29 2.10.2. ɋɨɡɞɚɧɢɟ ɤɥɢɟɧɬɚ ................................................................................ 31 III. Ȼɢɛɥɢɨɬɟɤɚ ɬɢɩɨɜ ...................................................................................... 33 3.1. ɉɪɨɟɤɬɢɪɨɜɚɧɢɟ ɛɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ. Ɋɟɞɚɤɬɨɪ Type Library Editor..... 33 3.2. ɉɚɧɟɥɶ ɢɧɫɬɪɭɦɟɧɬɨɜ ɞɢɚɥɨɝɨɜɨɝɨ ɨɤɧɚ Type Library Editor .............. 34 3.3. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɛɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ ɩɪɢ ɪɚɡɪɚɛɨɬɤɟ ɤɨɦɩɨɧɟɧɬɨɜ ....... 35 3.4. ɉɪɢɦɟɪ ɪɚɡɪɚɛɨɬɤɢ ɜɫɬɪɨɟɧɧɨɝɨ COM-ɫɟɪɜɟɪɚ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɛɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ ............................................................................................ 36 IV. Ɋɚɡɪɚɛɨɬɤɚ ɩɪɢɥɨɠɟɧɢɣ, ɢɫɩɨɥɶɡɭɸɳɢɯ COM-ɫɟɪɜɟɪɵ ...................... 38 4.1. ɉɨɥɭɱɟɧɢɟ ɫɫɵɥɤɢ ɧɚ ɢɧɬɟɪɮɟɣɫ ɤɨɦɩɨɧɟɧɬɚ. Ɏɭɧɤɰɢɢ CreateComObject ɢ ProgIdToClassId...................................................................................... 38 4.2. ɗɤɫɩɨɪɬ ɨɩɢɫɚɧɢɹ ɢɧɬɟɪɮɟɣɫɨɜ ɢɡ ɛɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ COM-ɫɟɪɜɟɪɚ 39 4.3. Ɉɫɨɛɟɧɧɨɫɬɢ ɬɟɯɧɢɤɢ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɤɨɦɩɨɧɟɧɬɨɜ ɜ Delphi............. 40 4.4. ɉɪɢɦɟɪ ɪɟɚɥɢɡɚɰɢɢ COM-ɤɥɢɟɧɬɚ ......................................................... 41 V. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ............................................................................................ 43 5.1. Ɋɚɧɧɟɟ ɢ ɩɨɡɞɧɟɟ ɫɜɹɡɵɜɚɧɢɟ. Ɍɢɩ Variant ............................................ 43 5.2. ɂɧɬɟɪɮɟɣɫɵ ɞɢɫɩɟɬɱɟɪɢɡɚɰɢɢ. ............................................................... 45 5.3. ɉɪɢɦɟɪ ɪɟɚɥɢɡɚɰɢɢ ɜɫɬɪɨɟɧɧɨɝɨ COM-ɫɟɪɜɟɪɚ ɚɜɬɨɦɚɬɢɡɚɰɢɢ........ 47 5.4. ɉɪɢɦɟɪ ɪɟɚɥɢɡɚɰɢɢ ɜɧɟɲɧɟɝɨ COM-ɫɟɪɜɟɪɚ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ............ 48 5.5. ɋɨɛɵɬɢɹ ɜ COM ɢ ɨɛɪɚɬɧɵɟ ɜɵɡɨɜɵ...................................................... 50 VI. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office ........................................ 54 3
6.1. VBA ɢ ɫɪɟɞɫɬɜɚ ɪɚɡɪɚɛɨɬɤɢ ɤɨɧɬɪɨɥɥɟɪɨɜ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ................. 56 6.2. Ɉɛɴɟɤɬɧɵɟ ɦɨɞɟɥɢ Microsoft Office ....................................................... 57 6.3. Ɉɛɳɢɟ ɩɪɢɧɰɢɩɵ ɫɨɡɞɚɧɢɹ ɤɨɧɬɪɨɥɥɟɪɨɜ ɚɜɬɨɦɚɬɢɡɚɰɢɢ.................. 58 6.4. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ Microsoft Word............................................................... 58 6.4.1. ɉɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɢ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ Microsoft Word.................................................................................... 58 6.4.2. ɋɨɡɞɚɧɢɟ ɢ ɨɬɤɪɵɬɢɟ ɞɨɤɭɦɟɧɬɨɜ Microsoft Word ............................ 60 6.4.3. ɋɨɯɪɚɧɟɧɢɟ, ɩɟɱɚɬɶ ɢ ɡɚɤɪɵɬɢɟ ɞɨɤɭɦɟɧɬɨɜ Microsoft Word .......... 60 6.4.4. ȼɫɬɚɜɤɚ ɬɟɤɫɬɚ ɢ ɨɛɴɟɤɬɨɜ ɜ ɞɨɤɭɦɟɧɬ ɢ ɮɨɪɦɚɬɢɪɨɜɚɧɢɟ ɬɟɤɫɬɚ ... 61 6.4.5. ɉɟɪɟɦɟɳɟɧɢɟ ɤɭɪɫɨɪɚ ɩɨ ɬɟɤɫɬɭ ......................................................... 64 6.4.6. ɋɨɡɞɚɧɢɟ ɬɚɛɥɢɰ .................................................................................... 65 6.4.7. Ɉɛɪɚɳɟɧɢɟ ɤ ɫɜɨɣɫɬɜɚɦ ɞɨɤɭɦɟɧɬɚ..................................................... 66 6.5. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ Microsoft Excel............................................................... 66 6.5.1. ɉɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɢ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ Microsoft Excel.................................................................................... 66 6.5.2. Ɂɚɩɭɫɤ Microsoft Excel, ɫɨɡɞɚɧɢɟ ɢ ɨɬɤɪɵɬɢɟ ɪɚɛɨɱɢɯ ɤɧɢɝ .................................................................................................... 68 6.5.3. ɋɨɯɪɚɧɟɧɢɟ, ɩɟɱɚɬɶ ɢ ɡɚɤɪɵɬɢɟ ɪɚɛɨɱɢɯ ɤɧɢɝ Microsoft Excel ........................................................................ 69 6.5.4. Ɉɛɪɚɳɟɧɢɟ ɤ ɥɢɫɬɚɦ ɢ ɹɱɟɣɤɚɦ ........................................................... 70 6.5.5. ɋɨɡɞɚɧɢɟ ɞɢɚɝɪɚɦɦ ............................................................................... 71 6.6. ɉɪɢɦɟɪ ɷɤɫɩɨɪɬɚ ɞɚɧɧɵɯ ɜ Word............................................................ 73 Ɂɚɞɚɱɢ «Ʉɥɢɟɧɬ-ɋɟɪɜɟɪ» ................................................................................ 82 ɋɩɢɫɨɤ ɥɢɬɟɪɚɬɭɪɵ ......................................................................................... 84 ɋɫɵɥɤɢ ɜ Internet ............................................................................................. 84
4
ȼɜɟɞɟɧɢɟ ɉɵɬɚɹɫɶ ɪɚɫɲɢɪɢɬɶ ɜɨɡɦɨɠɧɨɫɬɢ Windows, ɤɨɦɩɚɧɢɹ Microsoft ɫɬɨɥɤɧɭɥɚɫɶ ɫ ɧɟɨɛɯɨɞɢɦɨɫɬɶɸ ɫɨɡɞɚɧɢɹ ɬɟɯɧɨɥɨɝɢɢ, ɤɨɬɨɪɚɹ ɨɛɟɫɩɟɱɢɜɚɥɚ ɛɵ ɞɨɫɬɭɩ ɩɪɢɥɨɠɟɧɢɣ ɤ ɨɛɴɟɤɬɚɦ, ɪɚɫɩɨɥɨɠɟɧɧɵɦ ɜɧɟ ɩɪɢɥɨɠɟɧɢɹ. Ⱦɪɭɝɢɦɢ ɫɥɨɜɚɦɢ, ɩɪɢɥɨɠɟɧɢɹ ɞɨɥɠɧɵ ɪɚɛɨɬɚɬɶ ɫ ɜɧɟɲɧɢɦɢ ɨɛɴɟɤɬɚɦɢ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɨɜ, ɤɨɬɨɪɵɟ ɢɫɩɨɥɶɡɭɸɬɫɹ ɞɥɹ ɪɚɛɨɬɵ ɫ ɜɧɭɬɪɟɧɧɢɦɢ ɨɛɴɟɤɬɚɦɢ. Ʉɪɨɦɟ ɬɨɝɨ, ɨɛɴɟɤɬɵ ɧɟ ɞɨɥɠɧɵ ɡɚɜɢɫɟɬɶ ɨɬ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɤ ɧɢɦ ɞɨɥɠɟɧ ɛɵɬɶ ɨɬɤɪɵɬ ɞɨɫɬɭɩ ɫɨ ɫɬɨɪɨɧɵ ɩɪɢɥɨɠɟɧɢɣ ɧɟ ɬɨɥɶɤɨ ɥɨɤɚɥɶɧɨɝɨ, ɧɨ ɢ ɭɞɚɥɟɧɧɨɝɨ ɤɨɦɩɶɸɬɟɪɚ. ȼ ɤɚɱɟɫɬɜɟ ɪɟɲɟɧɢɹ ɩɪɨɛɥɟɦɵ, ɫɜɹɡɚɧɧɨɣ ɫ ɞɨɫɬɭɩɨɦ ɤ ɨɛɴɟɤɬɚɦ ɜ ɩɪɟɞɟɥɚɯ ɨɬɞɟɥɶɧɨɝɨ ɤɨɦɩɶɸɬɟɪɚ (ɩɪɢɥɨɠɟɧɢɟ—ɩɪɢɥɨɠɟɧɢɟ) ɢ ɥɨɤɚɥɶɧɨɣ ɫɟɬɢ (ɤɨɦɩɶɸɬɟɪ—ɤɨɦɩɶɸɬɟɪ), ɤɨɦɩɚɧɢɹ Microsoft ɪɚɡɪɚɛɨɬɚɥɚ ɦɨɞɟɥɢ ɫɨɫɬɚɜɧɵɯ ɨɛɴɟɤɬɨɜ, ɤɨɬɨɪɵɟ ɧɚɡɵɜɚɸɬɫɹ ɋɈɆ 1 (Component Object Model) ɢ DCOM (Distributed ɋɈɆ). ȼ ɞɚɧɧɨɦ ɦɟɬɨɞɢɱɟɫɤɨɦ ɩɨɫɨɛɢɢ ɢɡɥɨɠɟɧɵ ɨɫɧɨɜɵ ɷɬɨɣ ɬɟɯɧɨɥɨɝɢɢ ɢ ɩɪɨɞɟɦɨɧɫɬɪɢɪɨɜɚɧɵ ɩɪɢɦɟɪɵ ɫɨɡɞɚɧɢɹ ɢ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɩɪɢɥɨɠɟɧɢɣ, ɨɫɧɨɜɚɧɧɵɯ ɧɚ ɬɟɯɧɨɥɨɝɢɢ COM.
I. Ɉɫɧɨɜɧɵɟ ɩɨɧɹɬɢɹ ɢ ɨɩɪɟɞɟɥɟɧɢɹ 1.1. ɑɬɨ ɬɚɤɨɟ COM. Ɉɫɧɨɜɧɵɟ ɫɜɨɣɫɬɜɚ, ɨɬɥɢɱɚɸɳɢɟ COM ɨɬ ɈɈɉ Ɍɟɯɧɨɥɨɝɢɹ ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɨɫɧɨɜɚɧɚ ɧɚ ɬɨɦ, ɱɬɨ ɩɪɢɥɨɠɟɧɢɟ ɪɚɡɛɢɜɚɟɬɫɹ ɧɚ ɨɛɴɟɤɬɵ, ɤɨɬɨɪɵɟ ɜɡɚɢɦɨɞɟɣɫɬɜɭɸɬ ɞɪɭɝ ɫ ɞɪɭɝɨɦ ɜɧɭɬɪɢ ɩɪɨɝɪɚɦɦɵ (ɪɢɫ. 1.1).
ɗɬɨ ɞɚɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɛɵɫɬɪɨɣ ɪɚɡɪɚɛɨɬɤɢ ɢ ɦɨɞɢɮɢɤɚɰɢɢ ɩɪɨɝɪɚɦɦɧɵɯ ɩɪɨɞɭɤɬɨɜ ɫ ɢɡɛɟɠɚɧɢɟɦ ɨɲɢɛɨɤ, ɬɚɤ ɤɚɤ ɩɪɨɝɪɚɦɦɧɵɣ ɤɨɞ ɪɚɡɛɢɜɚɟɬɫɹ ɧɚ ɨɬɞɟɥɶɧɵɟ ɛɥɨɤɢ (ɨɛɴɟɤɬɵ), ɫɜɹɡɶ ɦɟɠɞɭ ɤɨɬɨɪɵɦɢ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɨ ɭɫɬɚɧɨɜɥɟɧɧɵɦ ɩɪɚɜɢɥɚɦ (ɫɜɨɣɫɬɜɚ ɢ ɦɟɬɨɞɵ). ȼ COM-ɬɟɯɧɨɥɨɝɢɢ ɨɛɴɟɤɬɵ ɩɨɦɟɳɚɸɬɫɹ ɜ ɨɬɞɟɥɶɧɵɟ ɢɫɩɨɥɧɹɟɦɵɟ ɛɥɨɤɢ (ɪɢɫ. 1.2), ɤɨɬɨɪɵɦɢ ɦɨɝɭɬ ɹɜɥɹɬɶɫɹ ɞɢɧɚɦɢɱɟɫɤɢ ɤɨɦɩɨɧɭɟɦɵɟ ɛɢɛɥɢɨɬɟɤɢ (DLL) ɢɥɢ ɩɪɢɥɨɠɟɧɢɟ (EXE).
Ɋɢɫ. 1.2. ɉɪɨɝɪɚɦɦɚ, ɫɤɨɧɫɬɪɭɢɪɨɜɚɧɧɚɹ ɩɨ ɚɪɯɢɬɟɤɬɭɪɟ COM Ɇɨɞɟɥɶ COM ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɢɧɫɬɪɭɤɰɢɸ ɩɨ ɫɨɡɞɚɧɢɸ ɫɨɜɦɟɫɬɢɦɵɯ ɤɨɦɩɨɧɟɧɬɨɜ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ ɢ ɧɟ ɹɜɥɹɟɬɫɹ ɹɡɵɤɨɦ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɛɢɛɥɢɨɬɟɤɨɣ ɩɪɨɝɪɚɦɦɧɨɝɨ ɤɨɞɚ ɢɥɢ ɤɨɦɩɢɥɹɬɨɪɨɦ. Ɍɟɯɧɨɥɨɝɢɹ COM ɨɫɧɨɜɚɧɚ ɧɚ ɫɥɟɞɭɸɳɢɯ ɨɫɧɨɜɧɵɯ ɤɨɧɰɟɩɰɢɹɯ. 1. ɍɧɢɤɚɥɶɧɨɫɬɶ ɢ ɤɨɧɬɟɤɫɬɧɚɹ ɧɟɡɚɜɢɫɢɦɨɫɬɶ ɤɨɦɩɨɧɟɧɬ. ȼ ɫɢɫɬɟɦɟ ɧɟ ɞɨɥɠɧɨ ɛɵɬɶ ɤɨɦɩɨɧɟɧɬɨɜ ɫ ɨɞɢɧɚɤɨɜɵɦ ɫɩɨɫɨɛɨɦ ɨɛɪɚɳɟɧɢɹ ɢ ɪɚɡɧɵɦɢ ɫɦɵɫɥɨɜɵɦɢ ɧɚɡɧɚɱɟɧɢɹɦɢ. 2. ɂɧɤɚɩɫɭɥɹɰɢɹ. Ɋɟɚɥɢɡɚɰɢɹ ɤɨɦɩɨɧɟɧɬɨɜ COM ɞɨɥɠɧɚ ɛɵɬɶ ɫɤɪɵɬɚ. ɗɬɨ ɧɟɨɛɯɨɞɢɦɨ ɞɥɹ ɬɨɝɨ, ɱɬɨɛɵ ɛɵɥɚ ɧɟɡɚɜɢɫɢɦɨɫɬɶ ɨɬ ɹɡɵɤɨɜ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. 3. ɉɨɪɬɚɬɢɜɧɨɫɬɶ ɢ ɤɨɦɦɭɧɢɤɚɛɟɥɶɧɨɫɬɶ. ɇɭɠɧɵɣ ɤɨɦɩɨɧɟɧɬ ɦɨɠɧɨ ɛɵɫɬɪɨ ɧɚɣɬɢ ɞɢɧɚɦɢɱɟɫɤɢ, ɝɞɟ ɛɵ ɨɧ ɧɢ ɧɚɯɨɞɢɥɫɹ.
Ɋɢɫ. 1.1. ɉɪɨɝɪɚɦɦɚ, ɫɤɨɧɫɬɪɭɢɪɨɜɚɧɧɚɹ ɜ ɈɈɉ
ɉɪɟɢɦɭɳɟɫɬɜɨ ɋɈɆ ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɬɨɦ, ɱɬɨ ɷɬɨ ɩɨɡɜɨɥɹɟɬ ɤɚɠɞɨɦɭ ɪɚɡɪɚɛɨɬɱɢɤɭ ɫɤɨɧɰɟɧɬɪɢɪɨɜɚɬɶɫɹ ɧɚ ɪɚɡɪɚɛɨɬɤɟ ɫɜɨɢɯ ɤɨɦɩɨɧɟɧɬ, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɨɛɦɟɧɢɜɚɬɶɫɹ ɢɧɮɨɪɦɚɰɢɟɣ ɧɟɡɚɜɢɫɢɦɨ ɨɬ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɢɥɢ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɵɯ ɫɪɟɞɫɬɜ ɪɟɚɥɢɡɚɰɢɢ. Ȼɨɥɟɟ ɬɨɝɨ, ɬɟɯɧɨɥɨɝɢɹ COM ɞɚɟɬ ɝɢɛɤɢɟ ɜɨɡɦɨɠɧɨɫɬɢ ɞɢɧɚɦɢɱɟɫɤɨɣ ɧɚɫɬɪɨɣɤɢ ɢ ɦɨɞɢɮɢɤɚɰɢɢ ɩɪɨɝɪɚɦɦɧɨɝɨ ɩɪɨɞɭɤɬɚ ɫ ɭɱɟɬɨɦ ɠɟɥɚɧɢɣ ɩɨɥɶɡɨɜɚɬɟɥɹ ɢ ɨɫɨɛɟɧɧɨɫɬɟɣ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɵ.
1
ɇɚɱɢɧɚɹ ɫ Windows 2000 ɜɜɨɞɢɬɫɹ ɧɨɜɚɹ ɬɟɯɧɨɥɨɝɢɹ, ɤɨɬɨɪɚɹ ɧɚɡɵɜɚɟɬɫɹ COM+. ɗɬɨ ɪɚɫɲɢɪɟɧɧɵɟ ɜɨɡɦɨɠɧɨɫɬɢ ɬɟɯɧɨɥɨɝɢɢ COM, ɩɨɞɞɟɪɠɢɜɚɸɳɚɹ ɚɪɯɢɬɟɤɬɭɪɭ Windows DNA (Distributed interNet Application) [5]. 5
6
1.2. Ɉɬɧɨɲɟɧɢɟ «Ʉɥɢɟɧɬ-ɫɟɪɜɟɪ» ɉɭɫɬɶ ɩɪɢɥɨɠɟɧɢɸ ɬɪɟɛɭɟɬɫɹ ɫɨɜɟɪɲɢɬɶ ɤɚɤɨɟ-ɬɨ ɞɟɣɫɬɜɢɟ ɢɥɢ ɩɪɨɰɟɫɫ, ɤɨɬɨɪɵɣ ɟɦɭ ɧɟɢɡɜɟɫɬɟɧ. ɇɨ ɟɫɬɶ ɤɨɦɩɨɧɟɧɬ, ɧɚɯɨɞɹɳɢɣɫɹ ɜ ɞɪɭɝɨɦ ɞɜɨɢɱɧɨɦ ɤɨɞɟ, ɤɨɬɨɪɵɣ ɦɨɠɟɬ ɷɬɨ ɞɟɣɫɬɜɢɟ ɢɥɢ ɩɪɨɰɟɫɫ ɫɨɜɟɪɲɢɬɶ. ȿɫɥɢ ɩɪɢɥɨɠɟɧɢɟ «ɡɧɚɟɬ» ɨ ɫɭɳɟɫɬɜɨɜɚɧɢɢ ɢ ɜɨɡɦɨɠɧɨɫɬɹɯ ɷɬɨɝɨ ɤɨɦɩɨɧɟɧɬɚ, ɬɨ ɨɧɨ «ɡɚɫɬɚɜɥɹɟɬ» ɤɨɦɩɨɧɟɧɬ ɜɵɩɨɥɧɢɬɶ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɟ ɞɟɣɫɬɜɢɟ. Ɍɚɤɨɟ ɜɡɚɢɦɨɞɟɣɫɬɜɢɟ ɩɪɢɥɨɠɟɧɢɹ ɢ ɤɨɦɩɨɧɟɧɬɚ ɧɚɡɵɜɚɸɬ ɨɬɧɨɲɟɧɢɟɦ «ɤɥɢɟɧɬ-ɫɟɪɜɟɪ», ɝɞɟ ɩɪɢɥɨɠɟɧɢɟ, ɢɝɪɚɸɳɟɟ ɪɨɥɶ ɢɧɢɰɢɚɬɨɪɚ, ɧɚɡɵɜɚɟɬɫɹ «ɤɥɢɟɧɬɨɦ», ɚ ɢɫɩɨɥɧɹɟɦɵɣ ɦɨɞɭɥɶ, ɯɪɚɧɹɳɢɣ ɤɨɦɩɨɧɟɧɬ, – «ɫɟɪɜɟɪɨɦ». ɋɭɳɟɫɬɜɭɟɬ ɞɜɚ ɬɢɩɚ COM-ɫɟɪɜɟɪɨɜ: ɜɫɬɪɨɟɧɧɵɟ, ɬɚɤɠɟ ɢɯ ɧɚɡɵɜɚɸɬ ɜɧɭɬɪɟɧɧɢɟ, ɢ ɜɧɟɲɧɢɟ. ȼɫɬɪɨɟɧɧɵɟ COM-ɫɟɪɜɟɪɵ ɷɬɨ ɞɢɧɚɦɢɱɟɫɤɢ ɤɨɦɩɨɧɭɟɦɵɟ ɛɢɛɥɢɨɬɟɤɢ (DLL), ɤɨɬɨɪɵɟ ɩɪɢ ɡɚɝɪɭɡɤɟ ɜ ɩɚɦɹɬɶ ɤɨɦɩɶɸɬɟɪɚ ɨɬɨɛɪɚɠɚɸɬɫɹ ɧɚ ɚɞɪɟɫɧɨɟ ɩɪɨɫɬɪɚɧɫɬɜɨ COM-ɤɥɢɟɧɬɚ (ɩɪɨɝɪɚɦɦɵ). ȼɧɟɲɧɢɟ COM-ɫɟɪɜɟɪɵ ɪɟɚɥɢɡɨɜɚɧɵ ɜ ɜɢɞɟ ɢɫɩɨɥɧɹɟɦɵɯ ɩɪɨɝɪɚɦɦ (exeɮɚɣɥɨɜ), ɢ, ɫɥɟɞɨɜɚɬɟɥɶɧɨ, ɨɧɢ ɜ ɩɪɨɰɟɫɫɟ ɜɵɩɨɥɧɟɧɢɹ ɡɚɧɢɦɚɸɬ ɜ ɩɚɦɹɬɢ ɤɨɦɩɶɸɬɟɪɚ ɚɞɪɟɫɧɨɟ ɩɪɨɫɬɪɚɧɫɬɜɨ, ɨɬɞɟɥɶɧɨɟ ɨɬ ɤɥɢɟɧɬɫɤɨɝɨ ɩɪɢɥɨɠɟɧɢɹ. ɗɬɨ ɩɪɢɜɨɞɢɬ ɤ ɧɟɤɨɬɨɪɵɦ ɧɸɚɧɫɚɦ ɩɪɢ ɫɨɡɞɚɧɢɢ ɬɚɤɨɝɨ ɪɨɞɚ COM-ɫɟɪɜɟɪɨɜ, ɨ ɱɟɦ ɛɭɞɟɬ ɫɤɚɡɚɧɨ ɜ ɩ. 2.8.
ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɦɨɠɟɬ ɛɵɬɶ ɫɢɧɬɟɡɢɪɨɜɚɧ ɢɡ ɨɱɟɧɶ ɧɟɩɨɫɬɨɹɧɧɵɯ ɦɚɲɢɧɧɵɯ ɯɚɪɚɤɬɟɪɢɫɬɢɤ. ȼ ɫɨɜɪɟɦɟɧɧɵɯ ɫɪɟɞɚɯ ɪɚɡɪɚɛɨɬɤɢ ɩɪɢɥɨɠɟɧɢɣ, ɬɚɤɢɯ ɤɚɤ Delphi, Visual Studio, ɪɟɚɥɢɡɨɜɚɧɵ ɫɪɟɞɫɬɜɚ ɚɜɬɨɦɚɬɢɱɟɫɤɨɝɨ ɩɨɥɭɱɟɧɢɹ ɭɧɢɤɚɥɶɧɨɝɨ ɧɨɦɟɪɚ ɱɟɪɟɡ API-ɮɭɧɤɰɢɸ CoCreateGuid. ɉɪɢɦɟɱɚɧɢɟ 1.1. ɑɬɨɛɵ ɩɨɥɭɱɢɬɶ GUID ɜ Delphi, ɧɚɞɨ ɧɚɠɚɬɶ ɤɨɦɛɢɧɚɰɢɸ ɤɥɚɜɢɲ Ctrl+Shift+G. Ⱦɥɹ ɚɜɬɨɦɚɬɢɱɟɫɤɨɣ ɝɟɧɟɪɚɰɢɢ ɝɥɨɛɚɥɶɧɨɝɨ ɭɧɢɤɚɥɶɧɨɝɨ ɧɨɦɟɪɚ ɜ ɩɪɨɝɪɚɦɦɟ ɢɫɩɨɥɶɡɭɟɬɫɹ ɩɪɨɰɟɞɭɪɚ CoCreateGuid ȼ ɩɪɨɝɪɚɦɦɟ GUID ɨɩɪɟɞɟɥɹɟɬɫɹ ɤɚɤ ɫɬɪɭɤɬɭɪɚ ɬɢɩɚ TGUID=Record D1: LongWord; D2: Word; D3: Word; D4: array [0..7] of Byte; End; ɑɟɬɵɪɟ ɩɨɥɹ TGUID ɫɨɨɬɜɟɬɫɬɜɭɸɬ ɱɟɬɵɪɟɦ ɫɨɫɬɚɜɧɵɦ 16-ɛɚɣɬɧɨɝɨ ɱɢɫɥɚ. Ⱦɥɹ ɭɞɨɛɫɬɜɚ ɷɬɨ ɱɢɫɥɨ ɦɨɠɟɬ ɛɵɬɶ ɡɚɩɢɫɚɧɨ ɜ ɫɥɟɞɭɸɳɟɣ ɫɢɦɜɨɥɶɧɨɣ ɲɟɫɬɧɚɞɰɚɬɟɪɢɱɧɨɣ ɮɨɪɦɟ (ɤɚɠɞɚɹ ɲɟɫɬɧɚɞɰɚɬɟɪɢɱɧɚɹ ɰɢɮɪɚ ɡɚɦɟɧɟɧɚ ɫɢɦɜɨɥɨɦ X): ‘{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}’
1.3. ɍɧɢɤɚɥɶɧɨɫɬɶ ɤɨɦɩɨɧɟɧɬ. GUID, CLSID ɑɬɨɛɵ ɩɪɢɥɨɠɟɧɢɟ ɦɨɝɥɨ ɫɜɹɡɚɬɶɫɹ ɫ ɤɨɦɩɨɧɟɧɬɨɦ, ɧɟɨɛɯɨɞɢɦɨ ɡɧɚɬɶ ɢɦɹ ɨɛɴɟɤɬɚ. ɇɨ ɬɭɬ ɜɨɡɧɢɤɚɟɬ ɩɪɨɛɥɟɦɚ ɫɨɜɩɚɞɟɧɢɹ ɢɦɟɧ, ɬɚɤ ɤɚɤ ɩɪɨɞɭɤɬɵ ɪɚɡɧɵɯ ɩɪɨɢɡɜɨɞɢɬɟɥɟɣ ɦɨɝɭɬ ɢɦɟɬɶ ɨɞɢɧɚɤɨɜɵɟ ɢɦɟɧɚ, ɚ ɫɥɟɞɨɜɚɬɟɥɶɧɨ, ɧɟ ɦɨɝɭɬ ɛɵɬɶ ɭɫɬɚɧɨɜɥɟɧɵ ɧɚ ɨɞɧɭ ɦɚɲɢɧɭ. Ⱦɥɹ ɪɟɲɟɧɢɹ ɷɬɨɣ ɩɪɨɛɥɟɦɵ ɤɨɦɩɚɧɢɹ Microsoft ɪɚɡɪɚɛɨɬɚɥɚ ɢɞɟɸ ɧɭɦɟɪɚɰɢɢ ɤɨɦɩɨɧɟɧɬɨɜ ɭɧɢɤɚɥɶɧɵɦɢ ɧɨɦɟɪɚɦɢ. ɗɬɨɬ ɧɨɦɟɪ ɧɚɡɵɜɚɟɬɫɹ GUID (Globally Unique Identifier), ɱɬɨ ɨɡɧɚɱɚɟɬ ɝɥɨɛɚɥɶɧɨ ɭɧɢɤɚɥɶɧɵɣ ɢɞɟɧɬɢɮɢɤɚɬɨɪ. GUID ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ 16-ɛɚɣɬɧɨɟ ɱɢɫɥɨ, ɜɵɱɢɫɥɟɧɧɨɟ ɫɩɟɰɢɚɥɶɧɨɣ ɯɷɲ-ɮɭɧɤɰɢɟɣ, ɭɱɢɬɵɜɚɸɳɟɣ ɫɥɟɞɭɸɳɢɟ ɞɚɧɧɵɟ: x ɬɟɤɭɳɢɟ ɞɚɬɭ ɢ ɜɪɟɦɹ; x «ɬɢɤɢ ɬɚɣɦɟɪɚ»; x ɩɪɨɫɬɨɣ ɢɧɤɪɟɦɟɧɬɧɵɣ ɫɱɟɬɱɢɤ, ɱɬɨɛɵ ɦɨɠɧɨ ɛɵɥɨ ɛɵ ɩɪɚɜɢɥɶɧɨ ɨɛɪɚɛɚɬɵɜɚɬɶ ɫɥɟɞɭɸɳɢɟ ɨɱɟɧɶ ɱɚɫɬɨ ɡɚɩɪɨɫɵ ɧɚ ɝɟɧɟɪɚɰɢɸ GUID; x ɢɫɬɢɧɧɨ ɝɥɨɛɚɥɶɧɨ ɭɧɢɤɚɥɶɧɵɣ IEEE-ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɦɚɲɢɧɵ, ɢɡɜɥɟɤɚɟɦɵɣ ɢɡ ɫɟɬɟɜɨɣ ɤɚɪɬɵ. ȿɫɥɢ ɜ ɦɚɲɢɧɟ ɧɟɬ ɫɟɬɟɜɨɣ ɤɚɪɬɵ,
7
ɉɪɢɦɟɪɵ ɡɚɩɢɫɢ GUID: ‘{168A8BE0-485B-11D5-B5D2-444553540000}’ ‘{168A8BE1-485B-11D5-B5D2-444553540000}’ ‘{168A8BE2-485B-11D5-B5D2-444553540000}’ Ⱦɥɹ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɫɢɦɜɨɥɶɧɨɝɨ ɩɪɟɞɫɬɚɜɥɟɧɢɹ GUID ɜ ɞɜɨɢɱɧɨɟ ɢ ɨɛɪɚɬɧɨ ɜ Delphi ɪɟɚɥɢɡɨɜɚɧɵ ɫɥɟɞɭɸɳɢɟ ɫɢɫɬɟɦɧɵɟ ɮɭɧɤɰɢɢ: function StringToGUID(const S: string): TGUID; function GUIDToString(const ClassID: TGUID): string; ɂɡ ɚɥɝɨɪɢɬɦɚ ɩɨɥɭɱɟɧɢɹ GUID ɢ ɪɚɡɦɟɪɧɨɫɬɢ ɱɢɫɥɚ ɜɢɞɧɨ, ɱɬɨ ɷɬɨɬ ɧɨɦɟɪ ɞɟɣɫɬɜɢɬɟɥɶɧɨ ɭɧɢɤɚɥɶɧɵɣ. Ʉɚɠɞɵɣ ɤɨɦɩɨɧɟɧɬ ɞɨɥɠɟɧ ɢɦɟɬɶ ɫɜɨɣ ɭɧɢɤɚɥɶɧɵɣ ɧɨɦɟɪ. ɗɬɨɬ ɧɨɦɟɪ ɧɚɡɵɜɚɸɬ CLSID (Class Identifier), ɱɬɨ ɨɡɧɚɱɚɟɬ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɤɥɚɫɫɚ. ɉɪɢɦɟɱɚɧɢɟ 1.2. Ʉɨɝɞɚ ɢɫɩɨɥɶɡɭɟɬɫɹ GUID, ɫɨɫɬɚɜɥɟɧɧɵɣ ɢɡ ɨɱɟɧɶ ɦɚɥɟɧɶɤɢɯ ɱɢɫɟɥ, ɷɬɨ, ɤɚɤ ɩɪɚɜɢɥɨ, ɹɜɥɹɟɬɫɹ ɩɪɢɡɧɚɤɨɦ ɩɪɢɧɚɞɥɟɠɧɨɫɬɢ ɤɨɦɩɨɧɟɧɬɚ ɤ ɹɞɪɭ, ɪɚɡɪɚɛɨɬɚɧɧɨɦɭ Microsoft. GUID, ɫɝɟɧɟɪɢɪɨɜɚɧɧɵɟ 8
ɞɪɭɝɢɦɢ ɩɪɨɢɡɜɨɞɢɬɟɥɹɦɢ, ɛɭɞɭɬ ɜɵɝɥɹɞɟɬɶ ɛɨɥɟɟ ɫɥɭɱɚɣɧɵɦɢ ɢ ɧɟ ɛɭɞɭɬ ɢɦɟɬɶ ɫɬɨɥɶɤɨ ɧɭɥɟɣ.
1.4. Ⱦɨɫɬɭɩ ɤ ɤɨɦɩɨɧɟɧɬɚɦ. ɂɧɬɟɪɮɟɣɫɵ Ɏɚɤɬɢɱɟɫɤɢ ɪɟɚɥɢɡɚɰɢɹ ɤɨɦɩɨɧɟɧɬɚ ɡɚɤɪɵɬɚ ɞɥɹ ɩɪɢɥɨɠɟɧɢɹ. ɉɨɥɶɡɨɜɚɬɟɥɹ ɧɟ ɞɨɥɠɧɵ ɢɧɬɟɪɟɫɨɜɚɬɶ ɫɩɨɫɨɛɵ ɪɟɚɥɢɡɚɰɢɢ ɤɨɦɩɨɧɟɧɬɚ, ɟɦɭ ɧɟɨɛɯɨɞɢɦɨ ɡɧɚɬɶ ɬɨɥɶɤɨ ɮɭɧɤɰɢɨɧɚɥɶɧɵɟ ɜɨɡɦɨɠɧɨɫɬɢ, ɤɨɬɨɪɵɟ ɦɨɠɟɬ ɩɪɟɞɨɫɬɚɜɢɬɶ ɤɨɦɩɨɧɟɧɬ. Ⱦɨɫɬɭɩ ɤ ɤɨɦɩɨɧɟɧɬɚɦ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɱɟɪɟɡ ɢɧɬɟɪɮɟɣɫ, ɤɨɬɨɪɵɣ ɢɝɪɚɟɬ ɪɨɥɶ ɤɨɧɬɪɚɤɬɚ (ɞɨɝɨɜɨɪɚ) ɦɟɠɞɭ ɨɛɴɟɤɬɨɦ ɢ ɩɨɥɶɡɨɜɚɬɟɥɟɦ. ɉɨ ɫɭɳɟɫɬɜɭ ɢɧɬɟɪɮɟɣɫ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɫɩɢɫɨɤ ɭɤɚɡɚɬɟɥɟɣ ɧɚ ɩɪɨɰɟɞɭɪɵ ɢ ɮɭɧɤɰɢɢ, ɪɟɚɥɢɡɨɜɚɧɧɵɟ ɜ ɤɨɦɩɨɧɟɧɬɟ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɢɧɬɟɪɮɟɣɫ ɩɨɯɨɠ ɧɚ ɚɛɫɬɪɚɤɬɧɵɣ ɤɥɚɫɫ, ɜ ɤɨɬɨɪɨɦ ɩɟɪɟɱɢɫɥɟɧɵ ɜɢɪɬɭɚɥɶɧɵɟ ɩɪɨɰɟɞɭɪɵ ɢ ɮɭɧɤɰɢɢ, ɪɟɚɥɢɡɚɰɢɹ ɤɨɬɨɪɵɯ ɥɨɠɢɬɫɹ ɧɚ ɞɨɱɟɪɧɢɟ ɤɥɚɫɫɵ. ɂɧɵɦɢ ɫɥɨɜɚɦɢ, ɢɧɬɟɪɮɟɣɫ ɨɩɪɟɞɟɥɹɟɬ ɩɨɜɟɞɟɧɢɟ ɨɛɴɟɤɬɚ, ɧɨ ɧɟ ɩɨɞɞɟɪɠɢɜɚɟɬ ɫɪɟɞɫɬɜɚ ɪɟɚɥɢɡɚɰɢɢ ɷɬɨɝɨ ɩɨɜɟɞɟɧɢɹ. ȿɳɟ ɨɞɧɢɦ ɜɚɠɧɵɦ ɫɜɨɣɫɬɜɨɦ COM-ɤɨɦɩɨɧɟɧɬɨɜ ɹɜɥɹɟɬɫɹ ɜɨɡɦɨɠɧɨɫɬɶ ɩɨɞɞɟɪɠɤɢ ɫɪɚɡɭ ɧɟɫɤɨɥɶɤɢɯ ɢɧɬɟɪɮɟɣɫɨɜ. ɗɬɨ ɞɚɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɪɚɡɛɢɬɶ ɛɨɥɶɲɨɣ ɧɚɛɨɪ ɩɪɨɰɟɞɭɪ ɧɚ ɧɟɫɤɨɥɶɤɨ ɧɟɛɨɥɶɲɢɯ ɥɨɝɢɱɟɫɤɢɯ ɝɪɭɩɩ. ɉɪɢɦɟɱɚɧɢɟ 1.3. Ɋɟɚɥɢɡɨɜɚɧɧɵɟ ɢ ɢɫɩɨɥɶɡɭɟɦɵɟ ɢɧɬɟɪɮɟɣɫɵ ɧɟ ɦɟɧɹɸɬɫɹ ɧɢɤɨɝɞɚ. ɉɪɢ ɦɨɞɢɮɢɤɚɰɢɢ ɤɨɦɩɨɧɟɧɬɚ ɫɭɳɟɫɬɜɭɸɳɢɣ ɢɧɬɟɪɮɟɣɫ ɧɟ ɦɟɧɹɟɬɫɹ, ɚ ɞɨɛɚɜɥɹɟɬɫɹ ɧɨɜɵɣ. ɗɬɨ ɨɛɟɫɩɟɱɢɜɚɟɬ ɤɨɧɬɟɤɫɬɧɭɸ ɧɟɡɚɜɢɫɢɦɨɫɬɶ COM. Ʉɚɤ ɢ ɤɨɦɩɨɧɟɧɬɵ, ɢɧɬɟɪɮɟɣɫɵ ɬɨɠɟ ɢɦɟɸɬ ɫɜɨɣ ɧɨɦɟɪ, ɤɨɬɨɪɵɣ ɧɚɡɵɜɚɸɬ IID (Interface Identifier), ɬɨ ɟɫɬɶ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɢɧɬɟɪɮɟɣɫɚ. ɗɬɨ ɩɨɡɜɨɥɹɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɢɧɬɟɪɮɟɣɫɵ, ɧɟ ɨɩɚɫɚɹɫɶ ɫɨɜɩɚɞɟɧɢɹ ɢɦɟɧ.
1.5. ɂɟɪɚɪɯɢɹ ɢɧɬɟɪɮɟɣɫɨɜ. ɂɧɬɟɪɮɟɣɫ IUnknown ȼ ɨɫɧɨɜɟ ɜɫɟɯ COM-ɢɧɬɟɪɮɟɣɫɨɜ ɥɟɠɢɬ ɢɧɬɟɪɮɟɣɫ ɫ ɢɦɟɧɟɦ IUnknown. ɗɬɨɬ ɢɧɬɟɪɮɟɣɫ ɩɨɞɞɟɪɠɢɜɚɟɬ ɬɪɢ ɜɚɠɧɵɟ ɮɭɧɤɰɢɢ, ɤɨɬɨɪɵɟ ɧɚɫɥɟɞɭɸɬɫɹ ɤɚɠɞɨɦɭ ɢɧɬɟɪɮɟɣɫɭ: IUnknown=interface [‘{00000000-0000-0000-C000-000000000046}’] function QueryInterface(const IID: TGUID; out obj): HResult; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; end;
9
ɉɪɢ ɞɢɧɚɦɢɱɟɫɤɨɣ ɡɚɝɪɭɡɤɟ ɤɨɦɩɨɧɟɧɬɚ ɫɢɫɬɟɦɚ ɧɟ ɡɧɚɟɬ, ɤɚɤɢɟ ɩɨɞɞɟɪɠɢɜɚɸɬɫɹ ɢɧɬɟɪɮɟɣɫɵ, ɧɨ ɡɧɚɟɬ, ɱɬɨ ɩɪɹɦɨ ɢɥɢ ɤɨɫɜɟɧɧɨ ɩɨɞɞɟɪɠɢɜɚɟɬɫɹ ɢɧɬɟɪɮɟɣɫ IUnknown, ɜ ɤɨɬɨɪɨɦ ɪɟɚɥɢɡɨɜɚɧɚ ɮɭɧɤɰɢɹ QueryInterface ɫɨ ɫɥɟɞɭɸɳɢɦɢ ɩɚɪɚɦɟɬɪɚɦɢ: IID – ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɡɚɩɪɚɲɢɜɚɟɦɨɝɨ ɢɧɬɟɪɮɟɣɫɚ; Obj – ɩɪɟɞɧɚɡɧɚɱɟɧ ɞɥɹ ɯɪɚɧɟɧɢɹ ɜɨɡɜɪɚɳɚɟɦɨɝɨ ɢɧɬɟɪɮɟɣɫɧɨɝɨ ɭɤɚɡɚɬɟɥɹ. Ɏɭɧɤɰɢɹ QueryInterface ɞɨɥɠɧɚ ɛɵɬɶ ɪɟɚɥɢɡɨɜɚɧɚ ɜ ɤɨɦɩɨɧɟɧɬɟ ɬɚɤɢɦ ɨɛɪɚɡɨɦ, ɱɬɨɛɵ ɦɨɠɧɨ ɛɵɥɨ ɩɨɥɭɱɢɬɶ ɥɸɛɨɣ ɩɨɞɞɟɪɠɢɜɚɟɦɵɣ ɢɧɬɟɪɮɟɣɫ. ȿɫɥɢ ɡɚɩɪɚɲɢɜɚɟɦɵɣ ɢɧɬɟɪɮɟɣɫ ɜ ɤɨɦɩɨɧɟɧɬɟ ɪɟɚɥɢɡɨɜɚɧ, QueryInterface ɜɨɡɜɪɚɳɚɟɬ ɭɤɚɡɚɬɟɥɶ ɧɚ ɢɧɬɟɪɮɟɣɫ ɜ ɩɚɪɚɦɟɬɪɟ obj ɢ ɡɧɚɱɟɧɢɟ S_OK, ɢɧɚɱɟ – E_NOINTERFACE. ɉɨɫɥɟ ɪɚɛɨɬɵ ɫ ɤɨɦɩɨɧɟɧɬɨɦ ɧɟɨɛɯɨɞɢɦɨ ɟɝɨ ɜɵɝɪɭɡɢɬɶ ɢɡ ɩɚɦɹɬɢ. ɋɥɨɠɧɨɫɬɢ ɦɨɝɭɬ ɜɨɡɧɢɤɧɭɬɶ, ɤɨɝɞɚ ɧɚ ɤɨɦɩɨɧɟɧɬ, ɜɟɪɧɟɟ, ɧɚ ɟɝɨ ɢɧɬɟɪɮɟɣɫɵ, ɢɦɟɟɬɫɹ ɧɟɫɤɨɥɶɤɨ ɫɫɵɥɨɤ. ȼ ɛɨɥɶɲɢɯ ɩɪɨɟɤɬɚɯ ɭɫɥɟɞɢɬɶ ɡɚ ɷɬɢɦ ɩɪɚɤɬɢɱɟɫɤɢ ɧɟɜɨɡɦɨɠɧɨ. ɑɬɨɛɵ ɢɡɛɟɠɚɬɶ ɬɚɤɨɣ ɫɢɬɭɚɰɢɢ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɱɟɬɱɢɤ ɫɫɵɥɨɤ. Ʉɨɝɞɚ ɤɥɢɟɧɬ ɩɨɥɭɱɚɟɬ ɧɟɤɨɬɨɪɵɣ ɢɧɬɟɪɮɟɣɫ, ɡɧɚɱɟɧɢɟ ɷɬɨɝɨ ɫɱɟɬɱɢɤɚ ɭɜɟɥɢɱɢɜɚɟɬɫɹ ɧɚ ɟɞɢɧɢɰɭ. Ʉɨɝɞɚ ɤɥɢɟɧɬ ɡɚɤɚɧɱɢɜɚɟɬ ɪɚɛɨɬɭ ɫ ɢɧɬɟɪɮɟɣɫɨɦ, ɡɧɚɱɟɧɢɟ ɧɚ ɟɞɢɧɢɰɭ ɭɦɟɧɶɲɚɟɬɫɹ. Ʉɨɝɞɚ ɨɧɨ ɞɨɯɨɞɢɬ ɞɨ ɧɭɥɹ, ɤɨɦɩɨɧɟɧɬ ɭɞɚɥɹɟɬ ɫɟɛɹ ɢɡ ɩɚɦɹɬɢ. Ʉɥɢɟɧɬ ɬɚɤɠɟ ɭɜɟɥɢɱɢɜɚɟɬ ɫɱɟɬɱɢɤ ɫɫɵɥɨɤ, ɤɨɝɞɚ ɫɨɡɞɚɟɬ ɧɨɜɭɸ ɫɫɵɥɤɭ ɧɚ ɭɠɟ ɢɦɟɸɳɢɣɫɹ ɭ ɧɟɝɨ ɢɧɬɟɪɮɟɣɫ. Ⱦɥɹ ɩɪɨɜɟɞɟɧɢɹ ɷɬɢɯ ɨɩɟɪɚɰɢɣ ɩɪɟɞɧɚɡɧɚɱɟɧɵ ɮɭɧɤɰɢɢ _AddRef ɢ _Release. _AddRef – ɭɜɟɥɢɱɢɜɚɟɬ ɫɱɟɬɱɢɤ ɫɫɵɥɨɤ ɧɚ ɟɞɢɧɢɰɭ ɢ ɜɨɡɜɪɚɳɚɟɬ ɤɨɥɢɱɟɫɬɜɨ ɫɫɵɥɨɤ. _Release – ɭɦɟɧɶɲɚɟɬ ɫɱɟɬɱɢɤ ɫɫɵɥɨɤ ɧɚ ɟɞɢɧɢɰɭ ɢ ɜɨɡɜɪɚɳɚɟɬ ɤɨɥɢɱɟɫɬɜɨ ɫɫɵɥɨɤ. ȿɫɥɢ ɫɱɟɬɱɢɤ ɪɚɜɟɧ ɧɭɥɸ, ɭɧɢɱɬɨɠɚɟɬ ɨɛɴɟɤɬ. Ⱦɥɹ ɤɨɪɪɟɤɬɧɨɣ ɪɚɛɨɬɵ ɩɪɢɥɨɠɟɧɢɹ ɢ ɤɨɦɩɨɧɟɧɬɨɜ ɧɟɨɛɯɨɞɢɦɨ ɫɬɪɨɝɨ ɫɨɛɥɸɞɚɬɶ ɬɪɢ ɩɪɚɜɢɥɚ, ɩɪɢɧɹɬɵɯ ɩɪɢ ɪɚɛɨɬɟ ɫ COM: 1. Ɏɭɧɤɰɢɢ, ɜɨɡɜɪɚɳɚɸɳɢɟ ɢɧɬɟɪɮɟɣɫɵ, ɩɟɪɟɞ ɜɨɡɜɪɚɬɨɦ ɜɫɟɝɞɚ ɞɨɥɠɧɵ ɜɵɡɜɚɬɶ _AddRef ɞɥɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɭɤɚɡɚɬɟɥɹ. ɗɬɨ ɬɚɤɠɟ ɨɬɧɨɫɢɬɫɹ ɢ ɤ QueryInterface. 2. ɉɨɫɥɟ ɡɚɜɟɪɲɟɧɢɹ ɪɚɛɨɬɵ ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɫɥɟɞɭɟɬ ɜɵɡɜɚɬɶ ɞɥɹ ɧɟɝɨ _Release. 3. ȼɫɟɝɞɚ ɫɥɟɞɭɟɬ ɜɵɡɵɜɚɬɶ _AddRef, ɤɨɝɞɚ ɫɨɡɞɚɟɬɫɹ ɧɨɜɚɹ ɫɫɵɥɤɚ ɧɚ ɞɚɧɧɵɣ ɢɧɬɟɪɮɟɣɫ. ɉɪɢɜɟɞɟɦ ɩɪɢɦɟɪ ɪɟɚɥɢɡɚɰɢɢ QueryInterface, _AddRef, _Release ɜ ɧɟɤɨɟɦ Ʉɨɦɩɨɧɟɧɬɟ TSomeObject: type TSomeObject=class(TObject, ISomeInterface) private 10
FRefCount: integer; public //ɨɩɢɫɚɧɢɟ ɢɧɬɟɪɮɟɣɫɚ IUnknown function QueryInterface(const IID:TGUID; out obj):HResult; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; end; function TSomeObject. QueryInterface(const obj):HResult; begin if GetInterface(IID, Obj) then begin Result:=S_OK; _AddRef; end else Result:=E_NOINTERFACE; end;
IID:TGUID;
out
1.6. ɉɨɪɬɚɬɢɜɧɨɫɬɶ ɢ ɤɨɦɦɭɧɢɤɚɛɟɥɶɧɨɫɬɶ COM. Ɋɟɝɢɫɬɪɚɰɢɹ COM-ɫɟɪɜɟɪɨɜ. ɋɢɫɬɟɦɧɵɣ ɪɟɟɫɬɪ Windows ȿɳɺ ɨɞɧɨ ɝɥɚɜɧɨɟ ɩɪɚɜɢɥɨ COM-ɬɟɯɧɨɥɨɝɢɢ – ɨɬɫɭɬɫɬɜɢɟ ɤɨɧɬɟɤɫɬɧɨɣ ɡɚɜɢɫɢɦɨɫɬɢ ɤɥɢɟɧɬɚ ɢ ɫɟɪɜɟɪɚ. ɉɨɞ ɤɨɧɬɟɤɫɬɧɨɣ ɧɟɡɚɜɢɫɢɦɨɫɬɶɸ ɩɨɞɪɚɡɭɦɟɜɚɟɬɫɹ, ɱɬɨ ɤɥɢɟɧɬ ɞɨɥɠɟɧ ɩɨɥɭɱɢɬɶ ɫɜɹɡɶ ɫ ɫɟɪɜɟɪɨɦ, ɝɞɟ ɛɵ ɨɧ ɧɢ ɧɚɯɨɞɢɥɫɹ. ɋɜɹɡɶ ɤɥɢɟɧɬɚ ɫ ɫɟɪɜɟɪɨɦ ɛɟɪɺɬ ɧɚ ɫɟɛɹ ɨɩɟɪɚɰɢɨɧɧɚɹ ɫɢɫɬɟɦɚ, ɤɨɬɨɪɚɹ ɫɨɞɟɪɠɢɬ ɫɢɫɬɟɦɧɭɸ ɛɚɡɭ ɞɚɧɧɵɯ, ɧɚɡɵɜɚɟɦɭɸ ɫɢɫɬɟɦɧɵɦ ɪɟɟɫɬɪɨɦ, ɝɞɟ ɩɪɨɩɢɫɵɜɚɟɬɫɹ ɧɚɡɜɚɧɢɟ COM-ɫɟɪɜɟɪɚ, ɭɧɢɤɚɥɶɧɵɣ ɧɨɦɟɪ ɤɨɦɩɨɧɟɧɬɚ CLSID ɢ ɞɪɭɝɚɹ ɢɧɮɨɪɦɚɰɢɹ. ɉɪɢɦɟɱɚɧɢɟ 1.4. Ɋɟɟɫɬɪ ɫɨɞɟɪɠɢɬ ɢɧɮɨɪɦɚɰɢɸ ɨɛ ɚɩɩɚɪɚɬɧɨɦ ɢ ɩɪɨɝɪɚɦɦɧɨɦ ɨɛɟɫɩɟɱɟɧɢɢ, ɨ ɤɨɧɮɢɝɭɪɚɰɢɢ ɤɨɦɩɶɸɬɟɪɚ ɢ ɨ ɩɨɥɶɡɨɜɚɬɟɥɹɯ. Ʌɸɛɚɹ ɩɪɨɝɪɚɦɦɚ ɞɥɹ Windows ɦɨɠɟɬ ɞɨɛɚɜɥɹɬɶ ɢ ɫɱɢɬɵɜɚɬɶ ɢɧɮɨɪɦɚɰɢɸ ɢɡ ɪɟɟɫɬɪɚ. Ɋɟɟɫɬɪ ɢɦɟɟɬ ɢɟɪɚɪɯɢɱɟɫɤɭɸ ɫɬɪɭɤɬɭɪɭ ɜ ɜɢɞɟ ɞɟɪɟɜɚ, ɝɞɟ ɭɡɥɚɦɢ ɹɜɥɹɸɬɫɹ ɪɚɡɞɟɥɵ, ɚ ɥɢɫɬɶɹɦɢ – ɞɚɧɧɵɟ. Ⱦɥɹ ɩɪɨɫɦɨɬɪɚ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɪɟɟɫɬɪɚ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɫɬɚɧɞɚɪɬɧɭɸ ɩɪɨɝɪɚɦɦɭ regedit.exe – ɪɟɞɚɤɬɨɪ ɪɟɟɫɬɪɚ (ɪɢɫ. 1.3).
function TSomeObject._AddRef: Integer; begin Inc(FRefCount); Result:=FRefCount; end; function TSomeObject._Release: Integer; begin Dec(FRefCount); Result:=FRefCount; if FRefCount=0 then destroy; end; ȼ ɩɪɢɦɟɪɟ ɨɩɢɫɚɧ ɨɛɴɟɤɬ TSomeObject, ɩɨɞɞɟɪɠɢɜɚɸɳɢɣ ɢɧɬɟɪɮɟɣɫ ISomeInterface, ɢ ɩɨɤɚɡɚɧɚ ɪɟɚɥɢɡɚɰɢɹ ɮɭɧɤɰɢɣ QueryInterface, _AddRef ɢ _Release.
Ɋɢɫ. 1.3. Ɋɟɞɚɤɬɨɪ ɪɟɟɫɬɪɚ
11
12
ɉɪɢɦɟɱɚɧɢɟ 1.5. ɋɢɫɬɟɦɧɵɣ ɪɟɟɫɬɪ ɹɜɥɹɟɬɫɹ ɨɱɟɧɶ ɜɚɠɧɨɣ ɫɭɳɧɨɫɬɶɸ ɜ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɟ. ɍɞɚɥɟɧɢɟ ɢɥɢ ɢɡɦɟɧɟɧɢɟ ɜ ɧɺɦ ɤɚɤɢɯ-ɥɢɛɨ ɞɚɧɧɵɯ ɦɨɠɟɬ ɩɪɢɜɟɫɬɢ ɤ ɧɟɜɨɡɦɨɠɧɨɫɬɢ ɪɚɛɨɬɵ ɧɟɤɨɬɨɪɵɯ ɩɪɢɥɨɠɟɧɢɣ, ɚ ɬɨ ɢ ɜɫɟɣ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɵ. ȼɫɟ ɢɡɦɟɧɟɧɢɹ ɜ ɪɟɟɫɬɪɟ ɡɚɩɢɫɵɜɚɸɬɫɹ ɫɪɚɡɭ ɧɚ ɞɢɫɤ, ɨɬɤɚɬɨɜ ɜ ɫɢɫɬɟɦɟ ɧɟɬ. ɍɞɚɥɟɧɢɟ ɢɥɢ ɢɡɦɟɧɟɧɢɟ ɞɚɧɧɵɯ ɜ ɫɢɫɬɟɦɧɨɦ ɪɟɟɫɬɪɟ ɛɟɡ ɱɟɬɤɨɝɨ ɩɨɧɢɦɚɧɢɹ ɫɭɬɢ ɩɪɨɢɫɯɨɞɹɳɟɝɨ ɤɪɚɣɧɟ ɨɩɚɫɧɨ. ɉɨɩɵɬɤɢ ɮɟɧɨɦɟɧɨɥɨɝɢɱɟɫɤɨɝɨ ɢɫɫɥɟɞɨɜɚɧɢɹ “ɱɬɨ ɛɭɞɟɬ, ɟɫɥɢ ɭɞɚɥɢɬɶ ɜɨɬ ɷɬɨ…” ɦɨɝɭɬ ɩɥɨɯɨ ɤɨɧɱɢɬɶɫɹ. Ⱦɚɧɧɵɟ ɨɛ ɨɛɴɟɤɬɚɯ COM ɯɪɚɧɹɬɫɹ ɜ ɩɨɞɪɚɡɞɟɥɟ CLSID ɪɚɡɞɟɥɚ HKEY_CLASSES_ROOT. ȼ ɷɬɨɦ ɪɚɡɞɟɥɟ ɩɟɪɟɱɢɫɥɟɧɵ CLSID ɜɫɟɯ ɤɨɦɩɨɧɟɧɬɨɜ, ɭɫɬɚɧɨɜɥɟɧɧɵɯ ɜ ɫɢɫɬɟɦɟ. Ʉɚɠɞɵɣ CLSID ɫɨɞɟɪɠɢɬ ɩɚɪɚɦɟɬɪ ɩɨ ɭɦɨɥɱɚɧɢɸ, ɧɚɡɵɜɚɟɦɵɣ «ɞɪɭɠɟɫɬɜɟɧɧɵɦ» ɢɦɟɧɟɦ ɤɨɦɩɨɧɟɧɬɚ. ȼ ɪɚɡɞɟɥɟ ɨɩɢɫɚɧɢɹ ɤɨɦɩɨɧɟɧɬɚ ɟɫɬɶ ɩɨɞɪɚɡɞɟɥ LocalServer32 (ɞɥɹ ɜɧɟɲɧɢɯ COM-ɫɟɪɜɟɪɨɜ) ɢɥɢ InprocServer32 (ɞɥɹ ɜɧɭɬɪɟɧɧɢɯ COM-ɫɟɪɜɟɪɨɜ), ɫɨɞɟɪɠɚɳɢɯ ɢɦɹ ɩɪɢɥɨɠɟɧɢɹ ɢɥɢ DLL, ɜ ɤɨɬɨɪɵɯ ɧɚɯɨɞɢɬɫɹ ɤɨɦɩɨɧɟɧɬ. ɂɦɹ ɮɚɣɥɚ ɢ CLSID – ɷɬɨ ɧɚɢɛɨɥɟɟ ɜɚɠɧɵɟ ɞɚɧɧɵɟ ɞɥɹ ɧɨɪɦɚɥɶɧɨɝɨ ɮɭɧɤɰɢɨɧɢɪɨɜɚɧɢɹ, ɧɨ ɞɥɹ ɧɟɤɨɬɨɪɵɯ, ɛɨɥɟɟ ɫɥɨɠɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ COM, ɯɪɚɧɢɬɫɹ ɢ ɞɪɭɝɚɹ ɢɧɮɨɪɦɚɰɢɹ. ɇɚɩɪɢɦɟɪ, ɷɬɨ ɧɨɦɟɪ ɛɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ, ɩɨɞɞɟɪɠɢɜɚɟɦɨɣ ɞɚɧɧɵɦ COM-ɫɟɪɜɟɪɨɦ (TypeLib), ɧɨɦɟɪ ɜɟɪɫɢɢ COM-ɫɟɪɜɟɪɚ (Version), ɩɪɨɝɪɚɦɦɧɨɟ ɢɦɹ (ProgID) ɢ ɬ. ɩ. ɑɬɨɛɵ ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɬɶ ɜɫɬɪɨɟɧɧɵɣ COM-ɫɟɪɜɟɪ ɜ ɫɢɫɬɟɦɧɨɦ ɪɟɟɫɬɪɟ, ɧɟɨɛɯɨɞɢɦɨ ɜɵɡɜɚɬɶ ɮɭɧɤɰɢɸ DllRegisterServer, ɧɚɯɨɞɹɳɭɸɫɹ ɜɧɭɬɪɢ DLL-ɦɨɞɭɥɹ COM-ɫɟɪɜɟɪɚ. ɗɬɨ ɦɨɠɧɨ ɫɞɟɥɚɬɶ ɜ ɩɪɢɥɨɠɟɧɢɢ, ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɡɚɝɪɭɡɢɜ DLL, ɢɥɢ ɫ ɩɨɦɨɳɶɸ ɫɬɚɧɞɚɪɬɧɨɣ ɭɬɢɥɢɬɵ Windows RegSvr32.exe, ɜɵɩɨɥɧɢɜ ɤɨɦɚɧɞɭ: RegSvr32 -s ɉɪɢ ɭɞɚɥɟɧɢɢ ɜɫɬɪɨɟɧɧɨɝɨ ɫɟɪɜɟɪɚ ɢɡ ɫɢɫɬɟɦɵ ɧɟɨɛɯɨɞɢɦɨ ɡɚɩɭɫɬɢɬɶ ɮɭɧɤɰɢɸ DllUnregisterServer. ȼ Windows ɭɞɚɥɟɧɢɟ ɫɟɪɜɟɪɚ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɤɨɦɚɧɞɨɣ:
II. Ɋɚɡɪɚɛɨɬɤɚ COM-ɫɟɪɜɟɪɨɜ ɜ Delphi 2.1. Ɋɚɡɪɚɛɨɬɤɚ ɢɧɬɟɪɮɟɣɫɚ ɉɪɟɠɞɟ, ɱɟɦ ɪɟɚɥɢɡɨɜɵɜɚɬɶ COM-ɫɟɪɜɟɪ, ɧɭɠɧɨ ɪɚɡɪɚɛɨɬɚɬɶ ɢɧɬɟɪɮɟɣɫ. ɂɧɬɟɪɮɟɣɫ ɹɜɥɹɟɬɫɹ ɫɜɹɡɶɸ ɦɟɠɞɭ ɤɥɢɟɧɬɨɦ ɢ ɫɟɪɜɟɪɨɦ (ɩ. 1.4). ȼ Delphi ɢɧɬɟɪɮɟɣɫɵ ɨɩɢɫɵɜɚɸɬɫɹ ɜ ɩɪɨɝɪɚɦɦɧɨɦ ɦɨɞɭɥɟ ɩɨ ɫɥɟɞɭɸɳɟɣ ɫɬɪɭɤɬɭɪɟ: =interface [] {ɫɩɢɫɨɤ ɩɪɨɰɟɞɭɪ ɢ ɮɭɧɤɰɢɣ} end; ɂɧɬɟɪɮɟɣɫɵ, ɤɚɤ ɢ ɤɥɚɫɫɵ, ɨɛɥɚɞɚɸɬ ɫɜɨɣɫɬɜɨɦ ɧɚɫɥɟɞɨɜɚɧɢɹ: =interface() [] {ɫɩɢɫɨɤ ɩɪɨɰɟɞɭɪ ɢ ɮɭɧɤɰɢɣ} end; ɉɪɢɦɟɱɚɧɢɟ 2.1. ȼ ɬɟɯɧɨɥɨɝɢɢ COM ɩɪɢɧɹɬɨ ɧɚɡɜɚɧɢɟ ɢɧɬɟɪɮɟɣɫɨɜ ɧɚɱɢɧɚɬɶ ɫ ɩɪɟɮɢɤɫɚ «I» (IUnknown, IDispatch, IMyInterface ɢ ɬ. ɩ.). ɉɪɢɦɟɱɚɧɢɟ 2.2. IID ɞɨɥɠɟɧ ɛɵɬɶ ɭɧɢɤɚɥɶɧɵɦ, ɩɨɷɬɨɦɭ, ɜɫɹɤɢɣ ɪɚɡ ɪɚɡɪɚɛɚɬɵɜɚɹ ɧɨɜɵɣ ɢɧɬɟɪɮɟɣɫ, ɢɫɩɨɥɶɡɭɣɬɟ ɝɟɧɟɪɚɬɨɪ ɭɧɢɤɚɥɶɧɵɯ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɜ ɫɢɫɬɟɦɵ (ɜ Delphi ɷɬɨ ɤɨɦɛɢɧɚɰɢɹ ɤɥɚɜɢɲ Ctrl+Shift+G). ɉɪɢɦɟɱɚɧɢɟ 2.3. ɉɪɢ ɨɩɢɫɚɧɢɢ ɦɟɬɨɞɨɜ ɢɧɬɟɪɮɟɣɫɨɜ ɧɟɨɛɯɨɞɢɦɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɢɪɟɤɬɢɜɭ stdcall, ɤɨɬɨɪɚɹ ɨɩɪɟɞɟɥɹɟɬ ɩɨɪɹɞɨɤ ɩɟɪɟɞɚɱɢ ɩɚɪɚɦɟɬɪɨɜ ɢ ɜɵɡɨɜɚ ɮɭɧɤɰɢɣ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫɨ ɫɬɚɧɞɚɪɬɨɦ, ɩɪɢɧɹɬɵɦ ɜ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɟ Windows.
Ⱦɥɹ ɪɟɝɢɫɬɪɚɰɢɢ ɜɧɟɲɧɢɯ COM-ɫɟɪɜɟɪɨɜ ɬɪɟɛɭɟɬɫɹ ɡɚɩɭɫɬɢɬɶ ɩɪɢɥɨɠɟɧɢɟ, ɜɤɥɸɱɢɜ ɜ ɤɨɦɚɧɞɧɭɸ ɫɬɪɨɤɭ ɡɚɩɭɫɤɚ ɤɥɸɱ /regserver, ɚ ɞɥɹ ɭɞɚɥɟɧɢɹ ɧɭɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɥɸɱ /unregserver. ȼɫɬɪɨɟɧɧɵɣ COMɫɟɪɜɟɪ ɪɟɝɢɫɬɪɢɪɭɟɬɫɹ ɢ ɩɪɢ ɩɟɪɜɨɦ ɡɚɩɭɫɤɟ ɩɪɢɥɨɠɟɧɢɹ ɛɟɡ ɜɫɹɤɢɯ ɞɨɩɨɥɧɢɬɟɥɶɧɵɯ ɤɥɸɱɟɣ ɜ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɟ, ɧɨ ɩɨɫɥɟ ɷɬɨɝɨ ɫɟɪɜɟɪ ɛɭɞɟɬ ɩɪɨɞɨɥɠɚɬɶ ɪɚɛɨɬɚɬɶ.
ȼɫɟ ɢɧɬɟɪɮɟɣɫɵ ɩɪɹɦɨ ɢɥɢ ɤɨɫɜɟɧɧɨ ɧɚɫɥɟɞɭɸɬɫɹ ɨɬ Iunknown, ɤɨɬɨɪɵɣ ɫɨɞɟɪɠɢɬ ɜɚɠɧɵɟ ɮɭɧɤɰɢɢ ɞɥɹ ɪɟɚɥɢɡɚɰɢɢ ɬɟɯɧɨɥɨɝɢɢ COM (ɩ. 1.5). Ⱦɥɹ ɤɨɪɪɟɤɬɧɨɣ ɪɚɛɨɬɵ ɩɪɢɥɨɠɟɧɢɹ ɜ ɢɧɬɟɪɮɟɣɫɟ ɫɥɟɞɭɟɬ ɨɩɢɫɵɜɚɬɶ ɮɭɧɤɰɢɢ, ɜɨɡɜɪɚɳɚɸɳɢɟ ɞɚɧɧɵɟ ɱɟɪɟɡ ɩɚɪɚɦɟɬɪɵ, ɚ ɜ ɤɚɱɟɫɬɜɟ ɪɟɡɭɥɶɬɚɬɚ – ɢɧɮɨɪɦɚɰɢɸ ɨ ɤɨɪɪɟɤɬɧɨɫɬɢ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɰɢɣ. ɗɬɨ ɦɨɠɟɬ ɛɵɬɶ ɭɫɥɨɜɧɵɣ ɤɨɞ ɨɲɢɛɤɢ ɢɥɢ ɠɟ ɩɪɨɫɬɨ ɢɧɮɨɪɦɚɰɢɹ ɨɛ ɭɫɩɟɲɧɨɫɬɢ ɜɵɩɨɥɧɟɧɢɹ, ɧɚɩɪɢɦɟɪ, true – ɮɭɧɤɰɢɹ ɜɵɩɨɥɧɟɧɚ ɭɫɩɟɲɧɨ, false – ɜɨɡɧɢɤɥɢ ɨɲɢɛɤɢ. Ɍɚɤɚɹ ɪɟɚɥɢɡɚɰɢɹ ɞɚɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɤɨɧɬɪɨɥɢɪɨɜɚɬɶ ɢ ɨɛɪɚɛɚɬɵɜɚɬɶ ɨɲɢɛɤɢ ɜ ɤɥɢɟɧɬɟ.
13
14
RegSvr32 -u
Ʉɥɢɟɧɬ ɢ ɫɟɪɜɟɪ ɞɨɥɠɧɵ ɫɨɞɟɪɠɚɬɶ ɨɞɢɧɚɤɨɜɨɟ ɨɩɢɫɚɧɢɟ ɢɧɬɟɪɮɟɣɫɨɜ. ɉɨɷɬɨɦɭ ɢɧɬɟɪɮɟɣɫ ɥɭɱɲɟ ɨɩɢɫɚɬɶ ɜ ɨɬɞɟɥɶɧɨɦ ɦɨɞɭɥɟ, ɤɨɬɨɪɵɣ ɩɪɢɫɨɟɞɢɧɹɟɬɫɹ ɤ ɤɥɢɟɧɬɭ ɢ ɤ ɫɟɪɜɟɪɭ. ɉɪɢɜɟɞɟɦ ɩɪɢɦɟɪ ɪɟɚɥɢɡɚɰɢɢ ɢɧɬɟɪɮɟɣɫɚ. ȼ ɞɚɧɧɨɦ ɩɪɢɦɟɪɟ ɨɩɢɫɚɧ ɢɧɬɟɪɮɟɣɫ, ɫɨɞɟɪɠɚɳɢɣ ɬɪɢ ɮɭɧɤɰɢɢ ɩɟɪɟɜɨɞɚ ɰɟɥɨɝɨ ɱɢɫɥɚ ɜ ɞɜɨɢɱɧɵɣ, ɜɨɫɶɦɟɪɢɱɧɵɣ ɢ ɲɟɫɬɧɚɞɰɚɬɟɪɢɱɧɵɣ ɜɢɞ, ɤɨɬɨɪɵɣ ɛɭɞɟɬ ɜɵɜɨɞɢɬɶɫɹ ɜ ɜɢɞɟ ɫɬɪɨɤɢ. 1. Ɂɚɩɭɫɬɢɦ Delphi ɢ ɨɬɤɪɨɟɦ ɧɨɜɵɣ ɦɨɞɭɥɶ, ɜɵɛɪɚɜ ɜ ɦɟɧɸ File/New. ȼ ɩɨɹɜɢɜɲɟɦɫɹ ɞɢɚɥɨɝɨɜɨɦ ɨɤɧɟ New Items ɧɚ ɡɚɤɥɚɞɤɟ New ɜɵɛɟɪɟɦ ɷɥɟɦɟɧɬ Unit. 2. ɋɨɯɪɚɧɢɦ ɧɨɜɵɣ ɦɨɞɭɥɶ ɤɚɤ ConvertInterface.pas ɢ ɜ ɧɟɝɨ ɩɨɦɟɫɬɢɦ ɫɥɟɞɭɸɳɢɣ ɬɟɤɫɬ: unit ConvertInterface; interface type IConvert=interface ['{F1E9A4BA-4C4A-11D5-8D36-006008159451}'] function Bin (const n: Word; var Str: WideString): Boolean; stdcall; function Oct(const n: Word; var Str: WideString): Boolean; stdcall; function Hex(const n: Word; var Str: WideString): Boolean; stdcall; end; implementation end.
2.2. Ɋɟɚɥɢɡɚɰɢɹ ɜɫɬɪɨɟɧɧɨɝɨ COM-ɫɟɪɜɟɪɚ ȼɫɬɪɨɟɧɧɵɟ COM-ɫɟɪɜɟɪɵ ɪɟɚɥɢɡɨɜɚɧɵ ɜɧɭɬɪɢ ɦɨɞɭɥɟɣ DLL, ɩɨɷɬɨɦɭ ɨɧɢ ɜɵɩɨɥɧɹɸɬɫɹ ɜ ɩɪɨɰɟɫɫɟ ɩɪɢɥɨɠɟɧɢɹ, ɤɨɬɨɪɨɟ ɢɯ ɢɫɩɨɥɶɡɭɟɬ. ȼɫɥɟɞɫɬɜɢɟ ɞɚɧɧɨɝɨ ɫɜɨɣɫɬɜɚ ɨɧɢ ɢ ɩɨɥɭɱɢɥɢ ɫɜɨɟ ɧɚɡɜɚɧɢɟ. Ⱦɥɹ ɬɨɝɨ, ɱɬɨɛɵ ɫɨɡɞɚɬɶ ɜɫɬɪɨɟɧɧɵɣ COM-ɫɟɪɜɟɪ ɜ ɫɪɟɞɟ Delphi, ɧɟɨɛɯɨɞɢɦɨ ɜ ɝɥɚɜɧɨɦ ɦɟɧɸ ɜɵɛɪɚɬɶ File/New. ȼ ɩɨɹɜɢɜɲɟɦɫɹ ɞɢɚɥɨɝɨɜɨɦ ɨɤɧɟ New Items ɨɬɤɪɵɬɶ ɡɚɤɥɚɞɤɭ ActiveX (ɪɢɫ. 2.1) ɢ ɜɵɛɪɚɬɶ ɷɥɟɦɟɧɬ ActiveX Library.
15
Ɋɢɫ. 2.1. Ⱦɢɚɥɨɝɨɜɨɟ ɨɤɧɨ New Items ɧɚ ɡɚɤɥɚɞɤɟ ActiveX ȼ ɛɢɛɥɢɨɬɟɤɭ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɩɪɨɩɢɫɵɜɚɸɬɫɹ ɱɟɬɵɪɟ ɷɤɫɩɨɪɬɢɪɭɟɦɵɟ ɮɭɧɤɰɢɢ, ɪɟɚɥɢɡɨɜɚɧɧɵɟ ɜ ɦɨɞɭɥɟ ComServ: function DllRegisterServer: HResult; stdcall; – ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɪɟɝɢɫɬɪɚɰɢɢ COM-ɫɟɪɜɟɪɚ ɜ ɫɢɫɬɟɦɧɨɦ ɪɟɟɫɬɪɟ. ȿɫɥɢ ɪɟɝɢɫɬɪɚɰɢɹ ɩɪɨɲɥɚ ɭɫɩɟɲɧɨ, ɮɭɧɤɰɢɹ ɜɨɡɜɪɚɳɚɟɬ ɡɧɚɱɟɧɢɟ S_OK, ɢɧɚɱɟ S_FAIL. function DllUnregisterServer: HResult; stdcall; – ɨɛɪɚɬɧɚɹ ɮɭɧɤɰɢɹ ɤ DllRegisterServer: ɭɞɚɥɹɟɬ ɢɡ ɪɟɟɫɬɪɚ Windows ɜɫɟ ɷɥɟɦɟɧɬɵ, ɤɚɫɚɸɳɢɟɫɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɤɨɦɩɨɧɟɧɬɚ. ȿɫɥɢ ɮɭɧɤɰɢɹ ɨɬɪɚɛɨɬɚɥɚ ɭɫɩɟɲɧɨ, ɬɨ ɜɨɡɜɪɚɳɚɟɬɫɹ ɡɧɚɱɟɧɢɟ S_OK, ɢɧɚɱɟ S_FAIL. function DllGetClassObject(const CLSID, IID: TGUID; var Obj): HResult; stdcall; – ɋɨɡɞɚɟɬ ɧɨɜɵɣ ɤɨɦɩɨɧɟɧɬ ɫ ɧɨɦɟɪɨɦ CLSID ɢ ɜɵɞɚɟɬ ɫɫɵɥɤɭ ɧɚ ɢɧɬɟɪɮɟɣɫ ɫ ɧɨɦɟɪɨɦ IID ɱɟɪɟɡ ɩɚɪɚɦɟɬɪ Obj. ȼɵɡɵɜɚɟɬɫɹ ɫɢɫɬɟɦɨɣ, ɪɟɚɥɢɡɭɸɳɟɣ ɚɪɯɢɬɟɤɬɭɪɭ COM. ȼ ɫɥɭɱɚɟ ɭɫɩɟɲɧɨɝɨ ɜɵɩɨɥɧɟɧɢɹ ɮɭɧɤɰɢɹ ɜɨɡɜɪɚɳɚɟɬ ɡɧɚɱɟɧɢɟ: S_OK ɢɧɚɱɟ: E_NOINTERFACE – ɟɫɥɢ ɢɧɬɟɪɮɟɣɫ ɧɟ ɧɚɣɞɟɧ ɢ CLASS_E_CLASSNOTAVAILABLE – ɤɨɦɩɨɧɟɧɬ ɫ ɬɚɤɢɦ ɧɨɦɟɪɨɦ ɧɟ ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɧ ɜ ɫɢɫɬɟɦɟ. function DllCanUnloadNow: HResult; stdcall; – ɜɵɡɵɜɚɟɬɫɹ ɦɟɯɚɧɢɡɦɨɦ ɪɟɚɥɢɡɚɰɢɢ COM ɞɥɹ ɩɪɨɜɟɪɤɢ, ɜɵɩɨɥɧɹɸɬɫɹ ɥɢ ɭɫɥɨɜɢɹ ɭɞɚɥɟɧɢɹ 16
COM-ɫɟɪɜɟɪɚ ɢɡ ɩɚɦɹɬɢ. ȿɫɥɢ ɤɚɤɨɟ-ɥɢɛɨ ɩɪɢɥɨɠɟɧɢɟ ɢɦɟɟɬ ɫɫɵɥɤɭ ɧɚ ɥɸɛɨɣ ɤɨɦɩɨɧɟɧɬ ɫɟɪɜɟɪɚ, ɬɨ ɮɭɧɤɰɢɹ ɜɟɪɧɟɬ S_FALSE, ɜ ɩɪɨɬɢɜɧɨɦ ɫɥɭɱɚɟ – S_TRUE. ȼ ɩɨɫɥɟɞɧɟɦ ɫɥɭɱɚɟ ɦɟɯɚɧɢɡɦ ɪɟɚɥɢɡɚɰɢɢ COM ɭɞɚɥɢɬ COM-ɫɟɪɜɟɪ ɢɡ ɩɚɦɹɬɢ.
2.3. Ɋɚɡɪɚɛɨɬɤɚ ɤɨɦɩɨɧɟɧɬɨɜ Ʌɸɛɨɣ COM-ɫɟɪɜɟɪ (ɜɫɬɪɨɟɧɧɵɣ ɢɥɢ ɜɧɟɲɧɢɣ) ɧɟ ɢɦɟɟɬ ɤɚɤɨɝɨ-ɥɢɛɨ ɫɦɵɫɥɚ, ɟɫɥɢ ɜ ɧɟɦ ɧɟ ɯɪɚɧɢɬɫɹ ɯɨɬɹ ɛɵ ɨɞɢɧ ɤɨɦɩɨɧɟɧɬ. ɑɬɨɛɵ ɜ ɪɚɡɪɚɛɚɬɵɜɚɟɦɨɦ COM-ɫɟɪɜɟɪɟ ɫɨɡɞɚɬɶ ɧɨɜɵɣ ɤɨɦɩɨɧɟɧɬ, ɧɚɞɨ ɜɵɛɪɚɬɶ ɜ ɝɥɚɜɧɨɦ ɦɟɧɸ Delphi ɩɭɧɤɬ File/New. Ɂɚɬɟɦ ɜ ɩɨɹɜɢɜɲɟɦɫɹ ɞɢɚɥɨɝɨɜɨɦ ɨɤɧɟ New Items (ɪɢɫ. 2.1) ɧɚ ɡɚɤɥɚɞɤɟ ActiveX ɜɵɛɪɚɬɶ ɷɥɟɦɟɧɬ COM Object. ɉɨɫɥɟ ɱɟɝɨ ɨɬɤɪɨɟɬɫɹ ɨɤɧɨ ɦɚɫɬɟɪɚ COM Object Wizard (ɪɢɫ. 2.2).
Internal (ɜɧɭɬɪɟɧɧɢɣ) – ɢɫɩɨɥɶɡɭɟɬɫɹ ɬɨɥɶɤɨ ɞɥɹ ɤɨɦɩɨɧɟɧɬɨɜ, ɤɨɬɨɪɵɟ ɧɟ ɩɪɟɞɩɨɥɚɝɚɟɬɫɹ ɫɞɟɥɚɬɶ ɞɨɫɬɭɩɧɵɦɢ ɞɥɹ ɤɥɢɟɧɬɫɤɢɯ ɩɪɢɥɨɠɟɧɢɣ. Ɂɚɩɪɚɲɢɜɚɬɶ ɫɨɡɞɚɧɢɟ ɷɤɡɟɦɩɥɹɪɚ ɬɚɤɨɝɨ ɤɨɦɩɨɧɟɧɬɚ ɪɚɡɪɟɲɟɧɨ ɬɨɥɶɤɨ ɫɨɛɫɬɜɟɧɧɨɦɭ COM-ɫɟɪɜɟɪɭ; Single Instance (ɟɞɢɧɫɬɜɟɧɧɵɣ ɷɤɡɟɦɩɥɹɪ) – ɞɥɹ ɤɚɠɞɨɝɨ ɤɥɢɟɧɬɫɤɨɝɨ ɩɪɢɥɨɠɟɧɢɹ ɞɨɩɭɫɤɚɟɬɫɹ ɫɨɡɞɚɧɢɟ ɬɨɥɶɤɨ ɨɞɧɨɝɨ ɷɤɡɟɦɩɥɹɪɚ ɤɨɦɩɨɧɟɧɬɚ. ɉɪɢɥɨɠɟɧɢɟ, ɡɚɩɪɚɲɢɜɚɸɳɟɟ ɤɨɦɩɨɧɟɧɬ, ɛɭɞɟɬ ɪɚɛɨɬɚɬɶ ɫ ɫɨɛɫɬɜɟɧɧɨɣ ɨɬɞɟɥɶɧɨɣ ɤɨɩɢɟɣ COM-ɫɟɪɜɟɪɚ; Multiple Instance (ɦɧɨɠɟɫɬɜɨ ɷɤɡɟɦɩɥɹɪɨɜ) – COM-ɫɟɪɜɟɪ ɫɩɨɫɨɛɟɧ ɫɨɡɞɚɜɚɬɶ ɦɧɨɠɟɫɬɜɨ ɤɨɩɢɣ ɤɨɦɩɨɧɟɧɬɚ. ɉɪɢ ɡɚɩɪɨɫɟ ɧɨɜɨɝɨ ɷɤɡɟɦɩɥɹɪɚ ɤɨɦɩɨɧɟɧɬɚ ɧɨɜɵɣ ɫɟɪɜɟɪ ɧɟ ɡɚɩɭɫɤɚɟɬɫɹ (ɟɫɥɢ ɨɧ ɭɠɟ ɡɚɩɭɳɟɧ ɪɚɧɟɟ), ɚ ɫɨɡɞɚɟɬɫɹ ɧɨɜɵɣ ɷɤɡɟɦɩɥɹɪ COM-ɨɛɴɟɤɬɚ. Threading model – ɨɩɪɟɞɟɥɹɟɬ ɬɢɩ ɩɨɞɞɟɪɠɢɜɚɟɦɨɣ ɦɨɞɟɥɢ ɩɨɬɨɤɨɜ ɡɚɞɚɱ. Ⱦɚɧɧɵɣ ɩɚɪɚɦɟɬɪ ɚɤɬɭɚɥɟɧ ɬɨɥɶɤɨ ɤ ɜɫɬɪɨɟɧɧɵɦ COMɫɟɪɜɟɪɚɦ ɢ ɦɨɠɟɬ ɩɪɢɧɢɦɚɬɶ ɫɥɟɞɭɸɳɢɟ ɡɧɚɱɟɧɢɹ: Single (ɨɞɧɨɩɨɬɨɤɨɜɚɹ) – ɜɫɟ ɡɚɹɜɤɢ ɧɚ ɞɨɫɬɭɩ ɤ ɤɨɦɩɨɧɟɧɬɭ ɜɵɫɬɪɚɢɜɚɸɬɫɹ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɨɣ Windows ɜ ɨɱɟɪɟɞɶ, ɬɚɤ ɱɬɨ ɧɟɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɛɟɫɩɨɤɨɢɬɶɫɹ ɨ ɬɨɦ, ɱɬɨ ɧɟɫɤɨɥɶɤɨ ɩɨɬɨɤɨɜ ɦɨɝɭɬ ɨɞɧɨɜɪɟɦɟɧɧɨ ɢɦɟɬɶ ɞɨɫɬɭɩ ɤ ɫɟɪɜɟɪɭ; Apartment (ɫɟɤɰɢɨɧɢɪɨɜɚɧɧɚɹ) – ɤɨɦɩɨɧɟɧɬɵ ɨɛɪɚɛɚɬɵɜɚɸɬ ɡɚɩɪɨɫɵ ɬɨɥɶɤɨ ɢɡ ɬɨɝɨ ɠɟ ɩɨɬɨɤɚ, ɤɨɬɨɪɵɣ ɢɯ ɩɨɪɨɞɢɥ. Ɉɞɢɧ ɫɟɪɜɟɪ ɦɨɠɟɬ ɷɤɫɩɨɪɬɢɪɨɜɚɬɶ ɦɧɨɠɟɫɬɜɨ COM-ɨɛɴɟɤɬɨɜ, ɩɪɢɱɟɦ ɤɚɠɞɵɣ ɢɡ ɧɢɯ ɦɨɠɟɬ ɛɵɬɶ ɫɨɡɞɚɧ ɜ ɞɪɭɝɨɦ ɩɨɬɨɤɟ, ɩɨɷɬɨɦɭ ɬɪɟɛɭɟɬɫɹ ɫɢɧɯɪɨɧɢɡɚɰɢɹ ɞɨɫɬɭɩɚ ɤ ɥɸɛɵɦ ɝɥɨɛɚɥɶɧɵɦ ɞɚɧɧɵɦ, ɤɨɬɨɪɵɟ ɨɩɪɟɞɟɥɟɧɵ ɜ ɫɟɪɜɟɪɟ ɩɨɫɪɟɞɫɬɜɨɦ ɦɶɸɬɟɤɫɨɜ, ɫɨɛɵɬɢɣ, ɤɪɢɬɢɱɟɫɤɢɯ ɫɟɤɰɢɣ ɢ ɬ. ɩ. Free (ɫɜɨɛɨɞɧɚɹ) – ɦɧɨɠɟɫɬɜɨ ɩɨɬɨɤɨɜ ɦɨɠɟɬ ɛɵɬɶ ɚɤɬɢɜɧɨ ɜ ɥɸɛɨɦ ɞɚɧɧɨɦ ɤɨɦɩɨɧɟɧɬɟ ɜ ɨɞɧɨ ɢ ɬɨ ɠɟ ɜɪɟɦɹ. ȼɫɥɟɞɫɬɜɢɟ ɷɬɨɝɨ ɧɭɠɧɨ ɩɨɡɚɛɨɬɢɬɶɫɹ ɨ ɫɢɧɯɪɨɧɢɡɚɰɢɢ ɞɨɫɬɭɩɚ ɧɟ ɬɨɥɶɤɨ ɤ ɝɥɨɛɚɥɶɧɵɦ ɞɚɧɧɵɦ, ɧɨ ɢ ɤ ɥɨɤɚɥɶɧɵɦ; Both (ɢ ɫɟɤɰɢɨɧɧɚɹ ɢ ɫɜɨɛɨɞɧɚɹ) – ɤɨɦɩɨɧɟɧɬ ɞɨɥɠɟɧ ɫɢɧɯɪɨɧɢɡɢɪɨɜɚɬɶ ɫɜɨɣ ɫɨɛɫɬɜɟɧɧɵɣ ɞɨɫɬɭɩ ɤ ɷɤɡɟɦɩɥɹɪɚɦ ɤɨɦɩɨɧɟɧɬɨɜ, ɧɚɫɬɪɨɟɧɧɵɯ ɧɚ ɫɟɤɰɢɨɧɢɪɨɜɚɧɧɭɸ ɦɨɞɟɥɶ, ɢ ɜɵɩɨɥɧɹɬɶ ɦɚɪɲɪɭɬɢɡɚɰɢɸ ɩɚɪɚɦɟɬɪɨɜ ɦɟɠɞɭ ɩɨɬɨɤɚɦɢ;
ȼ ɩɨɥɟ Class Name ɜɜɨɞɢɬɫɹ ɢɦɹ ɤɥɚɫɫɚ. ɉɪɟɮɢɤɫ «T» ɤ ɧɚɡɜɚɧɢɸ ɨɛɴɟɤɬɚ ɞɨɛɚɜɢɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ. ɇɚɡɜɚɧɢɟ ɨɛɴɟɤɬɚ ɧɟ ɞɨɥɠɧɨ ɛɵɬɶ ɫɥɭɠɟɛɧɵɦ ɫɥɨɜɨɦ ɢ ɫɨɜɩɚɞɚɬɶ ɫ ɢɦɟɧɟɦ COM-ɫɟɪɜɟɪɚ ɢ ɩɪɢɫɨɟɞɢɧɟɧɧɨɝɨ ɦɨɞɭɥɹ. ɉɨɥɟ Instancing ɨɩɪɟɞɟɥɹɟɬ ɦɟɬɨɞ ɫɨɡɞɚɧɢɹ ɷɤɡɟɦɩɥɹɪɚ ɤɨɦɩɨɧɟɧɬɚ ɢ ɚɤɬɭɚɥɶɧɨ ɬɨɥɶɤɨ ɞɥɹ ɜɧɟɲɧɢɯ COM-ɫɟɪɜɟɪɨɜ:
ȼ ɩɨɥɟ Implemented interfaces ɱɟɪɟɡ ɡɚɩɹɬɭɸ ɜɜɨɞɹɬɫɹ ɧɚɡɜɚɧɢɹ ɢɧɬɟɪɮɟɣɫɨɜ, ɤɨɬɨɪɵɟ ɛɭɞɟɬ ɩɨɞɞɟɪɠɢɜɚɬɶ ɤɨɦɩɨɧɟɧɬ. ɉɨɥɟ Description ɩɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɜɜɨɞɚ ɡɚɦɟɱɚɧɢɣ ɢɥɢ ɫɬɪɨɤɢɨɩɢɫɚɧɢɹ ɨɛɴɟɤɬɚ. Ʉɨɝɞɚ ɜɵɛɢɪɚɟɬɫɹ ɨɩɰɢɹ Include Type Library, ɤ ɨɩɢɫɚɧɢɸ Ʉɨɦɩɨɧɟɧɬɚ ɩɨɞɤɥɸɱɚɟɬɫɹ ɛɢɛɥɢɨɬɟɤɚ ɬɢɩɨɜ. Ȼɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ ɪɚɡɨɛɪɚɧɵ ɜ ɬɪɟɬɶɟɣ ɝɥɚɜɟ. Ʉɨɦɩɨɧɟɧɬɵ ɜ Delphi ɨɩɢɫɵɜɚɸɬɫɹ ɬɚɤ ɠɟ, ɤɚɤ ɢ ɤɥɚɫɫɵ ɨɛɴɟɤɬɨɜ:
17
18
Ɋɢɫ. 2.2. Ɇɚɫɬɟɪ COM Object Wizard
=class( {,; ɗɬɨ ɧɟɨɛɯɨɞɢɦɨ ɞɥɹ ɢɡɛɟɠɚɧɢɹ ɨɲɢɛɨɤ, ɤɨɝɞɚ ɤɨɦɩɨɧɟɧɬ ɧɟ ɩɨɥɭɱɢɥ ɨɬ ɤɥɢɟɧɬɚ ɢɧɬɟɪɮɟɣɫ ɨɛɪɚɬɧɨɝɨ ɜɵɡɨɜɚ. 51
ȼ Delphi ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɫɨɡɞɚɟɬɫɹ ɩɪɨɝɪɚɦɦɧɵɣ ɤɨɞ, ɩɨɞɞɟɪɠɢɜɚɸɳɢɣ ɦɟɯɚɧɢɡɦ ɨɛɪɚɛɨɬɤɢ ɫɨɛɵɬɢɣ ɬɨɥɶɤɨ ɞɥɹ ɩɟɪɜɨɝɨ ɜ ɩɨɪɹɞɤɟ ɩɨɞɤɥɸɱɟɧɢɣ ɤɥɢɟɧɬɚ. ɑɬɨɛɵ ɛɵɥɚ ɜɨɡɦɨɠɧɨɫɬɶ ɩɟɪɟɞɚɜɚɬɶ ɫɨɛɵɬɢɹ ɦɧɨɠɟɫɬɜɭ ɩɨɞɤɥɸɱɟɧɧɵɯ ɤɥɢɟɧɬɨɜ, ɧɭɠɧɨ ɜɧɟɫɬɢ ɧɟɤɨɬɨɪɵɟ ɢɡɦɟɧɟɧɢɹ ɜ ɩɪɨɝɪɚɦɦɧɵɣ ɤɨɞ. ȼɨ-ɩɟɪɜɵɯ, ɞɥɹ ɜɨɡɦɨɠɧɨɫɬɢ ɩɨɥɭɱɟɧɢɹ ɫɫɵɥɤɢ ɧɚ ɞɚɧɧɵɣ COMɫɟɪɜɟɪ ɫ ɩɨɦɨɳɶɸ ɮɭɧɤɰɢɢ GetOleObject ɟɝɨ ɧɭɠɧɨ ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɬɶ ɜ ɬɚɛɥɢɰɟ ɜɵɩɨɥɧɹɟɦɵɯ ɨɛɴɟɤɬɨɜ Windows. Ⱦɥɹ ɷɬɢɯ ɰɟɥɟɣ ɜ ɤɥɚɫɫ ɩɪɨɟɤɬɢɪɭɟɦɨɝɨ ɤɨɦɩɨɧɟɧɬɚ ɧɭɠɧɨ ɞɨɛɚɜɢɬɶ ɩɨɥɟ FObjectID: integer ɞɥɹ ɯɪɚɧɟɧɢɹ ɢɞɟɧɬɢɮɢɤɚɬɨɪɚ, ɚ ɜ ɩɪɨɰɟɞɭɪɭ Intitialize ɞɨɛɚɜɢɬɶ ɩɪɨɰɟɞɭɪɭ ɪɟɝɢɫɬɪɚɰɢɢ ɤɨɦɩɨɧɟɧɬɚ: RegisterActiveObject(self as Iunknown, , ACTIVEOBJECT_WEAK, FObjectID) Ⱦɥɹ ɬɨɝɨ ɱɬɨɛɵ ɭɞɚɥɢɬɶ ɤɨɦɩɨɧɟɧɬ ɢɡ ɬɚɛɥɢɰɵ ɜɵɩɨɥɧɹɟɦɵɯ ɨɛɴɟɤɬɨɜ Windows, ɧɭɠɧɨ ɫɨɡɞɚɬɶ ɦɟɬɨɞ Destroy ɢ ɜ ɧɟɦ ɜɵɡɜɚɬɶ ɮɭɧɤɰɢɸ RevokeActiveObject: destructor .Destroy; begin RevokeActiveObject(FObjectID, nil); end; ɉɪɢ ɫɨɡɞɚɧɢɢ ɷɥɟɦɟɧɬɚ FConnectionPoint ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ CreateConnectionPoint ɜ ɤɚɱɟɫɬɜɟ ɩɪɟɞɩɨɫɥɟɞɧɟɝɨ ɩɚɪɚɦɟɬɪɚ ɩɟɪɟɞɚɟɬɫɹ ɧɟ ckSingle (ɡɚɞɚɧɧɵɣ ɩɨ ɭɦɨɥɱɚɧɢɸ), ɚ ckMulti. ȼ ɢɬɨɝɟ ɪɟɚɥɢɡɚɰɢɹ ɦɟɬɨɞɚ Initialize ɛɭɞɟɬ ɫɥɟɞɭɸɳɚɹ: procedure .Initialize; begin inherited Initialize; FConnectionPoints := TConnectionPoints.Create(Self); if AutoFactory.EventTypeInfo nil then FConnectionPoint := FConnectionPoints.CreateConnectionPoint (AutoFactory.EventIID, ckMulti, EventConnect) else FConnectionPoint := nil; RegisterActiveObject(self as Iunknown, , ACTIVEOBJECT_WEAK, FObjectID) end; Ⱦɥɹ ɬɨɝɨ ɱɬɨɛɵ ɨɬɫɥɟɠɢɜɚɬɶ ɦɧɨɠɟɫɬɜɨ ɩɚɪɚɥɥɟɥɶɧɵɯ ɩɨɞɤɥɸɱɟɧɢɣ, ɧɭɠɧɨ ɪɟɚɥɢɡɨɜɚɬɶ ɫɥɟɞɭɸɳɭɸ ɮɭɧɤɰɢɸ: function .GetEnumerator: IEnumConnections; var 52
Container: IConnectionPointContainer; ConnectionPoint: IconnectionPoint; begin OleCheck(QueryInterface(IConnectionPointContainer, Container)); OleCheck(Container.FindConnectionPoint(AutoFactory.EventIID, ConnectionPoint)); ConnectionPoint.EnumConnections(result); end; Ⱦɚɧɧɚɹ ɮɭɧɤɰɢɹ ɩɨɡɜɨɥɹɟɬ ɩɨɥɭɱɢɬɶ ɞɚɧɧɵɟ ɨɬ ɫɱɟɬɱɢɤɚ ɩɨɞɤɥɸɱɟɧɢɣ, ɩɨɫɥɟ ɱɟɝɨ ɧɭɠɧɨ «ɩɪɨɣɬɢɫɶ» ɩɨ ɜɫɟɦ ɩɨɞɤɥɸɱɟɧɢɹɦ: var Enum: IEnumConnections; ConnectData: TConnectData; Fetched: Cardinal;
ɉɪɢɦɟɱɚɧɢɟ 5.6. Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ, ɱɬɨ ɢɧɬɟɪɮɟɣɫɵ ɤɨɦɩɨɧɟɧɬɚ ɢ ɨɛɴɟɤɬɚ ɜ ɩɪɢɥɨɠɟɧɢɢ ɞɨɥɠɧɵ ɢɦɟɬɶ ɨɞɢɧɚɤɨɜɵɣ IID. Ɍɚɤɠɟ ɞɨɥɠɧɚ ɫɨɜɩɚɞɚɬɶ ɧɭɦɟɪɚɰɢɹ ɦɟɬɨɞɨɜ ɢɧɬɟɪɮɟɣɫɨɜ. ɉɪɢ ɩɨɞɤɥɸɱɟɧɢɢ ɩɪɢɥɨɠɟɧɢɹ ɤ ɤɨɦɩɨɧɟɧɬɭ ɧɭɠɧɨ ɜɵɩɨɥɧɢɬɶ ɫɥɟɞɭɸɳɢɣ ɩɪɨɝɪɚɦɦɧɵɣ ɤɨɞ: with as IConnectionPointContainer do begin FindConnectionPoint(, ESink); OleCheck(ESink.Advise( as IDispatch, ConnectId)); end; ȼ ɞɚɧɧɨɦ ɩɪɨɝɪɚɦɦɧɨɦ ɤɨɞɟ ɜɵɩɨɥɧɹɸɬɫɹ ɫɥɟɞɭɸɳɢɟ ɞɟɣɫɬɜɢɹ:
begin {ɦɟɬɨɞ ɪɚɡɪɚɛɚɬɵɜɚɟɦɨɝɨ ɤɨɦɩɨɧɟɧɬɚ} {ɨɛɪɚɛɨɬɤɚ ɫɨɛɵɬɢɣ ɩɪɢ ɩɨɞɤɥɸɱɟɧɢɢ ɦɧɨɠɟɫɬɜɚ ɤɥɢɟɧɬɨɜ} Enum:=GetEnumerator; if Enum nil then begin while Enum.Next(1,ConnectData,@Fetched) = S_OK do if ConnectData.pUnk nil then (ConnectData.pUnk as ). end; end; Ɋɚɫɫɦɨɬɪɢɦ ɞɚɥɟɟ ɪɟɚɥɢɡɚɰɢɸ ɩɪɢɥɨɠɟɧɢɣ, ɢɫɩɨɥɶɡɭɸɳɢɯ COMɫɟɪɜɟɪɵ, ɩɨɞɞɟɪɠɢɜɚɸɳɢɟ ɫɨɛɵɬɢɹ. ɉɪɢɦɟɱɚɧɢɟ 5.5. Ɋɟɚɥɢɡɚɰɢɹ ɩɪɢɥɨɠɟɧɢɣ-ɤɥɢɟɧɬɨɜ ɞɥɹ COMɫɟɪɜɟɪɨɜ, ɩɨɞɞɟɪɠɢɜɚɸɳɢɯ ɫɨɛɵɬɢɹ, ɭɩɪɨɳɟɧɚ ɬɟɦ, ɱɬɨ ɫ ɩɨɦɨɳɶɸ ɞɢɚɥɨɝɨɜɨɝɨ ɨɤɧɚ ɢɦɩɨɪɬɚ ɛɢɛɥɢɨɬɟɤɢ ɬɢɩɨɜ ɦɨɠɧɨ ɫɝɟɧɟɪɢɪɨɜɚɬɶ ɤɨɦɩɨɧɟɧɬ Delphi, ɹɜɥɹɸɳɢɣɫɹ ɨɛɨɥɨɱɤɨɣ, ɩɨɞɞɟɪɠɢɜɚɸɳɟɣ ɜɫɟ ɫɜɨɣɫɬɜɚ ɢ ɦɟɬɨɞɵ ɤɨɦɩɨɧɟɧɬɚ COM-ɫɟɪɜɟɪɚ. Ⱦɥɹ ɬɨɝɨ ɱɬɨɛɵ ɨɛɪɚɛɚɬɵɜɚɬɶ ɫɨɛɵɬɢɹ ɩɨɞɤɥɸɱɟɧɧɨɝɨ ɤɨɦɩɨɧɟɧɬɚ, ɧɟɨɛɯɨɞɢɦɨ ɫɨɡɞɚɬɶ ɜ ɩɪɢɥɨɠɟɧɢɢ ɨɛɴɟɤɬ, ɩɨɞɞɟɪɠɢɜɚɸɳɢɣ ɢɧɬɟɪɮɟɣɫ, ɫɯɨɠɢɣ ɫ ɢɧɬɟɪɮɟɣɫɨɦ ɫɨɛɵɬɢɣ ɤɨɦɩɨɧɟɧɬɚ. Ɉɬɥɢɱɢɟ ɞɚɧɧɵɯ ɢɧɬɟɪɮɟɣɫɨɜ ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɬɨɦ, ɱɬɨ ɜ ɤɨɦɩɨɧɟɧɬɟ ɢɫɩɨɥɶɡɭɟɬɫɹ ɢɧɬɟɪɮɟɣɫ ɞɢɫɩɟɬɱɟɪɢɡɚɰɢɢ (dispinterface), ɚ ɜ ɩɪɢɥɨɠɟɧɢɢ – ɨɛɵɱɧɵɣ ɢɧɬɟɪɮɟɣɫ. 53
1. ɂɳɟɬɫɹ ɬɨɱɤɚ «ɜɯɨɞɚ» ɞɥɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɨɛɪɚɛɨɬɱɢɤɚ ɫɨɛɵɬɢɣ. 2. ȼ ɤɨɦɩɨɧɟɧɬ ɩɟɪɟɞɚɟɬɫɹ ɭɤɚɡɚɬɟɥɶ ɧɚ ɢɧɬɟɪɮɟɣɫ ɨɛɴɟɤɬɚ ɩɨɞɤɥɸɱɟɧɢɹ ɞɥɹ ɨɛɪɚɛɨɬɤɢ ɫɨɛɵɬɢɣ. Ɏɭɧɤɰɢɹ ESink.Advise ɜ ɩɚɪɚɦɟɬɪɟ ConnectId ɜɨɡɜɪɚɳɚɟɬ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɫɨɟɞɢɧɟɧɢɹ, ɤɨɬɨɪɵɣ ɛɭɞɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɞɥɹ ɪɚɡɪɵɜɚ ɫɜɹɡɢ ɤɥɢɟɧɬɚ ɫ ɫɟɪɜɟɪɨɦ. ɉɪɢ ɡɚɜɟɪɲɟɧɢɢ ɪɚɛɨɬɵ ɫ ɤɨɦɩɨɧɟɧɬɨɦ ɧɭɠɧɨ ɪɚɡɨɪɜɚɬɶ ɫɜɹɡɶ ɦɟɠɞɭ ɤɥɢɟɧɬɨɦ ɢ ɫɟɪɜɟɪɨɦ. Ⱦɥɹ ɷɬɢɯ ɰɟɥɟɣ ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɥɟɞɭɸɳɢɣ ɩɪɨɝɪɚɦɦɧɵɣ ɤɨɞ: with as IConnectionPointContainer do begin FindConnectionPoint(, ESink); ESink.UnAdvise(ConnectId); end; Ⱥɧɚɥɨɝɢɱɧɨ, ɤɚɤ ɢ ɩɪɢ ɩɨɞɤɥɸɱɟɧɢɢ, ɢɳɟɬɫɹ ɬɨɱɤɚ «ɜɯɨɞɚ» ɞɥɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɨɛɪɚɛɨɬɱɢɤɚ ɫɨɛɵɬɢɣ, ɡɚɬɟɦ ɜɵɡɵɜɚɟɬɫɹ ɩɪɨɰɟɞɭɪɚ ɪɚɡɪɵɜɚ ɫɨɟɞɢɧɟɧɢɹ ESink.UnAdvise, ɜ ɤɨɬɨɪɭɸ ɩɟɪɟɞɚɟɬɫɹ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɫɨɟɞɢɧɟɧɢɹ, ɩɨɥɭɱɟɧɧɵɣ ɜɨ ɜɪɟɦɹ ɩɨɞɤɥɸɱɟɧɢɹ ɤ ɫɟɪɜɟɪɭ. ɉɪɢɦɟɱɚɧɢɟ 5.7. ɇɟ ɡɚɛɵɜɚɣɬɟ ɨɬɤɥɸɱɚɬɶɫɹ ɨɬ ɫɟɪɜɟɪɨɜ, ɢɧɚɱɟ ɫɢɫɬɟɦɚ COM ɛɭɞɟɬ ɫɱɢɬɚɬɶ, ɱɬɨ ɤɨɦɩɨɧɟɧɬ COM-ɫɟɪɜɟɪɚ ɟɳɟ ɢɫɩɨɥɶɡɭɟɬɫɹ ɢ ɧɟ ɫɦɨɠɟɬ ɟɝɨ ɜɵɝɪɭɡɢɬɶ.
VI. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office ȼɨ ɦɧɨɝɢɯ ɩɪɢɥɨɠɟɧɢɹɯ, ɫɜɹɡɚɧɧɵɯ ɫ ɮɨɪɦɢɪɨɜɚɧɢɟɦ ɞɨɤɭɦɟɧɬɨɜ ɢ ɨɬɱɟɬɨɜ, ɧɟɪɟɞɤɨ ɩɪɢɦɟɧɹɸɬ ɫɟɪɜɢɫɵ, ɩɪɟɞɨɫɬɚɜɥɹɟɦɵɟ Microsoft Office. ɉɪɨɝɪɚɦɦɵ, ɩɪɟɞɨɫɬɚɜɥɹɟɦɵɟ ɜ ɞɚɧɧɨɦ ɩɚɤɟɬɟ, ɪɚɡɪɚɛɨɬɚɧɵ ɩɨ ɬɟɯɧɨɥɨ54
ɝɢɢ COM, ɱɬɨ ɨɛɟɫɩɟɱɢɜɚɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɭɩɪɚɜɥɟɧɢɹ ɞɚɧɧɵɦ ɩɪɢɥɨɠɟɧɢɟɦ ɫ ɩɨɦɨɳɶɸ ɞɪɭɝɢɯ ɩɪɢɥɨɠɟɧɢɣ ɢ ɦɚɤɪɨɹɡɵɤɨɜ. ȼɫɟ ɤɨɦɩɨɧɟɧɬɵ Microsoft Office ɩɨɞɞɟɪɠɢɜɚɸɬ ɨɞɢɧ ɢ ɬɨɬ ɠɟ ɦɚɤɪɨɹɡɵɤ: Visual Basic for Applications (VBA), ɩɨɡɜɨɥɹɸɳɢɣ ɫɨɡɞɚɜɚɬɶ ɩɪɢɥɨɠɟɧɢɹ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɜɧɭɬɪɢ ɞɨɤɭɦɟɧɬɨɜ Office (ɷɬɨ ɧɚɡɵɜɚɟɬɫɹ «ɪɟɲɟɧɢɹɦɢ ɧɚ ɛɚɡɟ Microsoft Office»). ɍɩɪɚɜɥɟɧɢɟ ɠɟ ɤɨɦɩɨɧɟɧɬɚɦɢ Office ɢɡ ɞɪɭɝɢɯ ɩɪɢɥɨɠɟɧɢɣ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɚɜɬɨɦɚɬɢɡɚɰɢɢ (Automation) – ɜɫɟ ɩɪɢɥɨɠɟɧɢɹ Microsoft Office ɹɜɥɹɸɬɫɹ ɫɟɪɜɟɪɚɦɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ (ɢɥɢ COM-ɫɟɪɜɟɪɚɦɢ). Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɬɚɤɢɯ ɩɪɢɥɨɠɟɧɢɣ ɩɪɢɝɨɞɧɵ ɥɸɛɵɟ ɫɪɟɞɫɬɜɚ ɪɚɡɪɚɛɨɬɤɢ, ɩɨɡɜɨɥɹɸɳɢɟ ɫɨɡɞɚɜɚɬɶ ɤɨɧɬɪɨɥɥɟɪɵ ɚɜɬɨɦɚɬɢɡɚɰɢɢ (COM-ɤɥɢɟɧɬɵ). ɇɚɢɛɨɥɟɟ ɱɚɫɬɨ ɞɥɹ ɷɬɨɣ ɰɟɥɢ ɢɫɩɨɥɶɡɭɟɬɫɹ Visual Basic, ɧɨ ɷɬɨ ɦɨɝɭɬ ɛɵɬɶ ɢ Delphi, C++ Builder, Visual C++ ɢ ɬ. ɩ. Ɉɞɧɚɤɨ, ɩɪɟɠɞɟ ɱɟɦ ɨɛɫɭɠɞɚɬɶ ɜɨɡɦɨɠɧɨɫɬɢ ɬɟɯ ɢɥɢ ɢɧɵɯ ɫɪɟɞɫɬɜ ɪɚɡɪɚɛɨɬɤɢ, ɫɥɟɞɭɟɬ ɪɚɡɨɛɪɚɬɶɫɹ, ɱɬɨ ɬɚɤɨɟ ɚɜɬɨɦɚɬɢɡɚɰɢɹ. ɉɪɚɤɬɢɱɟɫɤɢ ɜɫɟ, ɱɬɨ ɜ ɫɨɫɬɨɹɧɢɢ ɫɞɟɥɚɬɶ ɩɨɥɶɡɨɜɚɬɟɥɶ ɥɸɛɨɝɨ ɩɪɢɥɨɠɟɧɢɹ Microsoft Office ɫ ɩɨɦɨɳɶɸ ɦɟɧɸ, ɤɥɚɜɢɚɬɭɪɵ ɢ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɣ ɩɚɧɟɥɢ, ɦɨɠɟɬ ɛɵɬɶ ɪɟɚɥɢɡɨɜɚɧɨ ɢɡ ɩɪɢɥɨɠɟɧɢɹ, ɫɨɡɞɚɧɧɨɝɨ ɫ ɩɨɦɨɳɶɸ ɨɞɧɨɝɨ ɢɡ ɫɪɟɞɫɬɜ ɪɚɡɪɚɛɨɬɤɢ. Ɉɫɧɨɜɧɨɟ ɩɪɟɢɦɭɳɟɫɬɜɨ ɩɪɢɦɟɧɟɧɢɹ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office ɫɜɹɡɚɧɨ ɫ ɬɟɦ, ɱɬɨ ɧɟɬ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɪɚɡɪɚɛɚɬɵɜɚɬɶ ɫɨɛɫɬɜɟɧɧɵɟ ɫɪɟɞɫɬɜɚ ɮɨɪɦɢɪɨɜɚɧɢɹ ɢ ɩɪɨɫɦɨɬɪɚ ɨɬɱɟɬɨɜ. Ʉ ɬɨɦɭ ɠɟ, ɧɟɤɨɬɨɪɵɟ ɩɨɥɶɡɨɜɚɬɟɥɢ, ɩɪɢɜɵɤɲɢɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɩɪɢɥɨɠɟɧɢɹ Microsoft Office ɜ ɩɨɜɫɟɞɧɟɜɧɨɣ ɪɚɛɨɬɟ, ɩɪɟɞɩɨɱɢɬɚɸɬ ɯɪɚɧɢɬɶ ɨɬɱɟɬɵ ɢ ɞɪɭɝɢɟ ɞɨɤɭɦɟɧɬɵ ɜ ɨɞɧɨɦ ɢɡ ɮɨɪɦɚɬɨɜ Microsoft Office. ȼ ɞɚɧɧɨɣ ɝɥɚɜɟ ɩɪɢɜɟɞɟɧɨ ɨɩɢɫɚɧɢɟ ɦɟɬɨɞɢɤɢ ɪɟɚɥɢɡɚɰɢɢ ɭɩɪɚɜɥɟɧɢɹ ɩɪɢɥɨɠɟɧɢɹɦɢ Word ɢ Excel ɜ ɩɪɨɝɪɚɦɦɚɯ, ɪɚɡɪɚɛɚɬɵɜɚɟɦɵɯ ɜ ɜɢɡɭɚɥɶɧɨɣ ɫɪɟɞɟ Delphi, ɧɚ ɨɫɧɨɜɟ ɬɟɯɧɨɥɨɝɢɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ COMɩɪɢɥɨɠɟɧɢɣ. ɋɨɜɪɟɦɟɧɧɵɟ ɜɢɡɭɚɥɶɧɵɟ ɫɪɟɞɵ Delphi (ɜɟɪɫɢɢ 7 ɢ ɜɵɲɟ) ɩɨɡɜɨɥɹɸɬ ɫɨɡɞɚɜɚɬɶ ɤɨɦɩɨɧɟɧɬɵ, ɜɧɭɬɪɢ ɤɨɬɨɪɵɯ ɪɟɚɥɢɡɨɜɚɧɚ ɫɜɹɡɶ ɫ COMɫɟɪɜɟɪɚɦɢ. ɋ ɨɞɧɨɣ ɫɬɨɪɨɧɵ, ɬɚɤɨɣ ɩɨɞɯɨɞ ɤ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɸ ɩɨɡɜɨɥɹɟɬ ɢɡɛɟɠɚɬɶ ɧɟɤɨɬɨɪɵɯ ɬɪɭɞɧɨɫɬɟɣ, ɫɜɹɡɚɧɧɵɯ ɫ ɪɟɚɥɢɡɚɰɢɟɣ ɬɟɯɧɨɥɨɝɢɢ COM, ɚ ɫ ɞɪɭɝɨɣ ɫɬɨɪɨɧɵ – ɩɪɨɝɪɚɦɦɵ, ɪɟɚɥɢɡɨɜɚɧɧɵɟ ɧɚ ɬɚɤɢɯ ɤɨɦɩɨɧɟɧɬɚɯ, ɪɚɛɨɬɚɸɬ ɫɭɳɟɫɬɜɟɧɧɨ ɦɟɞɥɟɧɧɟɟ, ɱɟɦ ɬɟ, ɤɨɬɨɪɵɟ ɢɫɩɨɥɶɡɭɸɬ ɢɧɬɟɪɮɟɣɫɵ ɧɚɩɪɹɦɭɸ. Ⱦɪɭɝɢɦ ɨɬɪɢɰɚɬɟɥɶɧɵɦ ɦɨɦɟɧɬɨɦ ɹɜɥɹɟɬɫɹ ɬɨ, ɱɬɨ ɧɟɤɨɬɨɪɵɟ ɦɟɬɨɞɵ ɢɦɟɸɬ ɞɨɫɬɚɬɨɱɧɨ ɛɨɥɶɲɨɟ ɤɨɥɢɱɟɫɬɜɨ ɩɚɪɚɦɟɬɪɨɜ (ɧɚɩɪɢɦɟɪ, ɦɟɬɨɞ PrintOut ɩɪɢɥɨɠɟɧɢɹ Word ɢɦɟɟɬ ɨɤɨɥɨ ɞɜɚɞɰɚɬɢ ɩɚɪɚɦɟɬɪɨɜ), ɭɫɬɚɧɨɜɥɟɧɧɵɯ ɩɨ ɭɦɨɥɱɚɧɢɸ, ɧɨ ɜ ɩɪɨɰɟɫɫɟ ɮɨɪɦɢɪɨɜɚɧɢɹ ɤɨɦɩɨɧɟɧɬɨɜ ɜ ɫɪɟɞɟ Delphi ɞɚɧɧɵɟ ɡɧɚɱɟɧɢɹ ɬɟɪɹɸɬɫɹ ɢ ɢɯ ɜɫɟ ɪɚɜɧɨ ɩɪɢɯɨɞɢɬɫɹ ɜɜɨɞɢɬɶ. ȼɜɢɞɭ ɩɟɪɟɱɢɫɥɟɧɧɵɯ ɧɟɭɞɨɛɫɬɜ ɛɨɥɶɲɢɧɫɬɜɨ ɩɪɨɝɪɚɦɦɢɫɬɨɜ ɩɪɟɞɩɨɱɢɬɚɸɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɩɨɡɞɧɟɟ ɫɜɹɡɵɜɚɧɢɟ, ɝɞɟ ɪɟɚɥɶɧɚɹ ɫɫɵɥɤɚ ɧɚ ɨɛɴɟɤɬ ɜ ɩɟɪɟɦɟɧɧɨɣ ɢɥɢ ɤɥɚɫɫɟ ɩɨɹɜɥɹɟɬɫɹ ɧɚ ɷɬɚɩɟ ɜɵɩɨɥɧɟɧɢɹ ɩɪɢɥɨɠɟ-
ɧɢɹ-ɤɨɧɬɪɨɥɥɟɪɚ. ɏɨɬɹ ɷɬɨɬ ɫɩɨɫɨɛ ɛɨɥɟɟ ɦɟɞɥɟɧɧɵɣ, ɱɟɦ ɪɚɧɟɟ ɫɜɹɡɵɜɚɧɢɟ, ɧɨ ɨɧ ɞɨɫɬɭɩɟɧ ɜɨ ɜɫɟɯ ɫɪɟɞɫɬɜɚɯ ɪɚɡɪɚɛɨɬɤɢ, ɩɨɡɜɨɥɹɸɳɢɯ ɫɨɡɞɚɜɚɬɶ ɤɨɧɬɪɨɥɥɟɪɵ ɚɜɬɨɦɚɬɢɡɚɰɢɢ, ɢ ɦɟɧɟɟ ɱɭɜɫɬɜɢɬɟɥɟɧ ɤ ɬɨɦɭ, ɜɫɟ ɥɢ ɩɚɪɚɦɟɬɪɵ ɦɟɬɨɞɨɜ ɩɟɪɟɱɢɫɥɟɧɵ ɩɪɢ ɢɯ ɜɵɡɨɜɚɯ ɜ ɤɨɞɟ ɩɪɢɥɨɠɟɧɢɹɤɨɧɬɪɨɥɥɟɪɚ. ɉɪɢ ɩɨɡɞɧɟɦ ɫɜɹɡɵɜɚɧɢɢ ɤɨɪɪɟɤɬɧɨɫɬɶ ɜɵɡɨɜɨɜ ɦɟɬɨɞɨɜ ɩɪɨɜɟɪɹɟɬɫɹ ɜ ɦɨɦɟɧɬ ɢɯ ɨɫɭɳɟɫɬɜɥɟɧɢɹ, ɬɨ ɟɫɬɶ ɧɚ ɷɬɚɩɟ ɜɵɩɨɥɧɟɧɢɹ ɩɪɢɥɨɠɟɧɢɹ, ɚ ɧɟ ɧɚ ɷɬɚɩɟ ɟɝɨ ɤɨɦɩɢɥɹɰɢɢ. ȼɨ ɜɫɟɯ ɩɪɢɦɟɪɚɯ ɞɚɧɧɨɣ ɝɥɚɜɵ ɢɫɩɨɥɶɡɭɟɬɫɹ ɪɚɧɧɟɟ ɫɜɹɡɵɜɚɧɢɟ.
55
56
6.1. VBA ɢ ɫɪɟɞɫɬɜɚ ɪɚɡɪɚɛɨɬɤɢ ɤɨɧɬɪɨɥɥɟɪɨɜ ɚɜɬɨɦɚɬɢɡɚɰɢɢ Ʉɚɤ ɭɡɧɚɬɶ, ɤɚɤɢɟ ɨɛɴɟɤɬɵ ɞɨɫɬɭɩɧɵ ɜ ɫɟɪɜɟɪɚɯ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office? Ⱦɥɹ ɷɬɨɣ ɰɟɥɢ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɨɤɭɦɟɧɬɚɰɢɸ, ɨɩɢɫɵɜɚɸɳɭɸ ɢɯ ɨɛɴɟɤɬɧɭɸ ɦɨɞɟɥɶ [3]. Ɍɚɤɠɟ ɦɨɝɭɬ ɛɵɬɶ ɩɨɥɟɡɧɵɦɢ ɫɩɪɚɜɨɱɧɵɟ ɮɚɣɥɵ ɞɥɹ ɩɪɨɝɪɚɦɦɢɫɬɨɜ ɧɚ Visual Basic for Applications. ɂɧɨɝɞɚ ɞɥɹ ɨɫɜɨɟɧɢɹ ɨɛɴɟɤɬɧɨɣ ɦɨɞɟɥɢ ɚɜɬɨɦɚɬɢɡɢɪɭɟɦɨɝɨ ɫɟɪɜɟɪɚ ɦɨɠɧɨ ɧɚɱɚɬɶ ɫ ɡɚɩɢɫɢ ɧɟɨɛɯɨɞɢɦɨɣ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɞɟɣɫɬɜɢɣ ɜ ɜɢɞɟ ɦɚɤɪɨɫɚ ɫ ɩɨɦɨɳɶɸ VBȺ. ɋɨɡɞɚɬɶ ɦɚɤɪɨɫ ɦɨɠɧɨ, ɜɵɛɪɚɜ ɢɡ ɦɟɧɸ ɩɪɢɥɨɠɟɧɢɹ Microsoft Office ɩɭɧɤɬ Tools/Macro/Record New Macro. ɉɪɨɫɦɨɬɪ ɩɨɥɭɱɟɧɧɨɝɨ ɦɚɤɪɨɫɚ ɜ ɪɟɞɚɤɬɨɪɟ ɤɨɞɚ VBA (ɪɢɫ. 6.1) ɨɛɵɱɧɨ ɩɨɡɜɨɥɹɟɬ ɩɨɧɹɬɶ, ɤɚɤ ɞɨɥɠɟɧ ɜɵɝɥɹɞɟɬɶ ɤɨɞ, ɪɟɚɥɢɡɭɸɳɢɣ ɷɬɭ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɞɟɣɫɬɜɢɣ.
Ɋɢɫ. 6.1. Ɋɟɞɚɤɬɨɪ ɤɨɞɚ VBA
Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɱɬɨɛɵ ɭɡɧɚɬɶ, ɤɚɤ ɪɟɚɥɢɡɨɜɚɬɶ ɤɚɤɢɟ-ɥɢɛɨ ɞɟɣɫɬɜɢɹ, ɢɫɩɨɥɶɡɭɹ ɨɛɴɟɤɬɵ ɚɜɬɨɦɚɬɢɡɚɰɢɢ, ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ ɫɥɟɞɭɸɳɢɟ ɞɟɣɫɬɜɢɹ: 1) ɡɚɩɢɫɚɬɶ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɞɟɣɫɬɜɢɣ ɜ ɦɚɤɪɨɫ; 2) ɪɚɫɫɦɨɬɪɟɬɶ ɩɨɥɭɱɟɧɧɵɣ ɤɨɞ ɜ ɪɟɞɚɤɬɨɪɟ (ɪɢɫ. 1) ɢ ɩɟɪɟɜɟɫɬɢ ɟɝɨ ɧɚ ɹɡɵɤ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɤɨɬɨɪɵɣ ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɪɚɡɪɚɛɨɬɤɢ ɩɪɢɥɨɠɟɧɢɹ; 3) ɞɥɹ ɩɨɢɫɤɚ ɞɨɩɨɥɧɢɬɟɥɶɧɨɣ ɢɧɮɨɪɦɚɰɢɢ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɢɧɮɨɪɦɚɰɢɨɧɧɨ-ɫɩɪɚɜɨɱɧɭɸ ɫɢɫɬɟɦɭ MSDN [1] ɢɥɢ VBAxxx9.CHM (ɞɥɹ Microsoft Office 97 — VBxxx8.HLP ɫɨɨɬɜɟɬɫɬɜɟɧɧɨ). ɉɪɢɦɟɱɚɧɢɟ 6.1. ɉɚɪɚɦɟɬɪɵ ɧɟɤɨɬɨɪɵɯ ɮɭɧɤɰɢɣ ɫɟɪɜɟɪɨɜ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɡɚɞɚɸɬɫɹ ɜ ɜɢɞɟ ɤɨɧɫɬɚɧɬ, ɤɨɬɨɪɵɟ ɧɟ ɭɫɬɚɧɨɜɥɟɧɵ ɜ Delphi. ɑɬɨɛɵ ɩɨɥɭɱɢɬɶ ɡɧɚɱɟɧɢɟ ɬɚɤɢɯ ɤɨɧɫɬɚɧɬ ɜ VisualBasic, ɧɚɞɨ ɜɧɭɬɪɢ ɦɚɤɪɨɫɚ ɧɚɩɢɫɚɬɶ MsgBox().
6.2. Ɉɛɴɟɤɬɧɵɟ ɦɨɞɟɥɢ Microsoft Office ȼ ɨɛɴɟɤɬɧɵɯ ɦɨɞɟɥɹɯ ɜɫɟɯ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office ɜɫɟɝɞɚ ɢɦɟɟɬɫɹ ɫɚɦɵɣ ɝɥɚɜɧɵɣ ɨɛɴɟɤɬ, ɞɨɫɬɭɩɧɵɣ ɩɪɢɥɨɠɟɧɢɸ-ɤɨɧɬɪɨɥɥɟɪɭ ɢ ɩɪɟɞɫɬɚɜɥɹɸɳɢɣ ɫɚɦɨ ɚɜɬɨɦɚɬɢɡɢɪɭɟɦɨɟ ɩɪɢɥɨɠɟɧɢɟ. Ⱦɥɹ ɜɫɟɯ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office ɨɧ ɧɚɡɵɜɚɟɬɫɹ Application, ɢ ɦɧɨɝɢɟ ɟɝɨ ɫɜɨɣɫɬɜɚ ɢ ɦɟɬɨɞɵ ɞɥɹ ɜɫɟɯ ɷɬɢɯ ɩɪɢɥɨɠɟɧɢɣ ɬɚɤɠɟ ɨɞɢɧɚɤɨɜɵ. ɇɚɢɛɨɥɟɟ ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɸɬɫɹ ɫɥɟɞɭɸɳɢɟ ɢɡ ɧɢɯ. 1. ɋɜɨɣɫɬɜɨ Visible (ɞɨɫɬɭɩɧɨɟ ɞɥɹ ɨɛɴɟɤɬɚ Application ɜɫɟɯ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office) ɩɨɡɜɨɥɹɟɬ ɩɪɢɥɨɠɟɧɢɸ ɩɨɹɜɢɬɶɫɹ ɧɚ ɷɤɪɚɧɟ ɢ ɜ ɩɚɧɟɥɢ ɡɚɞɚɱ; ɨɧɨ ɩɪɢɧɢɦɚɟɬ ɡɧɚɱɟɧɢɹ True (ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɢɣ ɢɧɬɟɪɮɟɣɫ ɩɪɢɥɨɠɟɧɢɹ ɞɨɫɬɭɩɟɧ) ɢɥɢ False (ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɢɣ ɢɧɬɟɪɮɟɣɫ ɩɪɢɥɨɠɟɧɢɹ ɧɟɞɨɫɬɭɩɟɧ; ɷɬɨ ɡɧɚɱɟɧɢɟ ɭɫɬɚɧɚɜɥɢɜɚɟɬɫɹ ɩɨ ɭɦɨɥɱɚɧɢɸ). ȿɫɥɢ ɜɚɦ ɧɭɠɧɨ ɫɞɟɥɚɬɶ ɱɬɨ-ɬɨ ɫ ɞɨɤɭɦɟɧɬɨɦ Office ɜ ɮɨɧɨɜɨɦ ɪɟɠɢɦɟ, ɧɟ ɢɧɮɨɪɦɢɪɭɹ ɨɛ ɷɬɨɦ ɩɨɥɶɡɨɜɚɬɟɥɹ, ɦɨɠɧɨ ɧɟ ɨɛɪɚɳɚɬɶɫɹ ɤ ɷɬɨɦɭ ɫɜɨɣɫɬɜɭ — ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɩɪɢɥɨɠɟɧɢɟ ɦɨɠɧɨ ɛɭɞɟɬ ɧɚɣɬɢ ɬɨɥɶɤɨ ɜ ɫɩɢɫɤɟ ɩɪɨɰɟɫɫɨɜ ɫ ɩɨɦɨɳɶɸ ɩɪɢɥɨɠɟɧɢɹ Task Manager. 2. Ɇɟɬɨɞ Quit ɡɚɤɪɵɜɚɟɬ ɩɪɢɥɨɠɟɧɢɟ Office. ȼ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɬɨɝɨ, ɤɚɤɨɟ ɩɪɢɥɨɠɟɧɢɟ Office ɚɜɬɨɦɚɬɢɡɢɪɭɟɬɫɹ, ɨɧɨ ɦɨɠɟɬ ɢɦɟɬɶ ɩɚɪɚɦɟɬɪɵ ɢɥɢ ɧɟ ɢɦɟɬɶ ɬɚɤɨɜɵɯ. ɉɪɢɦɟɱɚɧɢɟ 6.2. ȼ ɧɟɤɨɬɨɪɵɯ ɩɪɨɝɪɚɦɦɚɯ ɦɟɬɨɞ Quit ɦɨɠɟɬ ɢɦɟɬɶ ɩɚɪɚɦɟɬɪɵ (ɧɚɩɪɢɦɟɪ, ɜ Microsoft Word), ɨɞɧɚɤɨ ɩɪɢ ɩɨɡɞɧɟɦ ɫɜɹɡɵɜɚɧɢɢ ɢɯ ɦɨɠɧɨ ɧɟ ɭɱɢɬɵɜɚɬɶ.
6.3. Ɉɛɳɢɟ ɩɪɢɧɰɢɩɵ ɫɨɡɞɚɧɢɹ ɤɨɧɬɪɨɥɥɟɪɨɜ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɉɪɢɥɨɠɟɧɢɟ, ɜ ɤɨɬɨɪɨɦ ɢɫɩɨɥɶɡɭɸɬɫɹ ɫɟɪɜɟɪɵ ɚɜɬɨɦɚɬɢɡɚɰɢɢ, ɞɚɥɟɟ ɛɭɞɭɬ ɧɚɡɵɜɚɬɶɫɹ ɤɨɧɬɪɨɥɥɟɪɚɦɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ. ȼ ɨɛɳɟɦ ɫɥɭɱɚɟ ɤɨɧɬɪɨɥɥɟɪ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɞɨɥɠɟɧ ɜɵɩɨɥɧɹɬɶ ɫɥɟɞɭɸɳɢɟ ɞɟɣɫɬɜɢɹ: 1) ɩɪɨɜɟɪɢɬɶ, ɡɚɩɭɳɟɧɚ ɥɢ ɤɨɩɢɹ ɩɪɢɥɨɠɟɧɢɹ-ɫɟɪɜɟɪɚ; 2) ɜ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɪɟɡɭɥɶɬɚɬɨɜ ɩɪɨɜɟɪɤɢ ɡɚɩɭɫɬɢɬɶ ɤɨɩɢɸ ɚɜɬɨɦɚɬɢɡɢɪɭɟɦɨɝɨ ɩɪɢɥɨɠɟɧɢɹ Office ɥɢɛɨ ɩɨɞɤɥɸɱɢɬɶɫɹ ɤ ɭɠɟ ɢɦɟɸɳɟɣɫɹ ɤɨɩɢɢ; 3) ɫɞɟɥɚɬɶ ɨɤɧɨ ɩɪɢɥɨɠɟɧɢɹ-ɫɟɪɜɟɪɚ ɜɢɞɢɦɵɦ (ɜ ɨɛɳɟɦ ɫɥɭɱɚɟ ɷɬɨ ɧɟ ɨɛɹɡɚɬɟɥɶɧɨ); 4) ɜɵɩɨɥɧɢɬɶ ɤɚɤɢɟ-ɬɨ ɞɟɣɫɬɜɢɹ ɫ ɩɪɢɥɨɠɟɧɢɟɦ-ɫɟɪɜɟɪɨɦ (ɧɚɩɪɢɦɟɪ, ɫɨɡɞɚɬɶ ɢɥɢ ɨɬɤɪɵɬɶ ɞɨɤɭɦɟɧɬɵ, ɢɡɦɟɧɢɬɶ ɢɯ ɞɚɧɧɵɟ, ɫɨɯɪɚɧɢɬɶ ɞɨɤɭɦɟɧɬɵ ɢ ɩɪ.); 5) ɡɚɤɪɵɬɶ ɩɪɢɥɨɠɟɧɢɟ-ɫɟɪɜɟɪ, ɟɫɥɢ ɟɝɨ ɤɨɩɢɹ ɛɵɥɚ ɡɚɩɭɳɟɧɚ ɞɚɧɧɵɦ ɤɨɧɬɪɨɥɥɟɪɨɦ, ɢɥɢ ɨɬɤɥɸɱɢɬɶɫɹ ɨɬ ɧɟɝɨ, ɟɫɥɢ ɤɨɧɬɪɨɥɥɟɪ ɩɨɞɤɥɸɱɢɥɫɹ ɤ ɭɠɟ ɢɦɟɸɳɟɣɫɹ ɤɨɩɢɢ. Ⱦɥɹ ɷɬɢɯ ɰɟɥɟɣ ɦɨɠɧɨ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɮɭɧɤɰɢɹɦɢ GetActiveOleObject ɞɥɹ ɩɨɞɤɥɸɱɟɧɢɹ ɤ ɭɠɟ ɡɚɩɭɳɟɧɧɨɣ ɤɨɩɢɢ ɩɪɢɥɨɠɟɧɢɹ-ɫɟɪɜɟɪɚ ɢ CreateOleObject ɞɥɹ ɡɚɩɭɫɤɚ ɧɨɜɨɣ, ɟɫɥɢ ɫɟɪɜɟɪ ɧɟ ɡɚɩɭɳɟɧ. ɇɚɩɪɢɦɟɪ, ɱɬɨɛɵ ɫɨɡɞɚɬɶ ɧɨɜɵɣ ɷɤɡɟɦɩɥɹɪ COM-ɫɟɪɜɟɪɚ ɩɪɢɥɨɠɟɧɢɹ Word, ɧɟɨɛɯɨɞɢɦɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɫɥɟɞɭɸɳɢɣ ɤɨɞ: App := CreateOleObject(‘App.Application’); ȼ ɪɟɡɭɥɶɬɚɬɟ ɜ ɩɟɪɟɦɟɧɧɭɸ ɜɚɪɢɚɧɬɧɨɝɨ ɬɢɩɚ App ɛɭɞɟɬ ɩɟɪɟɞɚɧ ɨɫɧɨɜɧɨɣ ɢɧɬɟɪɮɟɣɫ ɩɪɢɥɨɠɟɧɢɹ.
6.4. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ Microsoft Word ȼ ɞɚɧɧɨɦ ɪɚɡɞɟɥɟ ɦɵ ɨɛɫɭɞɢɦ ɧɚɢɛɨɥɟɟ ɱɚɫɬɨ ɜɫɬɪɟɱɚɸɳɢɟɫɹ ɡɚɞɚɱɢ, ɫɜɹɡɚɧɧɵɟ ɫ ɚɜɬɨɦɚɬɢɡɚɰɢɟɣ Microsoft Word. ɇɨ ɩɟɪɟɞ ɷɬɢɦ ɪɚɫɫɦɨɬɪɢɦ, ɤɚɤɨɜɵ ɩɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɨɫɧɨɜɧɵɯ ɨɛɴɟɤɬɨɜ Microsoft Word ɢ ɱɬɨ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɟɝɨ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ. 6.4.1. ɉɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɢ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ Microsoft Word Ⱦɥɹ ɩɪɢɥɨɠɟɧɢɹ-ɤɨɧɬɪɨɥɥɟɪɚ ɞɨɫɬɭɩɧɵ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɫɥɟɞɭɸɳɢɟ ɨɛɴɟɤɬɵ:
57
58
Ɉɛɴɟɤɬ Application Document
ɉɪɨɝɪɚɦɦɧɵɣ ɢɞɟɧɬɢɮɢɤɚɬɨɪ Word.Application, Word.Application.9 Word.Document, Word.Document.9, Word.Template.8
Ʉɨɦɦɟɧɬɚɪɢɣ ɫɨɡɞɚɟɬɫɹ ɷɤɡɟɦɩɥɹɪ Word ɛɟɡ ɨɬɤɪɵɬɵɯ ɞɨɤɭɦɟɧɬɨɜ ɫɨɡɞɚɟɬɫɹ ɷɤɡɟɦɩɥɹɪ Word ɫ ɨɞɧɢɦ ɜɧɨɜɶ ɫɨɡɞɚɧɧɵɦ ɞɨɤɭɦɟɧɬɨɦ
ȼɫɟ ɨɫɬɚɥɶɧɵɟ ɨɛɴɟɤɬɵ Word ɹɜɥɹɸɬɫɹ ɬɚɤ ɧɚɡɵɜɚɟɦɵɦɢ ɜɧɭɬɪɟɧɧɢɦɢ ɨɛɴɟɤɬɚɦɢ. ɗɬɨ ɨɡɧɚɱɚɟɬ, ɱɬɨ ɨɧɢ ɧɟ ɦɨɝɭɬ ɛɵɬɶ ɫɨɡɞɚɧɵ ɫɚɦɢ ɩɨ ɫɟɛɟ; ɬɚɤ, ɨɛɴɟɤɬ Paragraph (ɚɛɡɚɰ) ɧɟ ɦɨɠɟɬ ɛɵɬɶ ɫɨɡɞɚɧ ɨɬɞɟɥɶɧɨ ɨɬ ɫɨɞɟɪɠɚɳɟɝɨ ɟɝɨ ɞɨɤɭɦɟɧɬɚ. ȿɫɥɢ ɜɫɩɨɦɧɢɬɶ, ɱɬɨ ɨɫɧɨɜɧɨɟ ɧɚɡɧɚɱɟɧɢɟ Word — ɪɚɛɨɬɚ ɫ ɞɨɤɭɦɟɧɬɚɦɢ, ɦɨɠɧɨ ɥɟɝɤɨ ɩɨɧɹɬɶ ɢɟɪɚɪɯɢɸ ɟɝɨ ɨɛɴɟɤɬɧɨɣ ɦɨɞɟɥɢ (ɪɢɫ. 2).
6.4.2. ɋɨɡɞɚɧɢɟ ɢ ɨɬɤɪɵɬɢɟ ɞɨɤɭɦɟɧɬɨɜ Microsoft Word Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɩɪɢɦɟɪɨɜ ɢɫɩɨɥɶɡɨɜɚɧɢɹ Microsoft Word ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɨɞ ɫɨɡɞɚɧɢɹ ɤɨɧɬɪɨɥɥɟɪɚ, ɩɪɢɜɟɞɟɧɧɵɣ ɜɵɲɟ, ɢ ɦɨɞɢɮɢɰɢɪɨɜɚɬɶ ɟɝɨ, ɡɚɦɟɧɹɹ ɤɨɦɦɟɧɬɚɪɢɢ ɤɨɞɨɦ, ɦɚɧɢɩɭɥɢɪɭɸɳɢɦ ɫɜɨɣɫɬɜɚɦɢ ɢ ɦɟɬɨɞɚɦɢ ɨɛɴɟɤɬɚ Word.Application. Ɇɵ ɧɚɱɧɟɦ ɫ ɫɨɡɞɚɧɢɹ ɢ ɨɬɤɪɵɬɢɹ ɞɨɤɭɦɟɧɬɨɜ. ɋɨɡɞɚɬɶ ɧɨɜɵɣ ɞɨɤɭɦɟɧɬ Word ɦɨɠɧɨ, ɢɫɩɨɥɶɡɭɹ ɦɟɬɨɞ Add ɤɨɥɥɟɤɰɢɢ Documents ɨɛɴɟɤɬɚ Application: App.Documents.Add; ɑɬɨɛɵ ɫɨɡɞɚɬɶ ɧɟɫɬɚɧɞɚɪɬɧɵɣ ɞɨɤɭɦɟɧɬ, ɧɭɠɧɨ ɭɤɚɡɚɬɶ ɢɦɹ ɲɚɛɥɨɧɚ ɜ ɤɚɱɟɫɬɜɟ ɩɚɪɚɦɟɬɪɚ ɦɟɬɨɞɚ Add: App.Documents.Add(‘C:\Program Files\ Microsoft Office\Templates\1033\Manual.dot’); Ⱦɥɹ ɨɬɤɪɵɬɢɹ ɭɠɟ ɫɭɳɟɫɬɜɭɸɳɟɝɨ ɞɨɤɭɦɟɧɬɚ ɫɥɟɞɭɟɬ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɦɟɬɨɞɨɦ Open ɤɨɥɥɟɤɰɢɢ Documents: App.Documents.Open(‘C:\MyWordFile.doc’); Ɉɬɦɟɬɢɦ, ɱɬɨ ɫɜɨɣɫɬɜɨ ActiveDocument ɨɛɴɟɤɬɚ Word.Application ɭɤɚɡɵɜɚɟɬ ɧɚ ɬɟɤɭɳɢɣ ɚɤɬɢɜɧɵɣ ɞɨɤɭɦɟɧɬ ɫɪɟɞɢ ɨɞɧɨɝɨ ɢɥɢ ɧɟɫɤɨɥɶɤɢɯ ɨɬɤɪɵɬɵɯ. ɉɨɦɢɦɨ ɷɬɨɝɨ ɤ ɞɨɤɭɦɟɧɬɭ ɦɨɠɧɨ ɨɛɪɚɳɚɬɶɫɹ ɩɨ ɟɝɨ ɩɨɪɹɞɤɨɜɨɦɭ ɧɨɦɟɪɭ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Item; ɧɚɩɪɢɦɟɪ ɤɨ ɜɬɨɪɨɦɭ ɨɬɤɪɵɬɨɦɭ ɞɨɤɭɦɟɧɬɭ ɦɨɠɧɨ ɨɛɪɚɬɢɬɶɫɹ ɬɚɤ: App.Documents.Item(2) ɉɪɢɦɟɱɚɧɢɟ 6.3. ɇɭɦɟɪɚɰɢɹ ɱɥɟɧɨɜ ɤɨɥɥɟɤɰɢɣ ɜ Microsoft Office ɧɚɱɢɧɚɟɬɫɹ ɫ ɟɞɢɧɢɰɵ.
Ɋɢɫ. 6.2. Ɏɪɚɝɦɟɧɬ ɨɛɴɟɤɬɧɨɣ ɦɨɞɟɥɢ Microsoft Word Ɉɫɧɨɜɧɵɦ ɨɛɴɟɤɬɨɦ ɜ ɧɟɣ, ɤɚɤ ɢ ɜɨ ɜɫɟɯ ɞɪɭɝɢɯ ɩɪɢɥɨɠɟɧɢɹɯ Microsoft Office, ɹɜɥɹɟɬɫɹ ɨɛɴɟɤɬ Application, ɫɨɞɟɪɠɚɳɢɣ ɤɨɥɥɟɤɰɢɸ Documents ɨɛɴɟɤɬɨɜ ɬɢɩɚ Document. Ʉɚɠɞɵɣ ɨɛɴɟɤɬ ɬɢɩɚ Document ɫɨɞɟɪɠɢɬ ɤɨɥɥɟɤɰɢɸ Paragraphs ɨɛɴɟɤɬɨɜ ɬɢɩɚ Paragraph, Bookmarks ɬɢɩɚ Bookmark, Characters ɬɢɩɚ Character ɢ ɬ.ɞ. Ɇɚɧɢɩɭɥɹɰɢɹ ɞɨɤɭɦɟɧɬɚɦɢ, ɚɛɡɚɰɚɦɢ, ɫɢɦɜɨɥɚɦɢ, ɡɚɤɥɚɞɤɚɦɢ ɪɟɚɥɶɧɨ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɭɬɟɦ ɨɛɪɚɳɟɧɢɹ ɤ ɫɜɨɣɫɬɜɚɦ ɢ ɦɟɬɨɞɚɦ ɷɬɢɯ ɨɛɴɟɤɬɨɜ.
ɋɞɟɥɚɬɶ ɞɨɤɭɦɟɧɬ ɚɤɬɢɜɧɵɦ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Activate: App.Documents.Item(1).Activate; ɋɥɟɞɭɸɳɟɟ, ɱɟɦɭ ɫɥɟɞɭɟɬ ɧɚɭɱɢɬɶɫɹ, – ɷɬɨ ɫɨɯɪɚɧɹɬɶ ɞɨɤɭɦɟɧɬ Word ɢ ɡɚɤɪɵɜɚɬɶ ɫɚɦ Word. 6.4.3. ɋɨɯɪɚɧɟɧɢɟ, ɩɟɱɚɬɶ ɢ ɡɚɤɪɵɬɢɟ ɞɨɤɭɦɟɧɬɨɜ Microsoft Word Ɂɚɤɪɵɬɢɟ ɞɨɤɭɦɟɧɬɚ ɦɨɠɟɬ ɛɵɬɶ ɨɫɭɳɟɫɬɜɥɟɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Close: App.Documents.Item(2).Close; ɢɥɢ App.ActiveDocument.Close;
59
60
Ɇɟɬɨɞ Close ɢɦɟɟɬ ɧɟɫɤɨɥɶɤɨ ɧɟɨɛɹɡɚɬɟɥɶɧɵɯ (ɜ ɫɥɭɱɚɟ ɩɨɡɞɧɟɝɨ ɫɜɹɡɵɜɚɧɢɹ) ɩɚɪɚɦɟɬɪɨɜ, ɜɥɢɹɸɳɢɯ ɧɚ ɩɪɚɜɢɥɚ ɫɨɯɪɚɧɟɧɢɹ ɞɨɤɭɦɟɧɬɚ. ɉɟɪɜɵɣ ɢɡ ɧɢɯ ɜɥɢɹɟɬ ɧɚ ɬɨ, ɫɨɯɪɚɧɹɸɬɫɹ ɥɢ ɜɧɟɫɟɧɧɵɟ ɜ ɞɨɤɭɦɟɧɬ ɢɡɦɟɧɟɧɢɹ, ɢ ɩɪɢɧɢɦɚɟɬ ɬɪɢ ɜɨɡɦɨɠɧɵɯ ɡɧɚɱɟɧɢɹ (ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɟ ɤɨɧɫɬɚɧɬɵ ɪɟɤɨɦɟɧɞɭɟɬɫɹ ɨɩɢɫɚɬɶ ɜ ɩɪɢɥɨɠɟɧɢɢ). Ɍɪɟɬɢɣ ɩɚɪɚɦɟɬɪ ɩɪɢɧɢɦɚɟɬ ɡɧɚɱɟɧɢɹ True ɢɥɢ False ɢ ɜɥɢɹɟɬ ɧɚ ɬɨ, ɩɟɪɟɫɵɥɚɬɶ ɥɢ ɞɨɤɭɦɟɧɬ ɫɥɟɞɭɸɳɟɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɩɨ ɷɥɟɤɬɪɨɧɧɨɣ ɩɨɱɬɟ. ȿɫɥɢ ɷɬɚ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ ɧɟ ɩɪɢɦɟɧɹɟɬɫɹ, ɦɨɠɧɨ ɩɪɨɢɝɧɨɪɢɪɨɜɚɬɶ ɷɬɨɬ ɩɚɪɚɦɟɬɪ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɷɬɢɯ ɩɚɪɚɦɟɬɪɨɜ ɡɚɤɪɵɬɶ ɞɨɤɭɦɟɧɬ ɦɨɠɧɨ, ɧɚɩɪɢɦɟɪ, ɬɚɤ: App.ActiveDocument.Close(wdSaveChanges, wdPromptUser) ; ɉɪɨɫɬɨ ɫɨɯɪɚɧɢɬɶ ɞɨɤɭɦɟɧɬ, ɧɟ ɡɚɤɪɵɜɚɹ ɟɝɨ, ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Save: App.ActiveDocument.Save; ɗɬɨɬ ɦɟɬɨɞ ɬɚɤɠɟ ɢɦɟɟɬ ɧɟɫɤɨɥɶɤɨ ɧɟɨɛɹɡɚɬɟɥɶɧɵɯ (ɜ ɫɥɭɱɚɟ ɩɨɡɞɧɟɝɨ ɫɜɹɡɵɜɚɧɢɹ) ɩɚɪɚɦɟɬɪɨɜ, ɩɟɪɜɵɣ ɢɡ ɤɨɬɨɪɵɯ ɪɚɜɟɧ True, ɟɫɥɢ ɞɨɤɭɦɟɧɬ ɫɨɯɪɚɧɹɟɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ, ɢ False, ɟɫɥɢ ɧɭɠɧɨ ɜɵɜɨɞɢɬɶ ɞɢɚɥɨɝɨɜɭɸ ɩɚɧɟɥɶ ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɩɨɞɬɜɟɪɠɞɟɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɹ ɨ ɫɨɯɪɚɧɟɧɢɢ ɢɡɦɟɧɟɧɢɣ (ɟɫɥɢ ɬɚɤɨɜɵɟ ɛɵɥɢ ɫɞɟɥɚɧɵ). ȼɬɨɪɨɣ ɩɚɪɚɦɟɬɪ ɜɥɢɹɟɬ ɧɚ ɮɨɪɦɚɬ ɫɨɯɪɚɧɹɟɦɨɝɨ ɞɨɤɭɦɟɧɬɚ, ɢ ɫɩɢɫɨɤ ɟɝɨ ɜɨɡɦɨɠɧɵɯ ɡɧɚɱɟɧɢɣ ɫɨɜɩɚɞɚɟɬ ɫɨ ɫɩɢɫɤɨɦ ɡɧɚɱɟɧɢɣ ɜɬɨɪɨɝɨ ɩɚɪɚɦɟɬɪɚ ɦɟɬɨɞɚ Close. ɇɚɩɨɦɢɧɚɟɦ, ɱɬɨ ɡɚɤɪɵɬɶ ɫɚɦ Word ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Quit ɨɛɴɟɤɬɚ Word.Application. ɗɬɨɬ ɦɟɬɨɞ ɢɦɟɟɬ ɜ ɨɛɳɟɦ ɫɥɭɱɚɟ ɬɪɢ ɩɚɪɚɦɟɬɪɚ, ɫɨɜɩɚɞɚɸɳɢɯ ɫ ɩɚɪɚɦɟɬɪɚɦɢ ɦɟɬɨɞɚ Close ɨɛɴɟɤɬɚ Document. ȼɵɜɨɞ ɞɨɤɭɦɟɧɬɚ ɧɚ ɭɫɬɪɨɣɫɬɜɨ ɩɟɱɚɬɢ ɦɨɠɧɨ ɨɫɭɳɟɫɬɜɢɬɶ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ PrintOut ɨɛɴɟɤɬɚ Document, ɧɚɩɪɢɦɟɪ: App.ActiveDocument.PrintOut; ȿɫɥɢ ɧɭɠɧɨ ɢɡɦɟɧɢɬɶ ɩɚɪɚɦɟɬɪɵ ɩɟɱɚɬɢ, ɫɥɟɞɭɟɬ ɭɤɚɡɚɬɶ ɡɧɚɱɟɧɢɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɩɚɪɚɦɟɬɪɨɜ ɦɟɬɨɞɚ PrintOut (ɜ ɫɥɭɱɚɟ Microsoft Word ɢɯ ɨɤɨɥɨ ɞɜɚɞɰɚɬɢ). 6.4.4. ȼɫɬɚɜɤɚ ɬɟɤɫɬɚ ɢ ɨɛɴɟɤɬɨɜ ɜ ɞɨɤɭɦɟɧɬ ɢ ɮɨɪɦɚɬɢɪɨɜɚɧɢɟ ɬɟɤɫɬɚ Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɚɛɡɚɰɟɜ ɜ ɞɨɤɭɦɟɧɬɟ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɨɥɥɟɤɰɢɸ Paragraphs ɨɛɴɟɤɬɚ Document, ɩɪɟɞɫɬɚɜɥɹɸɳɭɸ ɧɚɛɨɪ ɚɛɡɚɰɟɜ ɞɚɧɧɨɝɨ ɞɨɤɭɦɟɧɬɚ. Ⱦɨɛɚɜɢɬɶ ɧɨɜɵɣ ɚɛɡɚɰ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Add ɷɬɨɣ ɤɨɥɥɟɤɰɢɢ: App.ActiveDocument.Paragraphs.Add; Ⱦɥɹ ɜɫɬɚɜɤɢ ɫɨɛɫɬɜɟɧɧɨ ɬɟɤɫɬɚ ɜ ɞɨɤɭɦɟɧɬ, ɬɟɦ ɧɟ ɦɟɧɟɟ, ɩɪɢɦɟɧɹɟɬɫɹ ɧɟ ɨɛɴɟɤɬ Paragraph, ɚ ɨɛɴɟɤɬ Range, ɩɪɟɞɫɬɚɜɥɹɸɳɢɣ ɥɸɛɭɸ ɧɟɩɪɟɪɵɜɧɭɸ ɱɚɫɬɶ ɞɨɤɭɦɟɧɬɚ (ɜ ɬɨɦ ɱɢɫɥɟ ɢ ɜɧɨɜɶ ɫɨɡɞɚɧɧɵɣ ɚɛɡɚɰ). ɗɬɨɬ ɨɛɴɟɤɬ ɦɨɠɟɬ ɛɵɬɶ ɫɨɡɞɚɧ ɪɚɡɧɵɦɢ ɫɩɨɫɨɛɚɦɢ. ɇɚɩɪɢɦɟɪ, ɦɨɠɧɨ ɭɤɚɡɚɬɶ 61
ɧɚɱɚɥɶɧɵɣ ɢ ɤɨɧɟɱɧɵɣ ɫɢɦɜɨɥɵ ɞɢɚɩɚɡɨɧɚ (ɟɫɥɢ ɬɚɤɨɜɵɟ ɢɦɟɸɬɫɹ ɜ ɞɨɤɭɦɟɧɬɟ): var Rng : Variant; ... Rng := App.ActiveDocument.Range(2,4); //ɫɨ 2-ɝɨ ɩɨ 4-ɣ ɫɢɦɜɨɥɵ ɢɥɢ ɭɤɚɡɚɬɶ ɧɨɦɟɪ ɚɛɡɚɰɚ (ɧɚɩɪɢɦɟɪ, ɬɨɥɶɤɨ ɱɬɨ ɫɨɡɞɚɧɧɨɝɨ): Rng:= App.ActiveDocument.Paragraphs.Item(1).Range; ɢɥɢ ɭɤɚɡɚɬɶ ɧɟɫɤɨɥɶɤɨ ɚɛɡɚɰɟɜ, ɫɥɟɞɭɸɳɢɯ ɩɨɞɪɹɞ: Rng := App.ActiveDocument.Range (App.ActiveDocument.Paragraphs.Item(3).Range.Start, App.ActiveDocument.Paragraphs.Item(5).Range.End) ȼɫɬɚɜɢɬɶ ɬɟɤɫɬ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɨɜ ɨɛɴɟɤɬɚ Range InsertBefore (ɩɟɪɟɞ ɞɢɚɩɚɡɨɧɨɦ) ɢɥɢ InsertAfter (ɩɨɫɥɟ ɞɢɚɩɚɡɨɧɚ), ɧɚɩɪɢɦɟɪ: Rng.InsertAfter(‘ɗɬɨ ɜɫɬɚɜɥɹɟɦɵɣ ɬɟɤɫɬ’); ɉɨɦɢɦɨ ɨɛɴɟɤɬɚ Range ɬɟɤɫɬ ɦɨɠɧɨ ɜɫɬɚɜɥɹɬɶ ɫ ɩɨɦɨɳɶɸ ɨɛɴɟɤɬɚ Selection, ɹɜɥɹɸɳɟɝɨɫɹ ɫɜɨɣɫɬɜɨɦ ɨɛɴɟɤɬɚ Word.Application ɢ ɩɪɟɞɫɬɚɜɥɹɸɳɟɝɨ ɫɨɛɨɣ ɜɵɞɟɥɟɧɧɭɸ ɱɚɫɬɶ ɞɨɤɭɦɟɧɬɚ (ɷɬɨɬ ɨɛɴɟɤɬ ɫɨɡɞɚɟɬɫɹ, ɟɫɥɢ ɩɨɥɶɡɨɜɚɬɟɥɶ ɜɵɞɟɥɹɟɬ ɱɚɫɬɶ ɞɨɤɭɦɟɧɬɚ ɫ ɩɨɦɨɳɶɸ ɦɵɲɢ, ɢ ɦɨɠɟɬ ɛɵɬɶ ɬɚɤɠɟ ɫɨɡɞɚɧ ɫ ɩɨɦɨɳɶɸ ɩɪɢɥɨɠɟɧɢɹ-ɤɨɧɬɪɨɥɥɟɪɚ). ɋɚɦ ɨɛɴɟɤɬ Selection ɦɨɠɧɨ ɫɨɡɞɚɬɶ, ɩɪɢɦɟɧɢɜ ɦɟɬɨɞ Select ɤ ɨɛɴɟɤɬɭ Range, ɧɚɩɪɢɦɟɪ: var Sel : Variant; ... App.ActiveDocument.Paragraphs.Item(3).Range.Select; ȼ ɩɪɢɜɟɞɟɧɧɨɦ ɜɵɲɟ ɩɪɢɦɟɪɟ ɜ ɬɟɤɭɳɟɦ ɞɨɤɭɦɟɧɬɟ ɜɵɞɟɥɹɟɬɫɹ ɬɪɟɬɢɣ ɚɛɡɚɰ. ȿɫɥɢ ɦɵ ɯɨɬɢɦ ɜɫɬɚɜɢɬɶ ɫɬɪɨɤɭ ɬɟɤɫɬɚ ɜ ɞɨɤɭɦɟɧɬ ɥɢɛɨ ɜɦɟɫɬɨ ɜɵɞɟɥɟɧɧɨɝɨ ɮɪɚɝɦɟɧɬɚ ɬɟɤɫɬɚ, ɥɢɛɨ ɩɟɪɟɞ ɧɢɦ, ɷɬɨ ɦɨɠɧɨ ɫɞɟɥɚɬɶ ɫ ɩɨɦɨɳɶɸ ɫɥɟɞɭɸɳɟɝɨ ɮɪɚɝɦɟɧɬɚ ɤɨɞɚ: var Sel : Variant; ... Sel := App.Selection; Sel.TypeText(‘ɗɬɨ ɬɟɤɫɬ, ɤɨɬɨɪɵɦ ɦɵ ɡɚɦɟɧɢɦ ɜɵɞɟɥɟɧɧɵɣ ɮɪɚɝɦɟɧɬ’); Ɉɬɦɟɬɢɦ, ɱɬɨ ɟɫɥɢ ɫɜɨɣɫɬɜɨ Options.ReplaceSelection ɨɛɴɟɤɬɚ Word.Application ɪɚɜɧɨ True, ɜɵɞɟɥɟɧɧɵɣ ɬɟɤɫɬ ɛɭɞɟɬ ɡɚɦɟɧɟɧ ɧɚ ɧɨɜɵɣ 62
ɬɟɤɫɬ (ɷɬɨɬ ɪɟɠɢɦ ɞɟɣɫɬɜɭɟɬ ɩɨ ɭɦɨɥɱɚɧɢɸ); ɟɫɥɢ ɠɟ ɧɭɠɧɨ, ɱɬɨɛɵ ɬɟɤɫɬ ɛɵɥ ɜɫɬɚɜɥɟɧ ɩɟɪɟɞ ɜɵɞɟɥɟɧɧɵɦ ɮɪɚɝɦɟɧɬɨɦ, ɚ ɧɟ ɜɦɟɫɬɨ ɧɟɝɨ, ɫɥɟɞɭɟɬ ɭɫɬɚɧɨɜɢɬɶ ɷɬɨ ɫɜɨɣɫɬɜɨ ɪɚɜɧɵɦ False: App.Options.ReplaceSelection := False; ɋɢɦɜɨɥ ɤɨɧɰɚ ɚɛɡɚɰɚ ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɨɛɴɟɤɬɚ Selection ɦɨɠɟɬ ɛɵɬɶ ɜɫɬɚɜɥɟɧ ɫ ɩɨɦɨɳɶɸ ɫɥɟɞɭɸɳɟɝɨ ɮɪɚɝɦɟɧɬɚ ɤɨɞɚ: Sel.TypeParagraph; Ʉ ɨɛɴɟɤɬɭ Selection, ɬɚɤ ɠɟ ɤɚɤ ɢ ɤ ɨɛɴɟɤɬɭ Range, ɦɨɠɧɨ ɩɪɢɦɟɧɢɬɶ ɦɟɬɨɞɵ InsertBefore ɢ InsertAfter. ȼ ɷɬɨɦ ɫɥɭɱɚɟ, ɜ ɨɬɥɢɱɢɟ ɨɬ ɩɪɟɞɵɞɭɳɟɝɨ, ɜɫɬɚɜɥɹɟɦɵɣ ɬɟɤɫɬ ɫɬɚɧɟɬ ɱɚɫɬɶɸ ɜɵɞɟɥɟɧɧɨɝɨ ɮɪɚɝɦɟɧɬɚ ɬɟɤɫɬɚ. ɋ ɩɨɦɨɳɶɸ ɨɛɴɟɤɬɚ Selection, ɢɫɩɨɥɶɡɭɹ ɟɝɨ ɫɜɨɣɫɬɜɨ Font ɢ ɫɜɨɣɫɬɜɚ ɨɛɴɟɤɬɚ Font, ɬɚɤɢɟ ɤɚɤ Bold, Italic, Size, …, ɦɨɠɧɨ ɨɬɮɨɪɦɚɬɢɪɨɜɚɬɶ ɬɟɤɫɬ. ɇɚɩɪɢɦɟɪ, ɬɚɤɢɦ ɨɛɪɚɡɨɦ ɦɨɠɧɨ ɜɫɬɚɜɢɬɶ ɫɬɪɨɤɭ, ɜɵɞɟɥɟɧɧɭɸ ɠɢɪɧɵɦ ɲɪɢɮɬɨɦ: Sel.Font.Bold := True; Sel.TypeText(‘ɗɬɨ ɬɟɤɫɬ, ɤɨɬɨɪɵɣ ɦɵ ɜɵɞɟɥɢɦ ɠɢɪɧɵɦ ɲɪɢɮɬɨɦ.’); Sel.Font.Bold := False; Sel.TypeParagraph; Ⱦɥɹ ɧɚɥɨɠɟɧɢɹ ɧɚ ɜɫɬɚɜɥɹɟɦɵɣ ɬɟɤɫɬ ɨɩɪɟɞɟɥɟɧɧɨɝɨ ɡɚɪɚɧɟɟ ɫɬɢɥɹ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɫɜɨɣɫɬɜɨ Style ɷɬɨɝɨ ɠɟ ɨɛɴɟɤɬɚ, ɧɚɩɪɢɦɟɪ: Sel.Style := ‘Heading 1’; Sel.TypeText(‘ɗɬɨ ɬɟɤɫɬ, ɤɨɬɨɪɵɣ ɫɬɚɧɟɬ ɡɚɝɨɥɨɜɤɨɦ’); Sel.TypeParagraph; ɇɟɪɟɞɤɨ ɞɨɤɭɦɟɧɬɵ Word ɫɨɞɟɪɠɚɬ ɞɚɧɧɵɟ ɞɪɭɝɢɯ ɩɪɢɥɨɠɟɧɢɣ. ɉɪɨɫɬɟɣɲɢɣ ɫɩɨɫɨɛ ɜɫɬɚɜɢɬɶ ɬɚɤɢɟ ɞɚɧɧɵɟ ɜ ɞɨɤɭɦɟɧɬ – ɢɫɩɨɥɶɡɨɜɚɬɶ ɦɟɬɨɞ Paste ɨɛɴɟɤɬɚ Range: Var Rng: Variant; ... Rng := App.Selection.Range; Rng.Collapse(wdCollapseEnd); Rng.Paste; ȿɫɬɟɫɬɜɟɧɧɨ, ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɜ ɛɭɮɟɪɟ ɨɛɦɟɧɚ ɭɠɟ ɞɨɥɠɧɵ ɫɨɞɟɪɠɚɬɶɫɹ ɜɫɬɚɜɥɹɟɦɵɟ ɞɚɧɧɵɟ. ȿɫɥɢ ɧɭɠɧɨ ɩɨɦɟɫɬɢɬɶ ɜ ɛɭɮɟɪ ɨɛɦɟɧɚ ɱɚɫɬɶ ɞɨɤɭɦɟɧɬɚ Word, ɷɬɨ ɦɨɠɧɨ ɫɞɟɥɚɬɶ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Copy ɨɛɴɟɤɬɚ Range: Var Rng: Variant; ... 63
Rng := App.Selection.Range; Rng.Copy; ɋɥɟɞɭɸɳɢɣ ɷɬɚɩ – ɩɟɪɟɦɟɳɟɧɢɟ ɤɭɪɫɨɪɚ ɜ ɧɭɠɧɨɟ ɦɟɫɬɨ ɬɟɤɫɬɚ. 6.4.5. ɉɟɪɟɦɟɳɟɧɢɟ ɤɭɪɫɨɪɚ ɩɨ ɬɟɤɫɬɭ ɂɫɩɨɥɶɡɭɹ ɦɟɬɨɞ Collapse, ɦɨɠɧɨ «ɫɠɚɬɶ» ɨɛɴɟɤɬ Range ɢɥɢ ɨɛɴɟɤɬ Selection, ɫɨɤɪɚɬɢɜ ɟɝɨ ɪɚɡɦɟɪ ɞɨ ɧɭɥɹ ɫɢɦɜɨɥɨɜ: Rng.Collapse(wdCollapseEnd); ɉɚɪɚɦɟɬɪ ɷɬɨɝɨ ɦɟɬɨɞɚ ɭɤɚɡɵɜɚɟɬ, ɜ ɧɚɱɚɥɟ ɢɥɢ ɜ ɤɨɧɰɟ ɢɫɯɨɞɧɨɝɨ ɮɪɚɝɦɟɧɬɚ ɨɤɚɠɟɬɫɹ ɧɨɜɵɣ ɨɛɴɟɤɬ Range ɢɥɢ Selection. ȿɫɥɢ ɢɫɩɨɥɶɡɭɟɬɫɹ ɩɨɡɞɧɟɟ ɫɜɹɡɵɜɚɧɢɟ, ɬɨ ɧɭɠɧɨ ɨɩɪɟɞɟɥɢɬɶ ɜ ɩɪɢɥɨɠɟɧɢɢ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɟ ɤɨɧɫɬɚɧɬɵ: const wdCollapseStart = $00000001;//ɧɨɜɵɣ ɨɛɴɟɤɬ ɧɚɯɨɞɢɬɫɹ ɜ ɧɚɱɚɥɟ ɮɪɚɝɦɟɧɬɚ wdCollapseEnd = $00000000;//ɧɨɜɵɣ ɨɛɴɟɤɬ ɧɚɯɨɞɢɬɫɹ ɜ ɤɨɧɰɟ ɮɪɚɝɦɟɧɬɚ ɉɟɪɟɦɟɳɚɬɶ ɤɭɪɫɨɪ ɩɨ ɬɟɤɫɬɭ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Move ɨɛɴɟɤɬɨɜ Range ɢ Selection. ɗɬɨɬ ɦɟɬɨɞ ɢɦɟɟɬ ɞɜɚ ɩɚɪɚɦɟɬɪɚ. ɉɟɪɜɵɣ ɭɤɚɡɵɜɚɟɬ ɧɚ ɬɨ, ɜ ɤɚɤɢɯ ɟɞɢɧɢɰɚɯ ɢɡɦɟɪɹɟɬɫɹ ɩɟɪɟɦɟɳɟɧɢɟ — ɜ ɫɢɦɜɨɥɚɯ (ɩɨ ɭɦɨɥɱɚɧɢɸ), ɫɥɨɜɚɯ, ɩɪɟɞɥɨɠɟɧɢɹɯ, ɚɛɡɚɰɚɯ ɢ ɞɪ. ȼɬɨɪɨɣ ɩɚɪɚɦɟɬɪ ɭɤɚɡɵɜɚɟɬ, ɧɚ ɫɤɨɥɶɤɨ ɟɞɢɧɢɰ ɩɪɢ ɷɬɨɦ ɧɭɠɧɨ ɩɟɪɟɦɟɫɬɢɬɶɫɹ (ɷɬɨ ɱɢɫɥɨ ɦɨɠɟɬ ɛɵɬɶ ɢ ɨɬɪɢɰɚɬɟɥɶɧɵɦ; ɩɨ ɭɦɨɥɱɚɧɢɸ ɨɧɨ ɪɚɜɧɨ 1). ɇɚɩɪɢɦɟɪ, ɫɥɟɞɭɸɳɢɣ ɮɪɚɝɦɟɧɬ ɤɨɞɚ: Rng.Move; ɩɪɢɜɟɞɟɬ ɤ ɩɟɪɟɦɟɳɟɧɢɸ ɤɭɪɫɨɪɚ ɧɚ ɨɞɢɧ ɫɢɦɜɨɥ ɜɩɟɪɟɞ, ɚ Rng.Move(wdParagraph,3); ɩɪɢɜɟɞɟɬ ɤ ɩɟɪɟɦɟɳɟɧɢɸ ɤɭɪɫɨɪɚ ɧɚ ɬɪɢ ɚɛɡɚɰɚ ɜɩɟɪɟɞ. Ɉɬɦɟɬɢɦ, ɱɬɨ ɷɬɨɬ ɦɟɬɨɞ ɢɫɩɨɥɶɡɭɟɬ ɫɥɟɞɭɸɳɢɟ ɤɨɧɫɬɚɧɬɵ: const //ȿɞɢɧɢɰɟɣ ɩɟɪɟɦɟɳɟɧɢɹ ɹɜɥɹɟɬɫɹ: wdCharacter = $00000001; //ɫɢɦɜɨɥ wdWord = $00000002; //ɫɥɨɜɨ wdSentence = $00000003; //ɩɪɟɞɥɨɠɟɧɢɟ wdParagraph = $00000004; //ɚɛɡɚɰ wdStory = $00000006; //ɱɚɫɬɶ ɞɨɤɭɦɟɧɬɚ (ɧɚɩɪ., ɤɨɥɨɧɬɢɬɭɥ, ɨɝɥɚɜɥɟɧɢɟ ɢ ɞɪ.) wdSection = $00000008; //ɪɚɡɞɟɥ wdColumn = $00000009; //ɤɨɥɨɧɤɚ ɬɚɛɥɢɰɵ wdRow = $0000000A; //ɫɬɪɨɤɚ ɬɚɛɥɢɰɵ wdCell = $0000000C; //ɹɱɟɣɤɚ ɬɚɛɥɢɰɵ wdTable = $0000000F; //ɬɚɛɥɢɰɚ 64
ɇɟɪɟɞɤɨ ɞɥɹ ɩɟɪɟɦɟɳɟɧɢɹ ɩɨ ɬɟɤɫɬɭ ɢɫɩɨɥɶɡɭɸɬɫɹ ɡɚɤɥɚɞɤɢ. ɋɨɡɞɚɬɶ ɡɚɤɥɚɞɤɭ ɜ ɬɟɤɭɳɟɣ ɩɨɡɢɰɢɢ ɤɭɪɫɨɪɚ ɦɨɠɧɨ ɩɭɬɟɦ ɞɨɛɚɜɥɟɧɢɹ ɱɥɟɧɚ ɤɨɥɥɟɤɰɢɢ Bookmarks ɨɛɴɟɤɬɚ Document c ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Add, ɭɤɚɡɚɜ ɢɦɹ ɡɚɤɥɚɞɤɢ ɜ ɤɚɱɟɫɬɜɟ ɩɚɪɚɦɟɬɪɚ, ɧɚɩɪɢɦɟɪ: App.ActiveDocument.Bookmarks.Add(‘MyBookmark’); ɉɪɨɜɟɪɢɬɶ ɫɭɳɟɫɬɜɨɜɚɧɢɟ ɡɚɤɥɚɞɤɢ ɜ ɞɨɤɭɦɟɧɬɟ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Exists, ɚ ɩɟɪɟɦɟɫɬɢɬɶɫɹ ɧɚ ɧɟɟ – ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Goto ɨɛɴɟɤɬɨɜ Document, Range ɢɥɢ Selection: Rng := App.ActiveDocument.Goto(wdGoToBookmark, wdGoToNext, ,‘MyBookmark’); Rng.InsertAfter(‘Ɍɟɤɫɬ, ɜɫɬɚɜɥɟɧɧɵɣ ɩɨɫɥɟ ɡɚɤɥɚɞɤɢ’); Ɂɧɚɱɟɧɢɹ ɤɨɧɫɬɚɧɬ ɞɥɹ ɷɬɨɝɨ ɩɪɢɦɟɪɚ ɬɚɤɨɜɵ: const wdGoToBookmark = $FFFFFFFF; //ɩɟɪɟɣɬɢ ɤ ɡɚɤɥɚɞɤɟ wdGoToNext = $00000002; //ɢɫɤɚɬɶ ɫɥɟɞɭɸɳɢɣ ɨɛɴɟɤɬ ɜ ɬɟɤɫɬɟ Ɉɬɦɟɬɢɦ, ɱɬɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Goto ɦɨɠɧɨ ɩɟɪɟɦɟɳɚɬɶɫɹ ɧɟ ɬɨɥɶɤɨ ɧɚ ɭɤɚɡɚɧɧɭɸ ɡɚɤɥɚɞɤɭ, ɧɨ ɢ ɧɚ ɞɪɭɝɢɟ ɨɛɴɟɤɬɵ (ɪɢɫɭɧɤɢ, ɝɪɚɦɦɚɬɢɱɟɫɤɢɟ ɨɲɢɛɤɢ ɢ ɞɪ.), ɢ ɧɚɩɪɚɜɥɟɧɢɟ ɩɟɪɟɦɟɳɟɧɢɹ ɬɨɠɟ ɦɨɠɟɬ ɛɵɬɶ ɪɚɡɥɢɱɧɵɦ. ɉɨɷɬɨɦɭ ɫɩɢɫɨɤ ɤɨɧɫɬɚɧɬ, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɛɵɬɶ ɢɫɩɨɥɶɡɨɜɚɧɵ ɜ ɤɚɱɟɫɬɜɟ ɩɚɪɚɦɟɬɪɨɜ ɞɚɧɧɨɝɨ ɦɟɬɨɞɚ, ɞɨɜɨɥɶɧɨ ɜɟɥɢɤ.
Rng.InsertAfter(‘4,5,6’); Rng.InsertParagraphAfter; Rng.InsertAfter(‘7,8,9’); Rng.InsertParagraphAfter; Rng.ConvertToTable(‘,’); ȼɧɟɲɧɢɣ ɜɢɞ ɬɚɛɥɢɰɵ ɦɨɠɧɨ ɢɡɦɟɧɢɬɶ ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜɚ Format, ɚ ɬɚɤɠɟ ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜ ɤɨɥɥɟɤɰɢɢ Columns, ɩɪɟɞɫɬɚɜɥɹɸɳɟɣ ɤɨɥɨɧɤɢ ɬɚɛɥɢɰɵ, ɢ ɤɨɥɥɟɤɰɢɢ Rows, ɩɪɟɞɫɬɚɜɥɹɸɳɟɣ ɫɬɪɨɤɢ ɬɚɛɥɢɰɵ ɨɛɴɟɤɬɚ Table. 6.4.7. Ɉɛɪɚɳɟɧɢɟ ɤ ɫɜɨɣɫɬɜɚɦ ɞɨɤɭɦɟɧɬɚ ɋɜɨɣɫɬɜɚ ɞɨɤɭɦɟɧɬɚ ɦɨɠɧɨ ɩɨɥɭɱɢɬɶ ɫ ɩɨɦɨɳɶɸ ɤɨɥɥɟɤɰɢɢ BuiltInDocumentProperties ɨɛɴɟɤɬɚ Document, ɧɚɩɪɢɦɟɪ: Memo1.Lines.Add(‘ɇɚɡɜɚɧɢɟ ‘+App.ActiveDocument.BuiltInDocumentProperties [wdPropertyTitle].Value); Memo1.Lines.Add(‘Ⱥɜɬɨɪ ‘+App.ActiveDocument.BuiltInDocumentProperties [wdPropertyAuthor].Value); Memo1.Lines.Add(‘ɒɚɛɥɨɧ ‘+App.ActiveDocument.BuiltInDocumentProperties [wdPropertyTemplate].Value);
6.4.6. ɋɨɡɞɚɧɢɟ ɬɚɛɥɢɰ ɋɨɡɞɚɜɚɬɶ ɬɚɛɥɢɰɵ ɦɨɠɧɨ ɞɜɭɦɹ ɫɩɨɫɨɛɚɦɢ. ɉɟɪɜɵɣ ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɜɵɡɨɜɟ ɦɟɬɨɞɚ Add ɤɨɥɥɟɤɰɢɢ Tables ɨɛɴɟɤɬɚ Document ɢ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɦ ɡɚɩɨɥɧɟɧɢɢ ɹɱɟɟɤ ɞɚɧɧɵɦɢ. ɗɬɨɬ ɫɩɨɫɨɛ ɩɪɢ ɩɨɡɞɧɟɦ ɫɜɹɡɵɜɚɧɢɢ ɪɚɛɨɬɚɟɬ ɞɨɜɨɥɶɧɨ ɦɟɞɥɟɧɧɨ. ȼɬɨɪɨɣ ɫɩɨɫɨɛ, ɧɚɦɧɨɝɨ ɛɨɥɟɟ «ɛɵɫɬɪɵɣ», ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɫɨɡɞɚɧɢɢ ɬɟɤɫɬɚ ɢɡ ɧɟɫɤɨɥɶɤɢɯ ɫɬɪɨɤ, ɫɨɞɟɪɠɚɳɢɯ ɩɨɞɫɬɪɨɤɢ ɫ ɪɚɡɞɟɥɢɬɟɥɹɦɢ (ɜ ɤɚɱɟɫɬɜɟ ɪɚɡɞɟɥɢɬɟɥɹ ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɥɸɛɨɣ ɢɥɢ ɩɨɱɬɢ ɥɸɛɨɣ ɫɢɦɜɨɥ, ɧɭɠɧɨ ɬɨɥɶɤɨ, ɱɬɨɛɵ ɨɧ ɡɚɜɟɞɨɦɨ ɧɟ ɜɫɬɪɟɱɚɥɫɹ ɜ ɞɚɧɧɵɯ, ɤɨɬɨɪɵɟ ɛɭɞɭɬ ɩɨɦɟɳɟɧɵ ɜ ɛɭɞɭɳɭɸ ɬɚɛɥɢɰɭ), ɢ ɩɨɫɥɟɞɭɸɳɟɣ ɤɨɧɜɟɪɬɚɰɢɢ ɬɚɤɨɝɨ ɬɟɤɫɬɚ ɜ ɬɚɛɥɢɰɭ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ ConvertToTable ɨɛɴɟɤɬɚ Range. ɇɢɠɟ ɩɪɢɜɟɞɟɧ ɩɪɢɦɟɪ ɫɨɡɞɚɧɢɹ ɬɚɛɥɢɰɵ ɢɡ ɬɪɟɯ ɫɬɪɨɤ ɢ ɬɪɟɯ ɫɬɨɥɛɰɨɜ ɷɬɢɦ ɫɩɨɫɨɛɨɦ (ɜ ɤɚɱɟcɬɜɟ ɪɚɡɞɟɥɢɬɟɥɹ, ɹɜɥɹɸɳɟɝɨɫɹ ɩɟɪɜɵɦ ɩɚɪɚɦɟɬɪɨɦ ɦɟɬɨɞɚ ConvertToTable, ɢɫɩɨɥɶɡɭɟɬɫɹ ɡɚɩɹɬɚɹ): Var Rng: Variant; ... Rng := App.Selection.Range; Rng.Collapse(wdCollapseEnd); Rng.InsertAfter(‘1, 2, 3’); Rng.InsertParagraphAfter; 65
ȼ ɞɚɧɧɨɦ ɪɚɡɞɟɥɟ ɩɪɢɜɟɞɟɧɵ ɨɫɧɨɜɧɵɟ ɨɩɟɪɚɰɢɢ, ɤɨɬɨɪɵɟ ɧɚɢɛɨɥɟɟ ɱɚɫɬɨ ɩɪɢɦɟɧɹɸɬɫɹ ɩɪɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ Microsoft Word. ȿɫɬɟɫɬɜɟɧɧɨ, ɜɨɡɦɨɠɧɨɫɬɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ Word ɞɚɥɟɤɨ ɧɟ ɢɫɱɟɪɩɵɜɚɸɬɫɹ ɩɪɢɜɟɞɟɧɧɵɦɢ ɩɪɢɦɟɪɚɦɢ, ɨɞɧɚɤɨ, ɪɭɤɨɜɨɞɫɬɜɭɹɫɶ ɨɫɧɨɜɧɵɦɢ ɩɪɢɧɰɢɩɚɦɢ ɫɨɡɞɚɧɢɹ ɤɨɧɬɪɨɥɥɟɪɨɜ Word, ɢɡɥɨɠɟɧɧɵɦɢ ɜ ɞɚɧɧɨɣ ɝɥɚɜɟ, ɢ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɣ ɫɩɪɚɜɨɱɧɨɣ ɢɧɮɨɪɦɚɰɢɟɣ [Ɉɲɢɛɤɚ! ɂɫɬɨɱɧɢɤ ɫɫɵɥɤɢ ɧɟ ɧɚɣɞɟɧ.], ɦɨɠɧɨ ɢɦɢ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨ.
6.5. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ Microsoft Excel ȼ ɞɚɧɧɨɦ ɪɚɡɞɟɥɟ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɧɚɢɛɨɥɟɟ ɱɚɫɬɨ ɜɫɬɪɟɱɚɸɳɢɟɫɹ ɡɚɞɚɱɢ, ɫɜɹɡɚɧɧɵɟ ɫ ɚɜɬɨɦɚɬɢɡɚɰɢɟɣ Microsoft Excel. ɇɨ ɩɟɪɟɞ ɷɬɢɦ ɪɚɫɫɦɨɬɪɢɦ, ɤɚɤɨɜɵ ɩɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɨɫɧɨɜɧɵɯ ɨɛɴɟɤɬɨɜ Microsoft Excel ɢ ɱɬɨ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɟɝɨ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ. 6.5.1. ɉɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɢ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ Microsoft Excel ɋɭɳɟɫɬɜɭɟɬ ɬɪɢ ɬɢɩɚ ɨɛɴɟɤɬɨɜ Excel, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɛɵɬɶ ɫɨɡɞɚɧɵ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɫ ɩɨɦɨɳɶɸ ɩɪɢɥɨɠɟɧɢɹ-ɤɨɧɬɪɨɥɥɟɪɚ. ɗɬɢ ɨɛɴɟɤɬɵ ɢ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɟ ɢɦ ɩɪɨɝɪɚɦɦɧɵɟ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɩɟɪɟɱɢɫɥɟɧɵ ɧɢɠɟ. 66
Ɉɛɴɟɤɬ
ɉɪɨɝɪɚɦɦɧɵɣ ɢɞɟɧɬɢɮɢɤɚɬɨɪ
Application
Excel.Application, Excel.Application.9
WorkBook
Excel.AddIn
Chart
Excel.Chart, Excel.Chart.8
WorkSheet
Excel.Sheet, Excel.Sheet.8
Ʉɨɦɦɟɧɬɚɪɢɣ ɋ ɩɨɦɨɳɶɸ ɷɬɨɝɨ ɩɪɨɝɪɚɦɦɧɨɝɨ ɢɞɟɧɬɢɮɢɤɚɬɨɪɚ ɫɨɡɞɚɟɬɫɹ ɷɤɡɟɦɩɥɹɪ ɩɪɢɥɨɠɟɧɢɹ ɛɟɡ ɨɬɤɪɵɬɵɯ ɪɚɛɨɱɢɯ ɤɧɢɝ ɋ ɩɨɦɨɳɶɸ ɷɬɨɝɨ ɩɪɨɝɪɚɦɦɧɨɝɨ ɢɞɟɧɬɢɮɢɤɚɬɨɪɚ ɫɨɡɞɚɟɬɫɹ ɷɤɡɟɦɩɥɹɪ ɪɚɫɲɢɪɟɧɢɹ (add-in) Excel (ɢɦɟɸɳɢɟɫɹ ɪɚɫɲɢɪɟɧɢɹ ɞɨɫɬɭɩɧɵ ɫ ɩɨɦɨɳɶɸ ɩɭɧɤɬɚ ɦɟɧɸ Tools/Add-Ins) Ɋɚɛɨɱɚɹ ɤɧɢɝɚ, ɫɨɡɞɚɧɧɚɹ ɫ ɩɨɦɨɳɶɸ ɷɬɢɯ ɩɪɨɝɪɚɦɦɧɵɯ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɜ, ɫɨɫɬɨɢɬ ɢɡ ɞɜɭɯ ɥɢɫɬɨɜ – ɨɞɧɨɝɨ ɞɥɹ ɞɢɚɝɪɚɦɦɵ, ɞɪɭɝɨɝɨ – ɞɥɹ ɞɚɧɧɵɯ, ɧɚ ɨɫɧɨɜɟ ɤɨɬɨɪɵɯ ɨɧɚ ɩɨɫɬɪɨɟɧɚ Ɋɚɛɨɱɚɹ ɤɧɢɝɚ, ɫɨɡɞɚɧɧɚɹ ɫ ɩɨɦɨɳɶɸ ɷɬɢɯ ɩɪɨɝɪɚɦɦɧɵɯ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɜ, ɫɨɫɬɨɢɬ ɢɡ ɨɞɧɨɝɨ ɥɢɫɬɚ
ȼɫɟ ɨɫɬɚɥɶɧɵɟ ɨɛɴɟɤɬɵ Excel ɹɜɥɹɸɬɫɹ ɜɧɭɬɪɟɧɧɢɦɢ ɨɛɴɟɤɬɚɦɢ ɢ ɫɭɳɟɫɬɜɨɜɚɬɶ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨ ɧɟ ɦɨɝɭɬ. Ɉɫɧɨɜɧɵɦ ɜ ɨɛɴɟɤɬɧɨɣ ɦɨɞɟɥɢ Excel ɹɜɥɹɟɬɫɹ ɨɛɴɟɤɬ Application, ɫɨɞɟɪɠɚɳɢɣ ɤɨɥɥɟɤɰɢɸ Workbooks ɨɛɴɟɤɬɨɜ ɬɢɩɚ WorkBook (ɪɢɫ. 3).
Ʉɚɠɞɵɣ ɨɛɴɟɤɬ ɬɢɩɚ WorkBook ɫɨɞɟɪɠɢɬ ɤɨɥɥɟɤɰɢɸ WorkSheetsɨɛɴɟɤɬɨɜ ɬɢɩɚ WorkSheet, Charts ɬɢɩɚ Chart ɢ ɞɪ. Ɇɚɧɢɩɭɥɹɰɢɹ ɪɚɛɨɱɢɦɢ ɤɧɢɝɚɦɢ, ɢɯ ɥɢɫɬɚɦɢ, ɹɱɟɣɤɚɦɢ, ɞɢɚɝɪɚɦɦɚɦɢ ɪɟɚɥɶɧɨ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɭɬɟɦ ɨɛɪɚɳɟɧɢɹ ɤ ɫɜɨɣɫɬɜɚɦ ɢ ɦɟɬɨɞɚɦ ɷɬɢɯ ɨɛɴɟɤɬɨɜ. Ɋɚɫɫɦɨɬɪɢɦ ɧɚɢɛɨɥɟɟ ɱɚɫɬɨ ɜɫɬɪɟɱɚɸɳɢɟɫɹ ɡɚɞɚɱɢ, ɫɜɹɡɚɧɧɵɟ ɫ ɚɜɬɨɦɚɬɢɡɚɰɢɟɣ Microsoft Excel. 6.5.2. Ɂɚɩɭɫɤ Microsoft Excel, ɫɨɡɞɚɧɢɟ ɢ ɨɬɤɪɵɬɢɟ ɪɚɛɨɱɢɯ ɤɧɢɝ Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɩɪɢɦɟɪɨɜ ɢɫɩɨɥɶɡɨɜɚɧɢɹ Microsoft Excel ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɮɭɧɤɰɢɸ CreateOleObject: App := CreateOleObject(‘Excel.Application’); ɋɨɡɞɚɬɶ ɧɨɜɭɸ ɪɚɛɨɱɭɸ ɤɧɢɝɭ Excel ɦɨɠɧɨ, ɢɫɩɨɥɶɡɭɹ ɦɟɬɨɞ Add ɤɨɥɥɟɤɰɢɢ Workbooks ɨɛɴɟɤɬɚ Application: App.WorkBooks.Add; Ⱦɥɹ ɫɨɡɞɚɧɢɹ ɪɚɛɨɱɟɣ ɤɧɢɝɢ ɧɚ ɨɫɧɨɜɟ ɲɚɛɥɨɧɚ ɫɥɟɞɭɟɬ ɭɤɚɡɚɬɶ ɟɝɨ ɢɦɹ ɜ ɤɚɱɟɫɬɜɟ ɩɟɪɜɨɝɨ ɩɚɪɚɦɟɬɪɚ ɦɟɬɨɞɚ Add: App.WorkBooks.Add (‘C:\Program Files\Microsoft Office\Templates\1033\invoice.xlt’); ȼ ɤɚɱɟɫɬɜɟ ɩɟɪɜɨɝɨ ɩɚɪɚɦɟɬɪɚ ɷɬɨɝɨ ɦɟɬɨɞɚ ɦɨɠɧɨ ɬɚɤɠɟ ɢɫɩɨɥɶɡɨɜɚɬɶ ɫɥɟɞɭɸɳɢɟ ɤɨɧɫɬɚɧɬɵ: const xlWBATChart = $FFFFEFF3; //ɪɚɛɨɱɚɹ ɤɧɢɝɚ ɫɨɫɬɨɢɬ ɢɡ ɥɢɫɬɚ ɫ ɞɢɚɝɪɚɦɦɨɣ xlWBATWorksheet = $FFFFEFB9; //ɪɚɛɨɱɚɹ ɤɧɢɝɚ ɫɨɫɬɨɢɬ ɢɡ ɥɢɫɬɚ ɫ ɞɚɧɧɵɦɢ ȼ ɷɬɨɦ ɫɥɭɱɚɟ ɪɚɛɨɱɚɹ ɤɧɢɝɚ ɛɭɞɟɬ ɫɨɞɟɪɠɚɬɶ ɨɞɢɧ ɥɢɫɬ ɬɢɩɚ, ɡɚɞɚɧɧɨɝɨ ɭɤɚɡɚɧɧɨɣ ɤɨɧɫɬɚɧɬɨɣ (ɝɪɚɮɢɤ, ɨɛɵɱɧɵɣ ɥɢɫɬ ɫ ɞɚɧɧɵɦɢ ɢ ɞɪ.) Ⱦɥɹ ɨɬɤɪɵɬɢɹ ɭɠɟ ɫɭɳɟɫɬɜɭɸɳɟɝɨ ɞɨɤɭɦɟɧɬɚ ɫɥɟɞɭɟɬ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɦɟɬɨɞɨɦ Open ɤɨɥɥɟɤɰɢɢ WorkBooks: App.Documents.Open(‘C:\MyExcelFile.xls’);
Ɋɢɫ. 6.3. Ɏɪɚɝɦɟɧɬ ɨɛɴɟɤɬɧɨɣ ɦɨɞɟɥɢ Microsoft Excel
67
Ɉɬɦɟɬɢɦ, ɱɬɨ ɫɜɨɣɫɬɜɨ ActiveWorkBook ɨɛɴɟɤɬɚ Excel.Application ɭɤɚɡɵɜɚɟɬ ɧɚ ɬɟɤɭɳɭɸ ɚɤɬɢɜɧɭɸ ɪɚɛɨɱɭɸ ɤɧɢɝɭ ɫɪɟɞɢ ɨɞɧɨɣ ɢɥɢ ɧɟɫɤɨɥɶɤɢɯ ɨɬɤɪɵɬɵɯ. ɉɨɦɢɦɨ ɷɬɨɝɨ ɤ ɪɚɛɨɱɟɣ ɤɧɢɝɟ ɦɨɠɧɨ ɨɛɪɚɳɚɬɶɫɹ ɩɨ ɟɟ ɩɨɪɹɞɤɨɜɨɦɭ ɧɨɦɟɪɭ, ɧɚɩɪɢɦɟɪ ɤɨ ɜɬɨɪɨɣ ɨɬɤɪɵɬɨɣ ɪɚɛɨɱɟɣ ɤɧɢɝɟ ɦɨɠɧɨ ɨɛɪɚɬɢɬɶɫɹ ɬɚɤ: App.WorkBooks[2]
68
Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ ɧɚ ɬɨ, ɱɬɨ ɜ Delphi ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɩɨɡɞɧɟɝɨ ɫɜɹɡɵɜɚɧɢɹ ɫɢɧɬɚɤɫɢɫ, ɢɫɩɨɥɶɡɭɟɦɵɣ ɞɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɱɥɟɧɚɦ ɤɨɥɥɟɤɰɢɣ ɨɛɴɟɤɬɨɜ Excel, ɨɬɥɢɱɟɧ ɨɬ ɫɢɧɬɚɤɫɢɫɚ, ɢɫɩɨɥɶɡɭɟɦɨɝɨ ɞɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɨɛɴɟɤɬɚɦ Word – ɜ ɫɥɭɱɚɟ Word ɦɵ ɢɫɩɨɥɶɡɨɜɚɥɢ ɦɟɬɨɞ Item, ɚ ɜ ɫɥɭɱɚɟ Excel ɦɵ ɨɛɪɚɳɚɟɦɫɹ ɤ ɱɥɟɧɚɦ ɤɨɥɥɟɤɰɢɢ ɤɚɤ ɤ ɷɥɟɦɟɧɬɚɦ ɦɚɫɫɢɜɚ. ȿɫɥɢ ɠɟ ɜɵ ɢɫɩɨɥɶɡɭɟɬɟ Visual Basic, ɫɢɧɬɚɤɫɢɫ, ɩɪɢɦɟɧɹɟɦɵɣ ɞɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɱɥɟɧɚɦ ɤɨɥɥɟɤɰɢɣ, ɛɭɞɟɬ ɨɞɢɧɚɤɨɜ ɞɥɹ ɜɫɟɯ ɤɨɥɥɟɤɰɢɣ Microsoft Office. ɋɞɟɥɚɬɶ ɪɚɛɨɱɭɸ ɤɧɢɝɭ ɚɤɬɢɜɧɨɣ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Activate: App.WorkBooks[2].Activate; Ɋɚɫɫɦɨɬɪɢɦ ɞɚɥɟɟ ɫɨɯɪɚɧɟɧɢɟ ɪɚɛɨɱɢɯ ɤɧɢɝ ɜ ɮɚɣɥɚɯ. 6.5.3. ɋɨɯɪɚɧɟɧɢɟ, ɩɟɱɚɬɶ ɢ ɡɚɤɪɵɬɢɟ ɪɚɛɨɱɢɯ ɤɧɢɝ Microsoft Excel Ɂɚɤɪɵɬɢɟ ɞɨɤɭɦɟɧɬɚ ɦɨɠɟɬ ɛɵɬɶ ɨɫɭɳɟɫɬɜɥɟɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Close: App.WorkBooks[2].Close;
ȼɵɜɨɞ ɞɨɤɭɦɟɧɬɚ Excel ɧɚ ɭɫɬɪɨɣɫɬɜɨ ɩɟɱɚɬɢ ɦɨɠɧɨ ɨɫɭɳɟɫɬɜɢɬɶ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ PrintOut ɨɛɴɟɤɬɚ WorkBook, ɧɚɩɪɢɦɟɪ: App.ActiveWorkBook.PrintOut; ȿɫɥɢ ɧɭɠɧɨ ɢɡɦɟɧɢɬɶ ɩɚɪɚɦɟɬɪɵ ɩɟɱɚɬɢ, ɫɥɟɞɭɟɬ ɭɤɚɡɚɬɶ ɡɧɚɱɟɧɢɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɩɚɪɚɦɟɬɪɨɜ ɦɟɬɨɞɚ PrintOut (ɜ ɫɥɭɱɚɟ Excel ɢɯ ɜɨɫɟɦɶ). 6.5.4. Ɉɛɪɚɳɟɧɢɟ ɤ ɥɢɫɬɚɦ ɢ ɹɱɟɣɤɚɦ Ɉɛɪɚɳɟɧɢɟ ɤ ɥɢɫɬɚɦ ɪɚɛɨɱɟɣ ɤɧɢɝɢ ɩɪɨɢɡɜɨɞɢɬɫɹ ɫ ɩɨɦɨɳɶɸ ɤɨɥɥɟɤɰɢɢ WorkSheets ɨɛɴɟɤɬɚ WorkBook. Ʉɚɠɞɵɣ ɱɥɟɧ ɷɬɨɣ ɤɨɥɥɟɤɰɢɢ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɨɛɴɟɤɬ WorkSheet. Ʉ ɱɥɟɧɭ ɷɬɨɣ ɤɨɥɥɟɤɰɢɢ ɦɨɠɧɨ ɨɛɪɚɬɢɬɶɫɹ ɩɨ ɟɝɨ ɩɨɪɹɞɤɨɜɨɦɭ ɧɨɦɟɪɭ, ɧɚɩɪɢɦɟɪ: App.WorkBooks[1].WorkSheets[1].Name := ‘ɋɬɪɚɧɢɰɚ 1’; ɉɪɢɜɟɞɟɧɧɵɣ ɜɵɲɟ ɩɪɢɦɟɪ ɢɥɥɸɫɬɪɢɪɭɟɬ, ɤɚɤ ɦɨɠɧɨ ɢɡɦɟɧɢɬɶ ɢɦɹ ɥɢɫɬɚ ɪɚɛɨɱɟɣ ɤɧɢɝɢ. Ʉ ɥɢɫɬɭ ɪɚɛɨɱɟɣ ɤɧɢɝɢ ɦɨɠɧɨ ɨɛɪɚɬɢɬɶɫɹ ɢ ɩɨ ɢɦɟɧɢ, ɧɚɩɪɢɦɟɪ: App.WorkBooks[1].WorkSheets[‘Sheet1’].Name := ‘ɋɬɪɚɧɢɰɚ 1’;
ɢɥɢ App.ActiveWorkBook.Close; Ɇɟɬɨɞ Close ɢɦɟɟɬ ɧɟɫɤɨɥɶɤɨ ɧɟɨɛɹɡɚɬɟɥɶɧɵɯ (ɜ ɫɥɭɱɚɟ ɩɨɡɞɧɟɝɨ ɫɜɹɡɵɜɚɧɢɹ) ɩɚɪɚɦɟɬɪɨɜ, ɜɥɢɹɸɳɢɯ ɧɚ ɩɪɚɜɢɥɚ ɫɨɯɪɚɧɟɧɢɹ ɪɚɛɨɱɟɣ ɤɧɢɝɢ. ɉɟɪɜɵɣ ɢɡ ɩɚɪɚɦɟɬɪɨɜ ɩɪɢɧɢɦɚɟɬ ɡɧɚɱɟɧɢɹ True ɢɥɢ False ɢ ɜɥɢɹɟɬ ɧɚ ɬɨ, ɫɨɯɪɚɧɹɬɶ ɥɢ ɢɡɦɟɧɟɧɢɹ, ɜɧɟɫɟɧɧɵɟ ɜ ɪɚɛɨɱɭɸ ɤɧɢɝɭ. ȼɬɨɪɨɣ ɩɚɪɚɦɟɬɪ (ɬɢɩɚ Variant) — ɢɦɹ ɮɚɣɥɚ, ɜ ɤɨɬɨɪɨɦ ɧɭɠɧɨ ɫɨɯɪɚɧɢɬɶ ɪɚɛɨɱɭɸ ɤɧɢɝɭ (ɟɫɥɢ ɜ ɧɟɟ ɛɵɥɢ ɜɧɟɫɟɧɵ ɢɡɦɟɧɟɧɢɹ). Ɍɪɟɬɢɣ ɩɚɪɚɦɟɬɪ, ɬɚɤɠɟ ɩɪɢɧɢɦɚɸɳɢɣ ɡɧɚɱɟɧɢɹ True ɢɥɢ False, ɜɥɢɹɟɬ ɧɚ ɬɨ, ɫɥɟɞɭɟɬ ɥɢ ɩɟɪɟɫɵɥɚɬɶ ɞɨɤɭɦɟɧɬ ɫɥɟɞɭɸɳɟɦɭ ɩɨɥɶɡɨɜɚɬɟɥɸ ɩɨ ɷɥɟɤɬɪɨɧɧɨɣ ɩɨɱɬɟ, ɢ ɦɨɠɟɬ ɛɵɬɶ ɩɪɨɢɝɧɨɪɢɪɨɜɚɧ, ɟɫɥɢ ɷɬɚ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ ɧɟ ɢɫɩɨɥɶɡɭɟɬɫɹ: App.ActiveWorkBook.Close(True,’C:\MyWorkBook.xls’); ɉɪɨɫɬɨ ɫɨɯɪɚɧɢɬɶ ɪɚɛɨɱɭɸ ɤɧɢɝɭ, ɧɟ ɡɚɤɪɵɜɚɹ ɟɟ, ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɨɜ Save ɢɥɢ SaveAs: App.ActiveWorkBook.Save; ɢɥɢ App.ActiveWorkBook.SaveAs(‘C:\MyWorkBook.xls’); Ɇɟɬɨɞ SaveAs ɢɦɟɟɬ ɛɨɥɟɟ ɞɟɫɹɬɤɚ ɩɚɪɚɦɟɬɪɨɜ, ɜɥɢɹɸɳɢɯ ɧɚ ɬɨ, ɤɚɤ ɢɦɟɧɧɨ ɫɨɯɪɚɧɹɟɬɫɹ ɞɨɤɭɦɟɧɬ (ɩɨɞ ɤɚɤɢɦ ɢɦɟɧɟɦ, ɫ ɩɚɪɨɥɟɦ ɢɥɢ ɛɟɡ ɧɟɝɨ, ɤɚɤɨɜɚ ɤɨɞɨɜɚɹ ɫɬɪɚɧɢɰɚ ɞɥɹ ɫɨɞɟɪɠɚɳɟɝɨɫɹ ɜ ɧɟɣ ɬɟɤɫɬɚ ɢ ɞɪ.). Ɂɚɤɪɵɬɶ ɫɚɦ Excel ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Quit ɨɛɴɟɤɬɚ Excel.Application. ȼ ɫɥɭɱɚɟ Excel ɷɬɨɬ ɦɟɬɨɞ ɩɚɪɚɦɟɬɪɨɜ ɧɟ ɢɦɟɟɬ. 69
Ɉɛɪɚɳɟɧɢɟ ɤ ɨɬɞɟɥɶɧɵɦ ɹɱɟɣɤɚɦ ɥɢɫɬɚ ɩɪɨɢɡɜɨɞɢɬɫɹ ɫ ɩɨɦɨɳɶɸ ɤɨɥɥɟɤɰɢɢ Cells ɨɛɴɟɤɬɚ WorkSheet. ɇɚɩɪɢɦɟɪ, ɞɨɛɚɜɢɬɶ ɞɚɧɧɵɟ ɜ ɹɱɟɣɤɭ B1 ɦɨɠɧɨ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: App.WorkBooks[1].WorkSheets[‘Sheet1’].Cells[1,2].Value:=’25’; Ɂɞɟɫɶ ɩɟɪɜɚɹ ɢɡ ɤɨɨɪɞɢɧɚɬ ɹɱɟɣɤɢ ɭɤɚɡɵɜɚɟɬ ɧɚ ɧɨɦɟɪ ɫɬɪɨɤɢ, ɜɬɨɪɚɹ – ɧɚ ɧɨɦɟɪ ɫɬɨɥɛɰɚ. Ⱦɨɛɚɜɥɟɧɢɟ ɮɨɪɦɭɥ ɜ ɹɱɟɣɤɢ ɩɪɨɢɡɜɨɞɢɬɫɹ ɚɧɚɥɨɝɢɱɧɵɦ ɫɩɨɫɨɛɨɦ: App.WorkBooks[1].WorkSheets[‘Sheet1’].Cells[3,2].Value := ‘ =SUM(B1:B2)’; Ɉɱɢɫɬɢɬɶ ɹɱɟɣɤɭ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ ClearContents. Ɏɨɪɦɚɬɢɪɨɜɚɧɢɟ ɬɟɤɫɬɚ ɜ ɹɱɟɣɤɚɯ ɩɪɨɢɡɜɨɞɢɬɫɹ ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜ Font ɢ Interior ɨɛɴɟɤɬɚ Cell ɢ ɢɯ ɩɨɞɫɜɨɣɫɬɜ. ɇɚɩɪɢɦɟɪ, ɫɥɟɞɭɸɳɢɣ ɮɪɚɝɦɟɧɬ ɤɨɞɚ ɜɵɜɨɞɢɬ ɬɟɤɫɬ ɜ ɹɱɟɣɤɟ ɤɪɚɫɧɵɦ ɠɢɪɧɵɦ ɲɪɢɮɬɨɦ Courier ɤɟɝɥɹ 16 ɧɚ ɠɟɥɬɨɦ ɮɨɧɟ: App.WorkBooks[1].WorkSheets[1].Cells[3,2].Interior.Color := clYellow; App.WorkBooks[1].WorkSheets[1].Cells[3,2].Font.Color := clRed; App.WorkBooks[1].WorkSheets[1].Cells[3,2].Font.Name := ‘Courier’; App.WorkBooks[1].WorkSheets[1].Cells[3,2].Font.Size := 16; App.WorkBooks[1].WorkSheets[1].Cells[3,2].Font.Bold := True; ȼɦɟɫɬɨ ɫɜɨɣɫɬɜɚ Color ɦɨɠɧɨ ɢɫɩɨɥɶɡɨɜɚɬɶ ɫɜɨɣɫɬɜɨ ColorIndex, ɩɪɢɧɢɦɚɸɳɟɟ ɡɧɚɱɟɧɢɹ ɨɬ 1 ɞɨ 56; ɬɚɛɥɢɰɭ ɫɨɨɬɜɟɬɫɬɜɢɣ ɡɧɚɱɟɧɢɣ ɷɬɨɝɨ 70
ɫɜɨɣɫɬɜɚ ɪɟɚɥɶɧɵɦ ɰɜɟɬɚɦ ɦɨɠɧɨ ɧɚɣɬɢ ɜ ɫɩɪɚɜɨɱɧɨɦ ɮɚɣɥɟ VBAXL9.CHM. Ɉɛɪɚɬɢɬɶɫɹ ɤ ɬɟɤɭɳɟɣ ɹɱɟɣɤɟ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜɚ ActiveCell ɨɛɴɟɤɬɚ Excel.Application, ɚ ɭɡɧɚɬɶ ɦɟɫɬɨɩɨɥɨɠɟɧɢɟ ɹɱɟɣɤɢ ɦɨɠɧɨ ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜɚ Address ɨɛɴɟɤɬɚ Cell, ɧɚɩɪɢɦɟɪ: ShowMessage(App.ActiveCell.Address); ɉɨɦɢɦɨ ɨɛɪɚɳɟɧɢɹ ɤ ɨɬɞɟɥɶɧɵɦ ɹɱɟɣɤɚɦ, ɦɨɠɧɨ ɦɚɧɢɩɭɥɢɪɨɜɚɬɶ ɩɪɹɦɨɭɝɨɥɶɧɵɦɢ ɨɛɥɚɫɬɹɦɢ ɹɱɟɟɤ ɫ ɩɨɦɨɳɶɸ ɨɛɴɟɤɬɚ Range, ɧɚɩɪɢɦɟɪ: App.WorkBooks[1].WorkSheets[2].Range[‘A1:C5’].Value := ‘Test’; App.WorkBooks[1].WorkSheets[2].Range[‘A1:C5’].Font.Color := clRed; ɉɪɢɜɟɞɟɧɧɵɣ ɜɵɲɟ ɤɨɞ ɩɪɢɜɨɞɢɬ ɤ ɡɚɩɨɥɧɟɧɢɸ ɩɪɹɦɨɭɝɨɥɶɧɨɝɨ ɭɱɚɫɬɤɚ ɬɟɤɫɬɨɦ ɢ ɤ ɢɡɦɟɧɟɧɢɸ ɰɜɟɬɚ ɲɪɢɮɬɚ ɹɱɟɟɤ. Ɉɛɴɟɤɬ Range ɬɚɤɠɟ ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɟɬɫɹ ɞɥɹ ɤɨɩɢɪɨɜɚɧɢɹ ɩɪɹɦɨɭɝɨɥɶɧɵɯ ɨɛɥɚɫɬɟɣ ɱɟɪɟɡ ɛɭɮɟɪ ɨɛɦɟɧɚ. ɇɢɠɟ ɩɪɢɜɟɞɟɧ ɩɪɢɦɟɪ, ɢɥɥɸɫɬɪɢɪɭɸɳɢɣ ɤɨɩɢɪɨɜɚɧɢɟ ɬɚɤɨɣ ɨɛɥɚɫɬɢ: App.WorkBooks[1].WorkSheets[2].Range[‘A1:C5’].Copy; App.WorkBooks[1].WorkSheets[2].Range[‘A11:C15’].Select; App.WorkBooks[1].WorkSheets[2].Paste; Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ ɧɚ ɬɨ, ɱɬɨ ɞɢɚɩɚɡɨɧ, ɤɭɞɚ ɤɨɩɢɪɭɸɬɫɹ ɞɚɧɧɵɟ, ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɜɵɞɟɥɹɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɦɟɬɨɞɚ Select. Ɉɬɦɟɬɢɦ, ɱɬɨ ɩɪɢɦɟɪɧɨ ɬɚɤɢɦ ɠɟ ɨɛɪɚɡɨɦ ɦɨɠɧɨ ɤɨɩɢɪɨɜɚɬɶ ɞɚɧɧɵɟ ɢ ɢɡ ɞɪɭɝɢɯ ɩɪɢɥɨɠɟɧɢɣ (ɧɚɩɪɢɦɟɪ, ɢɡ Microsoft Word). Ⱦɨɜɨɥɶɧɨ ɱɚɫɬɨ ɩɪɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ Excel ɢɫɩɨɥɶɡɭɸɬɫɹ ɟɝɨ ɜɨɡɦɨɠɧɨɫɬɢ, ɫɜɹɡɚɧɧɵɟ ɫ ɩɨɫɬɪɨɟɧɢɟɦ ɞɢɚɝɪɚɦɦ. ɇɢɠɟ ɦɵ ɪɚɫɫɦɨɬɪɢɦ, ɤɚɤ ɷɬɨ ɫɞɟɥɚɬɶ. 6.5.5. ɋɨɡɞɚɧɢɟ ɞɢɚɝɪɚɦɦ Ⱦɢɚɝɪɚɦɦɚɦ Excel ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɨɛɴɟɤɬ Chart, ɤɨɬɨɪɵɣ ɦɨɠɟɬ ɪɚɫɩɨɥɚɝɚɬɶɫɹ ɤɚɤ ɧɚ ɨɬɞɟɥɶɧɨɦ ɥɢɫɬɟ, ɬɚɤ ɢ ɧɚ ɥɢɫɬɟ ɫ ɞɚɧɧɵɦɢ. ȿɫɥɢ ɨɛɴɟɤɬ Chart ɪɚɫɩɨɥɚɝɚɟɬɫɹ ɧɚ ɥɢɫɬɟ ɫ ɞɚɧɧɵɦɢ, ɟɦɭ ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɱɥɟɧ ɤɨɥɥɟɤɰɢɢ ChartObjects ɨɛɴɟɤɬɚ WorkSheet ɢ ɫɨɡɞɚɧɢɟ ɞɢɚɝɪɚɦɦɵ ɧɭɠɧɨ ɧɚɱɚɬɶ ɫ ɞɨɛɚɜɥɟɧɢɹ ɷɥɟɦɟɧɬɚ ɜ ɷɬɭ ɤɨɥɥɟɤɰɢɸ: Ch:=App.WorkBooks[1].WorkSheets[2].ChartObjects.Add(10,50,400,400); ɉɚɪɚɦɟɬɪɚɦɢ ɷɬɨɝɨ ɦɟɬɨɞɚ ɹɜɥɹɸɬɫɹ ɤɨɨɪɞɢɧɚɬɵ ɥɟɜɨɝɨ ɜɟɪɯɧɟɝɨ ɭɝɥɚ ɢ ɪɚɡɦɟɪɵ ɞɢɚɝɪɚɦɦɵ ɜ ɩɭɧɤɬɚɯ (1/72 ɞɸɣɦɚ). ȿɫɥɢ ɠɟ ɞɢɚɝɪɚɦɦɚ ɪɚɫɩɨɥɚɝɚɟɬɫɹ ɧɚ ɨɬɞɟɥɶɧɨɦ ɥɢɫɬɟ (ɧɟ ɩɪɟɞɧɚɡɧɚɱɟɧɧɨɦ ɞɥɹ ɯɪɚɧɟɧɢɹ ɞɚɧɧɵɯ), ɬɨ ɫɨɡɞɚɧɢɟ ɞɢɚɝɪɚɦɦɵ ɧɭɠɧɨ ɧɚɱɚɬɶ ɫ ɞɨɛɚɜɥɟɧɢɹ ɷɥɟɦɟɧɬɚ ɜ ɤɨɥɥɟɤɰɢɸ Sheets ɨɛɴɟɤɬɚ Application (ɤɨɬɨɪɚɹ ɨɬ71
ɥɢɱɚɟɬɫɹ ɨɬ ɤɨɥɥɟɤɰɢɢ WorkSheets ɬɟɦ, ɱɬɨ ɫɨɞɟɪɠɢɬ ɥɢɫɬɵ ɜɫɟɯ ɬɢɩɨɜ, ɚ ɧɟ ɬɨɥɶɤɨ ɥɢɫɬɵ ɫ ɞɚɧɧɵɦɢ): App.WorkBooks[1].Sheets.Add(,,1,xlWBATChart); ȼ ɷɬɨɦ ɫɥɭɱɚɟ ɩɟɪɜɵɣ ɩɚɪɚɦɟɬɪ ɦɟɬɨɞɚ Add ɭɤɚɡɵɜɚɟɬ ɩɨɪɹɞɤɨɜɵɣ ɧɨɦɟɪ ɥɢɫɬɚ, ɩɟɪɟɞ ɤɨɬɨɪɵɦ ɧɭɠɧɨ ɩɨɦɟɫɬɢɬɶ ɞɚɧɧɵɣ ɥɢɫɬ (ɢɥɢ ɞɚɧɧɵɟ ɥɢɫɬɵ, ɟɫɥɢ ɢɯ ɧɟɫɤɨɥɶɤɨ), ɜɬɨɪɨɣ ɩɚɪɚɦɟɬɪ – ɩɨɪɹɞɤɨɜɵɣ ɧɨɦɟɪ ɥɢɫɬɚ, ɩɨɫɥɟ ɤɨɬɨɪɨɝɨ ɧɭɠɧɨ ɩɨɦɟɫɬɢɬɶ ɞɚɧɧɵɣ ɥɢɫɬ (ɢɫɩɨɥɶɡɭɟɬɫɹ ɨɛɵɱɧɨ ɨɞɢɧ ɢɡ ɧɢɯ), ɬɪɟɬɢɣ ɩɚɪɚɦɟɬɪ – ɫɤɨɥɶɤɨ ɧɭɠɧɨ ɫɨɡɞɚɬɶ ɥɢɫɬɨɜ, ɚ ɱɟɬɜɟɪɬɵɣ – ɤɚɤɨɝɨ ɬɢɩɚ ɞɨɥɠɟɧ ɛɵɬɶ ɥɢɫɬ. Ɂɧɚɱɟɧɢɹ ɱɟɬɜɟɪɬɨɝɨ ɩɚɪɚɦɟɬɪɚ ɫɨɜɩɚɞɚɸɬ ɫɨ ɡɧɚɱɟɧɢɹɦɢ ɩɟɪɜɨɝɨ ɩɚɪɚɦɟɬɪɚ ɦɟɬɨɞɚ Add ɤɨɥɥɟɤɰɢɢ WorkBooks ɨɛɴɟɤɬɚ Application, ɢ ɩɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɢɦɟɧ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɤɨɧɫɬɚɧɬ ɫɥɟɞɭɟɬ ɨɩɪɟɞɟɥɢɬɶ ɢɯ ɜ ɩɪɢɥɨɠɟɧɢɢ-ɤɨɧɬɪɨɥɥɟɪɟ. ɉɪɨɫɬɟɣɲɢɣ ɫɩɨɫɨɛ ɫɨɡɞɚɬɶ ɞɢɚɝɪɚɦɦɭ, ɫ ɬɨɱɤɢ ɡɪɟɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɹ, – ɫɨɡɞɚɬɶ ɟɟ ɫ ɩɨɦɨɳɶɸ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɷɤɫɩɟɪɬɚ ɧɚ ɨɫɧɨɜɟ ɩɪɹɦɨɭɝɨɥɶɧɨɣ ɨɛɥɚɫɬɢ ɫ ɞɚɧɧɵɦɢ. Ɍɨɱɧɨ ɬɚɤ ɠɟ ɦɨɠɧɨ ɫɨɡɞɚɬɶ ɞɢɚɝɪɚɦɦɭ ɢ ɫ ɩɨɦɨɳɶɸ ɤɨɧɬɪɨɥɥɟɪɚ ɚɜɬɨɦɚɬɢɡɚɰɢɢ – ɞɥɹ ɷɬɨɣ ɰɟɥɢ ɭ ɨɛɴɟɤɬɚ Chart, ɹɜɥɹɸɳɟɝɨɫɹ ɫɜɨɣɫɬɜɨɦ ɨɛɴɟɤɬɚ ChartObject (ɱɥɟɧɚ ɤɨɥɥɟɤɰɢɢ ChartObjects), ɢɦɟɟɬɫɹ ɦɟɬɨɞ ChartWizard. ɉɟɪɜɵɦ ɩɚɪɚɦɟɬɪɨɦ ɷɬɨɝɨ ɦɟɬɨɞɚ ɹɜɥɹɟɬɫɹ ɨɛɴɟɤɬ Range, ɫɨɞɟɪɠɚɳɢɣ ɞɢɚɩɚɡɨɧ ɹɱɟɟɤ ɞɥɹ ɩɨɫɬɪɨɟɧɢɹ ɞɢɚɝɪɚɦɦɵ, ɚ ɜɬɨɪɵɦ – ɱɢɫɥɨɜɨɣ ɩɚɪɚɦɟɬɪ, ɭɤɚɡɵɜɚɸɳɢɣ, ɤɚɤɨɝɨ ɬɢɩɚ ɞɨɥɠɧɚ ɛɵɬɶ ɷɬɚ ɞɢɚɝɪɚɦɦɚ: Var Ch: Variant; … Ch.Chart.ChartWizard(App.WorkBooks[1].WorkSheets[2].Range[‘A1:C5’], xl3DColumn); ȼɨɡɦɨɠɧɵɟ ɡɧɚɱɟɧɢɹ ɩɚɪɚɦɟɬɪɚ, ɨɬɜɟɱɚɸɳɟɝɨ ɡɚ ɬɢɩ ɞɢɚɝɪɚɦɦɵ, ɦɨɠɧɨ ɧɚɣɬɢ ɜ ɫɩɪɚɜɨɱɧɨɦ ɮɚɣɥɟ. ɍ ɨɛɴɟɤɬɚ Chart ɢɦɟɟɬɫɹ ɦɧɨɠɟɫɬɜɨ ɫɜɨɣɫɬɜ, ɨɬɜɟɱɚɸɳɢɯ ɡɚ ɜɧɟɲɧɢɣ ɜɢɞ ɞɢɚɝɪɚɦɦɵ, ɫ ɩɨɦɨɳɶɸ ɤɨɬɨɪɵɯ ɦɨɠɧɨ ɢɡɦɟɧɢɬɶ ɟɟ ɬɨɱɧɨ ɬɚɤ ɠɟ, ɤɚɤ ɩɨɥɶɡɨɜɚɬɟɥɢ ɞɟɥɚɸɬ ɷɬɨ ɜɪɭɱɧɭɸ. ɇɢɠɟ ɩɪɢɜɨɞɢɬɫɹ ɩɪɢɦɟɪ ɫɨɡɞɚɧɢɹ ɡɚɝɨɥɨɜɤɚ ɞɢɚɝɪɚɦɦɵ ɢ ɩɨɞɩɢɫɟɣ ɜɞɨɥɶ ɟɟ ɨɫɟɣ (ɨɬɦɟɬɢɦ, ɱɬɨ ɨɫɢ ɟɫɬɶ ɧɟ ɭ ɜɫɟɯ ɬɢɩɨɜ ɞɢɚɝɪɚɦɦ). Ch.Chart.HasTitle :=1; Ch.Chart.HasLegend := False; Ch.Chart.ChartTitle.Text := ‘ɉɪɢɦɟɪ ɞɢɚɝɪɚɦɦɵ Excel ‘; Ch.Chart.Axes(1).HasTitle := True; Ch.Chart.Axes(1).AxisTitle.Text := ‘ɉɨɞɩɢɫɶ ɜɞɨɥɶ ɨɫɢ ɚɛɫɰɢɫɫ’; Ch.Chart.Axes(2).HasTitle := True; Ch.Chart.Axes(2).AxisTitle.Text := ‘ɉɨɞɩɢɫɶ ɜɞɨɥɶ ɨɫɢ ɨɪɞɢɧɚɬ’; ȿɳɟ ɨɞɢɧ ɫɩɨɫɨɛ ɫɨɡɞɚɧɢɹ ɞɢɚɝɪɚɦɦɵ – ɨɩɪɟɞɟɥɢɬɶ ɜɫɟ ɟɟ ɩɚɪɚɦɟɬɪɵ ɫ ɩɨɦɨɳɶɸ ɫɜɨɣɫɬɜ ɨɛɴɟɤɬɚ Chart, ɜɤɥɸɱɚɹ ɢ ɨɩɪɟɞɟɥɟɧɢɟ ɫɟɪɢɣ, ɧɚ ɨɫɧɨ72
ɜɟ ɤɨɬɨɪɵɯ ɨɧɚ ɞɨɥɠɧɚ ɛɵɬɶ ɩɨɫɬɪɨɟɧɚ. Ⱦɚɧɧɵɟ ɞɥɹ ɫɟɪɢɢ ɨɛɵɱɧɨ ɧɚɯɨɞɢɬɫɹ ɜ ɨɛɴɟɤɬɟ Range, ɫɨɞɟɪɠɚɳɟɦ ɫɬɪɨɤɭ ɢɥɢ ɫɬɨɥɛɟɰ ɞɚɧɧɵɯ, ɚ ɞɨɛɚɜɥɟɧɢɟ ɫɟɪɢɢ ɤ ɞɢɚɝɪɚɦɦɟ ɩɪɨɢɡɜɨɞɢɬɫɹ ɩɭɬɟɦ ɞɨɛɚɜɥɟɧɢɹ ɱɥɟɧɚ ɤ ɤɨɥɥɟɤɰɢɢ SeriesCollection, ɧɚɩɪɢɦɟɪ: App.WorkBooks[1].Sheets.Add(,,1,xlWBATChart); App.WorkBooks[1].Sheets[1].ChartType := xl3DPie; Rng:=App.WorkBooks[1].WorkSheets[2].Range[‘B1:B5’]; App.WorkBooks[1].Sheets[1].SeriesCollection.Add(Rng); ȼ ɞɚɧɧɨɦ ɩɪɢɦɟɪɟ ɤ ɞɢɚɝɪɚɦɦɟ, ɫɨɡɞɚɧɧɨɣ ɧɚ ɨɬɞɟɥɶɧɨɦ ɥɢɫɬɟ, ɫɩɟɰɢɚɥɶɧɨ ɩɪɟɞɧɚɡɧɚɱɟɧɧɨɦ ɞɥɹ ɞɢɚɝɪɚɦɦ, ɞɨɛɚɜɥɹɟɬɫɹ ɨɞɧɚ ɫɟɪɢɹ ɧɚ ɨɫɧɨɜɟ ɞɢɚɩɚɡɨɧɚ ɹɱɟɟɤ ɞɪɭɝɨɝɨ ɥɢɫɬɚ. ȼɨɡɦɨɠɧɨɫɬɢ ɚɜɬɨɦɚɬɢɡɚɰɢɢ Microsoft Excel ɢ Word ɞɚɥɟɤɨ ɧɟ ɢɫɱɟɪɩɵɜɚɸɬɫɹ ɩɪɢɜɟɞɟɧɧɵɦɢ ɩɪɢɦɟɪɚɦɢ. ɋɜɟɞɟɧɢɹ ɨ ɧɢɯ ɦɨɠɧɨ ɜɫɟɝɞɚ ɧɚɣɬɢ ɜ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɦ ɫɩɪɚɜɨɱɧɨɦ ɮɚɣɥɟ.
6.6. ɉɪɢɦɟɪ ɷɤɫɩɨɪɬɚ ɞɚɧɧɵɯ ɜ Word ȼ ɤɚɱɟɫɬɜɟ ɩɪɢɦɟɪɚ ɪɚɫɫɦɨɬɪɢɦ ɡɚɞɚɱɭ ɮɨɪɦɢɪɨɜɚɧɢɹ ɨɬɱɟɬɚ ɞɚɧɧɵɯ ɢɡ ɡɚɞɚɧɧɨɣ ɛɚɡɵ ɞɚɧɧɵɯ ɜ Microsoft Word: ɧɟɨɛɯɨɞɢɦɨ ɫɮɨɪɦɢɪɨɜɚɬɶ ɫɥɨɠɧɵɣ ɞɨɤɭɦɟɧɬ ɫ ɤɨɥɨɧɬɢɬɭɥɚɦɢ, ɬɚɛɥɢɰɚɦɢ ɢ ɡɚɝɨɥɨɜɤɚɦɢ. Ɍɚɤɠɟ ɞɨɤɭɦɟɧɬ ɞɨɥɠɟɧ ɢɦɟɬɶ ɬɢɬɭɥɶɧɭɸ ɫɬɪɚɧɢɰɭ, ɧɚ ɤɨɬɨɪɨɣ ɩɢɲɟɬɫɹ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɬɟɤɫɬ, ɫɨ ɜɬɨɪɨɣ ɫɬɪɚɧɢɰɵ ɧɚɱɢɧɚɟɬɫɹ ɜɟɪɯɧɢɣ ɤɨɥɨɧɬɢɬɭɥ, ɝɞɟ ɡɚɞɚɟɬɫɹ ɡɚɝɨɥɨɜɨɤ. Ⱦɥɹ ɩɨɞɤɥɸɱɟɧɢɹ ɤ ɛɚɡɟ ɞɚɧɧɵɯ ɛɭɞɭɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɫɬɚɧɞɚɪɬɧɵɟ ɤɨɦɩɨɧɟɧɬɵ Delphi, ɧɚɩɪɢɦɟɪ, TADODataset. ɋɭɳɟɫɬɜɭɟɬ ɞɜɚ ɫɩɨɫɨɛɚ ɪɟɲɟɧɢɹ ɩɨɫɬɚɜɥɟɧɧɨɣ ɡɚɞɚɱɢ: 1. Ȼɟɡ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɲɚɛɥɨɧɚ: ɫɨɡɞɚɟɬɫɹ ɧɨɜɵɣ ɞɨɤɭɦɟɧɬ, ɝɞɟ ɫɨɡɞɚɸɬɫɹ ɤɨɥɨɧɬɢɬɭɥɵ ɧɚɞɩɢɫɢ ɢ ɬ.ɞ. ɗɬɨɬ ɦɟɬɨɞ ɞɨɫɬɚɬɨɱɧɨ ɫɥɨɠɟɧ, ɬɚɤ ɤɚɤ ɧɟɨɛɯɨɞɢɦɨ ɭɱɢɬɵɜɚɬɶ ɬɨ, ɱɬɨ ɧɚ ɪɚɡɧɵɯ ɤɨɦɩɶɸɬɟɪɚɯ ɦɨɝɭɬ ɢɡɧɚɱɚɥɶɧɨ ɫɬɨɹɬɶ ɪɚɡɧɵɟ ɧɚɫɬɪɨɣɤɢ ɫɬɪɚɧɢɰɵ, ɲɪɢɮɬɨɜ, ɚɛɡɚɰɟɜ. 2. ɋ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɲɚɛɥɨɧɚ: ɡɚɪɚɧɟɟ ɫɨɡɞɚɟɬɫɹ ɞɨɤɭɦɟɧɬ, ɤɨɬɨɪɵɣ ɢɫɩɨɥɶɡɭɟɬɫɹ ɤɚɤ ɲɚɛɥɨɧ. ɇɚɩɪɢɦɟɪ, ɜ ɲɚɛɥɨɧ ɜ ɧɭɠɧɨɦ ɦɟɫɬɟ ɜ ɰɟɧɬɪɟ ɩɟɪɜɨɣ ɫɬɪɚɧɢɰɵ ɫɬɚɜɢɬɫɹ ɨɛɴɟɤɬ ɬɢɩɚ ɧɚɞɩɢɫɶ, ɜ ɤɨɬɨɪɨɣ ɜɵɫɬɚɜɥɹɟɬɫɹ ɧɭɠɧɵɣ ɲɪɢɮɬ ɢ ɜɵɪɚɜɧɢɜɚɧɢɟ. ȼ ɤɨɧɰɟ ɩɟɪɜɨɣ ɫɬɪɚɧɢɰɵ ɞɟɥɚɟɬɫɹ ɪɚɡɪɵɜ ɪɚɡɞɟɥɚ. ɇɚ ɜɬɨɪɨɣ ɫɬɪɚɧɢɰɟ ɜ ɜɟɪɯɧɢɣ ɤɨɥɨɧɬɢɬɭɥ ɬɨɠɟ ɜɫɬɚɜɥɹɟɬɫɹ ɨɛɴɟɤɬ ɬɢɩɚ ɧɚɞɩɢɫɶ. ȼ ɧɟɝɨ ɛɭɞɟɬ ɜɫɬɚɜɥɹɬɶɫɹ ɧɚɡɜɚɧɢɟ ɞɨɤɭɦɟɧɬɚ. Ⱦɚɥɟɟ ɡɚɩɢɫɵɜɚɟɬɫɹ ɦɚɤɪɨɫ, ɜ ɤɨɬɨɪɨɦ ɜɵɩɨɥɧɹɸɬɫɹ ɞɟɣɫɬɜɢɹ, ɤɨɬɨɪɵɟ ɧɟɨɛɯɨɞɢɦɨ ɪɟɚɥɢɡɨɜɚɬɶ ɜ Delphi: 1) ɜ ɨɛɴɟɤɬ ɬɢɩɚ ɧɚɞɩɢɫɶ ɧɚ ɩɟɪɜɨɣ ɫɬɪɚɧɢɰɟ ɜɧɟɫɬɢ ɬɟɤɫɬ; 2) ɩɟɪɟɣɬɢ ɜ ɤɨɧɟɰ ɞɨɤɭɦɟɧɬɚ; 3) ɩɟɪɟɣɬɢ ɜ ɜɟɪɯɧɢɣ ɤɨɥɨɧɬɢɬɭɥ; 4) ɜ ɨɛɴɟɤɬ ɬɢɩɚ ɧɚɞɩɢɫɶ ɜ ɤɨɥɨɧɬɢɬɭɥɟ ɜɧɟɫɬɢ ɬɟɤɫɬ; 5) ɜɟɪɧɭɬɶɫɹ ɧɚ ɜɬɨɪɭɸ ɫɬɪɚɧɢɰɭ. 73
ȼ ɪɟɡɭɥɶɬɚɬɟ ɩɨɥɭɱɚɟɬɫɹ ɫɥɟɞɭɸɳɢɣ ɦɚɤɪɨɫ: Sub Ɇɚɤɪɨɫ1() ActiveDocument.Shapes("Text Box 8").Select Selection.TypeText Text:="ɬɟɤɫɬ ɧɚ ɬɢɬɭɥɶɧɨɣ" Selection.EndKey Unit:=wdStory If ActiveWindow.View.SplitSpecial wdPaneNone Then ActiveWindow.Panes(2).Close End If If ActiveWindow.ActivePane.View.Type = wdNormalView Or _ ActiveWindow.ActivePane.View.Type = wdOutlineView Then ActiveWindow.ActivePane.View.Type = wdPrintView End If ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.HeaderFooter.Shapes("Text Box 5").Select Selection.TypeText Text:="Ɍɟɤɫɬ ɜ ɤɨɥɨɧɬɢɬɭɥɟ" ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument End Sub ȿɫɥɢ ɩɪɟɨɛɪɚɡɨɜɚɬɶ ɜ ɤɨɞ Delphi, ɬɨ ɩɨɥɭɱɢɦ: //ɜɵɛɢɪɚɟɬɫɹ ɩɟɪɜɚɹ ɧɚɞɩɢɫɶ Vr := 'Text Box 8'; Word.ActiveDocument.Shapes.Item(vr).Select; //ɩɢɲɟɬɫɹ ɬɟɤɫɬ Word.Selection.TypeText('ɬɟɤɫɬ ɧɚ ɬɢɬɭɥɶɧɨɣ'); //ɩɟɪɟɯɨɞ ɜ ɤɨɧɟɰ ɞɨɤɭɦɟɧɬɚ Vr := wdStory; Word.Selection.EndKey(Vr); //ɨɩɟɪɚɬɨɪɵ if ɡɞɟɫɶ ɧɟ ɧɭɠɧɵ //ɩɟɪɟɯɨɞ ɜ ɜɟɪɯɧɢɣ ɤɨɥɨɧɬɢɬɭɥ Word.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader; Vr := 'Text Box 5'; Word.Selection.HeaderFooter.Shapes.Item(Vr).Select; Word.Selection.TypeText('ɬɟɤɫɬ ɜ ɤɨɥɨɧɬɢɬɭɥɟ'); Word.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument;
74
Ⱥɧɚɥɨɝɢɱɧɵɦ ɨɛɪɚɡɨɦ ɦɨɠɧɨ ɩɨɥɭɱɢɬɶ ɤɨɞ ɜɜɨɞɚ ɬɟɤɫɬɚ ɜ ɤɨɥɨɧɬɢɬɭɥɵ, ɧɚɫɬɪɨɣɤɭ ɲɪɢɮɬɨɜ, ɚɛɡɚɰɟɜ ɢ ɬ. ɩ. Ɋɟɲɟɧɢɟ ɩɨɫɬɚɜɥɟɧɧɨɣ ɡɚɞɚɱɢ ɩɪɢɜɟɞɟɧɨ ɜ ɫɥɟɞɭɸɳɟɦ ɥɢɫɬɢɧɝɟ: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, ActiveX; type TForm1 = class(TForm) ADOConnection1: TADOConnection; ADODataSet1: TADODataSet; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } procedure TableExport(Word,Document,Selection: Variant; DataSet: TDataSet; Title,FlagText: String); public { Public declarations } end; var Form1: TForm1; implementation uses ComObj; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var Word: Variant; Document: Variant; Selection: Variant; Vr: OleVariant; begin 75
Screen.Cursor := crHourGlass; //ɫɨɡɞɚɟɬɫɹ ɫɟɪɜɟɪ ɚɜɬɨɦɚɬɢɡɚɰɢɢ Word Word := CreateOleObject('Word.Application'); try //ɫɨɡɞɚɟɬɫɹ ɧɨɜɵɣ ɞɨɤɭɦɟɧɬ ɩɨ ɲɚɛɥɨɧɭ Document := Word.Documents.Add(GetCurrentDir+'\Shablon.doc'); //ɜɵɛɢɪɚɟɬɫɹ ɩɟɪɜɚɹ ɧɚɞɩɢɫɶ Vr := 'Text Box 8'; Document.Shapes.Item(Vr).Select; //ɡɚɩɨɦɢɧɚɟɬɫɹ ɫɫɵɥɤɚ ɧɚ ɨɛɴɟɤɬ Selection Selection := Word.Selection; //ɩɢɲɟɬɫɹ ɬɟɤɫɬ Selection.TypeText('ɬɟɤɫɬ ɧɚ ɬɢɬɭɥɶɧɨɣ'); //ɩɟɪɟɯɨɞ ɜ ɤɨɧɟɰ ɞɨɤɭɦɟɧɬɚ Vr := wdStory; Selection.EndKey(Vr); //ɩɟɪɟɯɨɞ ɜ ɜɟɪɯɧɢɣ ɤɨɥɨɧɬɢɬɭɥ Word.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader; Vr := 'Text Box 5'; Selection.HeaderFooter.Shapes.Item(Vr).Select; Word.Selection.TypeText('ɬɟɤɫɬ ɜ ɤɨɥɨɧɬɢɬɭɥɟ'); Word.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument; ADODataSet1.Close; ADODataSet1.CommandText := 'SELECT [Main].[Tel], [Main].[name], '+ '[Main].[House], [Korp].[NameKorp], [Flat].[NameFlat], [Ul].[NameUl] '+ ' FROM Main, Ul, Korp, Flat WHERE ([Main].[IdUl]=[Ul].[IdUl]) And '+ '([Main].[IdKorp]=[Korp].[IdKorp]) And '+ '([Main].[IdFlat]=[Flat].[IdFlat]) '; ADODataSet1.Open; //ɧɚɫɬɪɚɢɜɚɸɬɫɹ ɩɚɪɚɦɟɬɪɵ ɷɤɫɩɨɪɬɚ //ɡɚɝɨɥɨɜɨɤ ADODataSet1.fields[0].DisplayLabel := 'Ɍɟɥɟɮɨɧ'; //ɲɢɪɢɧɚ ɫɬɨɥɛɰɚ ADODataSet1.fields[0].Tag := round(Word.CentimetersToPoints(2)); //ɨɬɨɛɪɚɠɚɬɶ ɩɨɥɟ DataSet1.fields[0].Visible := True; 76
//ɡɚɝɨɥɨɜɨɤ ADODataSet1.fields[1].DisplayLabel := 'ɎɂɈ'; //ɲɢɪɢɧɚ ɫɬɨɥɛɰɚ ADODataSet1.fields[1].Tag := Round(Word.CentimetersToPoints(10)); //ɨɬɨɛɪɚɠɚɬɶ ɩɨɥɟ ADODataSet1.fields[1].Visible := True; //ɡɚɝɨɥɨɜɨɤ ADODataSet1.fields[2].DisplayLabel := 'Ⱦɨɦ'; //ɲɢɪɢɧɚ ɫɬɨɥɛɰɚ ADODataSet1.fields[2].Tag:= Round(Word.CentimetersToPoints(1.5)); //ɨɬɨɛɪɚɠɚɬɶ ɩɨɥɟ ADODataSet1.fields[2].Visible := True; //ɡɚɝɨɥɨɜɨɤ ADODataSet1.fields[3].DisplayLabel := 'Ʉɨɪɩɭɫ'; //ɲɢɪɢɧɚ ɫɬɨɥɛɰɚ ADODataSet1.fields[3].Tag := Round(Word.CentimetersToPoints(1.5)); //ɨɬɨɛɪɚɠɚɬɶ ɩɨɥɟ ADODataSet1.fields[3].Visible := True; //ɡɚɝɨɥɨɜɨɤ ADODataSet1.fields[4].DisplayLabel := 'Ʉɜɚɪɬɢɪɚ'; //ɲɢɪɢɧɚ ɫɬɨɥɛɰɚ ADODataSet1.fields[4].Tag := Round(Word.CentimetersToPoints(1.5)); //ɨɬɨɛɪɚɠɚɬɶ ɩɨɥɟ ADODataSet1.fields[4].Visible := True; //ɧɟ ɨɬɨɛɪɚɠɚɬɶ ɩɨɥɟ ADODataSet1.fields[5].Visible := False; //ɜɵɡɵɜɚɟɬɫɹ ɩɪɨɰɟɞɭɪɚ ɷɤɫɩɨɪɬɚ TableExport(Word,Document,Selection,ADODataSet1,'ɀɢɜɭɳɢɟ ɧɚ ɭɥɢɰɟ Ⱥɯɦɟɬɨɜɚ','ȺɏɆȿɌɈȼȺ'); 77
TableExport(Word,Document,Selection,ADODataSet1,'ɀɢɜɭɳɢɟ ɧɚ ɭɥɢɰɟ Ʌɟɬɱɢɤɨɜ','ɅȿɌɑɂɄɈȼ'); finally //ɨɬɨɛɪɚɠɟɬɫɹ Word Word.Visible := True; //ɧɟ ɡɚɛɭɞɶɬɟ ɭɞɚɥɢɬɶ ɫɫɵɥɤɢ!!! Selection := Null; Document := Null; Word := Null; Screen.Cursor := crDefault; end; end; procedure TForm1.TableExport(Word,Document,Selection: Variant; DataSet: TDataSet; Title,FlagText: String); var I,ColCount: Integer; //ɤɨɥɢɱɟɫɬɜɨ ɤɨɥɨɧɨɤ ɜ ɬɚɛɥɢɰɟ TableBeg: Integer; //ɇɨɦɟɪ ɫɢɦɜɨɥɚ ɜ ɧɚɱɚɥɟ ɬɚɛɥɢɰɵ TableBeg2: Integer; //ɇɨɦɟɪ ɫɢɦɜɨɥɚ ɜ ɧɚɱɚɥɟ ɞɚɧɧɵɯ ɬɚɛɥɢɰɵ Vr1,Vr2: OleVariant; F: Boolean; St: String; function ConvertString(S: String): String; {ɉɪɢ ɮɨɪɦɢɪɨɜɚɧɢɢ ɬɚɛɥɢɰɵ ɜ ɤɚɱɟɫɬɜɟ ɪɚɡɞɟɥɢɬɟɥɹ ɩɨ ɭɦɨɥɱɚɧɢɸ ɢɫɩɨɥɶɡɭɟɬɫɹ "-", ɤɨɬɨɪɵɣ ɧɟɨɛɯɨɞɢɦɨ ɡɚɦɟɧɢɬɶ ɧɚ ɚɧɚɥɨɝɢɱɧɵɣ ɫɢɦɜɨɥ ɫ ɤɨɞɨɦ #173} begin Result := StringReplace(S,'-',#173,[]); end; begin {ɉɪɨɰɟɞɭɪɚ ɷɤɫɩɨɪɬɢɪɭɟɬ ɥɢɲɶ ɬɟ ɡɚɩɢɫɢ, ɭ ɤɨɬɨɪɵɯ ɡɧɚɱɟɧɢɟ ɩɨɫɥɟɞɧɟɝɨ ɩɨɥɹ ɫɨɜɩɚɞɚɟɬ ɫ FlagText. ȿɫɥɢ FlagText=,'' ɬɨ ɷɤɫɩɨɪɬɢɪɭɸɬɫɹ ɜɫɟ ɡɚɩɢɫɢ} Vr1 := wdStory; //ɩɟɪɟɯɨɞ ɜ ɤɨɧɟɰ ɞɨɤɭɦɟɧɬɚ Selection.EndKey(Vr1); //ɜɫɬɚɜɥɹɟɬɫɹ ɡɚɝɨɥɨɜɨɤ ɬɚɛɥɢɰɵ Document.Range.InsertAfter(Title); //ɧɚɫɬɪɨɣɤɢ ɫɬɢɥɹ ɚɛɡɚɰɚ Document.Paragraphs.Item(Document.Paragraphs.Count).Range.Select; 78
Selection.ParagraphFormat.KeepWithNext := -1; Selection.ParagraphFormat.SpaceAfter := 14; //ɡɚɞɚɟɬɫɹ ɲɪɢɮɬ Selection.Font.Size := 15; WSelection.Font.bold := 1; //ɞɨɛɚɜɥɹɟɬɫɹ ɫɬɪɨɤɚ Document.Paragraphs.Add; Document.Paragraphs.Item(Document.Paragraphs.Count).Range.Select; Selection.ParagraphFormat.SpaceAfter := 0; Vr1 := wdStory; //ɩɟɪɟɯɨɞ ɜ ɤɨɧɟɰ ɞɨɤɭɦɟɧɬɚ Selection.EndKey(Vr1); //ɡɚɩɨɦɢɧɚɟɬɫɹ ɩɨɥɨɠɟɧɢɟ ɤɭɪɫɨɪɚ. ɗɬɨ ɧɚɱɚɥɨ ɛɭɞɭɳɟɣ ɬɚɛɥɢɰɵ. //ɡɚɬɟɦ ɜɵɛɢɪɚɟɬɫɹ ɜɟɫɶ ɨɫɬɚɜɲɢɣɫɹ ɬɟɤɫɬ, ɱɬɨɛɵ ɩɪɟɨɛɪɚɡɨɜɚɬɶ //ɟɝɨ ɜ ɬɚɛɥɢɰɭ TableBeg := Selection.End; DataSet.First; //ɜɫɬɚɜɥɹɸɬɫɹ ɡɚɝɨɥɨɜɤɢ ɞɥɹ ɜɫɟɯ ɜɢɞɢɦɵɯ ɩɨɥɟɣ for I := 0 to DataSet.FieldCount-1 do if DataSet.Fields[i].Visible then Document.Range.InsertAfter (ɋonvertString(DataSet.Fields[I]. DisplayLabel)+#9); Selection.EndKey(Vr1); //ɭɛɢɪɚɸɬɫɹ ɩɨɫɥɟɞɧɢɟ ɫɢɦɜɨɥɵ ɬɚɛɭɥɹɰɢɢ {ɋɢɦɜɨɥ ɬɚɛɭɥɹɰɢɢ ɢɫɩɨɥɶɡɭɟɬɫɹ ɜ ɤɚɱɟɫɬɜɟ ɪɚɡɞɟɥɢɬɟɥɹ ɞɥɹ ɫɬɨɥɛɰɨɜ ɬɚɛɥɢɰɵ} Selection.TypeBackspace; //ɩɪɢɦɟɧɹɟɬɫɹ ɲɪɢɮɬ Document.Paragraphs.Item(Document.Paragraphs.Count).Range.Select; Selection.Font.Size := 14; Selection.Font.Italic := 1; Selection.Font.Bold := 0; //ɞɨɛɚɜɥɹɟɬɫɹ ɫɬɪɨɤɚ Document.Paragraphs.Add; //Ɉɩɪɟɞɟɥɟɧɢɟ, ɛɵɥɢ ɥɢ ɜ ɬɚɛɥɢɰɟ ɜɨɨɛɳɟ ɡɚɩɢɫɢ ɞɥɹ ɷɤɫɩɨɪɬɚ F := True; //ɋɬɪɨɤɚ ɞɥɹ ɷɤɫɩɨɪɬɚ ɬɟɤɫɬɚ ɬɚɛɥɢɰɵ St := ''; 79
//ɧɚɱɚɥɨ ɞɚɧɧɵɯ ɜ ɬɚɛɥɢɰɟ TableBeg2 := Selection.End; if Dataset.RecordCount > 0 then begin repeat if (Dataset.fields[DataSet.Fields.Count-1].AsString = FlagText) or (FlagText = '') then begin for I := 0 to DataSet.FieldCount-1 do if DataSet.Fields[I].Visible then //ɱɟɪɟɡ ɬɚɛɭɥɹɰɢɸ ɜɵɜɨɞɹɬɫɹ ɜɫɟ ɜɢɞɢɦɵɟ ɩɨɥɹ St := St+DataSet.Fields[I].AsString+#9; //ɭɛɢɪɚɟɬɫɹ ɩɨɫɥɟɞɧɢɣ ɫɢɦɜɨɥ ɬɚɛɭɥɹɰɢɢ SetLength(St,Length(St)-1); //ɩɟɪɟɧɨɫ ɫɬɪɨɤɢ St := St+#13; F := False; end; Dataset.Next; until Dataset.Eof; //ɩɟɪɟɯɨɞ ɜ ɤɨɧɟɰ ɬɟɤɫɬɚ Selection.EndKey(Vr1); //ɜɫɬɚɜɤɚ ɞɚɧɧɵɯ ɬɚɛɥɢɰɵ Selection.InsertAfter(ɋonvertString(St)); //ɧɚɱɚɥɨ ɞɚɧɧɵɯ ɬɚɛɥɢɰɵ Vr1 := TableBeg2; //ɤɨɧɟɰ ɬɚɛɥɢɰɵ Vr2 := Selection.End; Selection.Font.Size := 12; Selection.Font.Bold := 0; Selection.Font.Italic := 0; end; //ɜ ɬɨɦ ɫɥɭɱɚɟ, ɟɫɥɢ ɧɟ ɷɤɫɩɨɪɬɢɪɨɜɚɥɨɫɶ ɧɢ ɨɞɧɨɣ ɡɚɩɢɫɢ //ɮɨɪɦɢɪɭɟɬɫɹ ɩɭɫɬɚɹ ɫɬɪɨɤɚ if F then begin for I := 0 to DataSet.FieldCount-1 do 80
if DataSet.Fields[I].Visible then Document.Range.InsertAfter(' '+#9); Selection.EndKey(Vr1,EmptyParam);
end; end. ɉɪɢ ɧɚɠɚɬɢɢ ɧɚ ɤɧɨɩɤɭ Button1 ɜɵɩɨɥɧɹɟɬɫɹ ɩɪɨɰɟɞɭɪɚ Button1Click, ɜ ɤɨɬɨɪɨɣ ɫɨɡɞɚɸɬɫɹ ɨɛɴɟɤɬɵ Word ɢ Document, ɡɚɞɚɸɬɫɹ ɬɢɬɭɥɶɧɵɣ ɥɢɫɬ ɢ ɤɨɥɨɧɬɢɬɭɥɵ, ɡɚɬɟɦ ɜɵɡɵɜɚɟɬɫɹ ɩɪɨɰɟɞɭɪɚ TableExport – ɷɤɫɩɨɪɬɚ ɞɚɧɧɵɯ ɜ ɬɚɛɥɢɰɭ Word. ȼ ɞɚɧɧɨɣ ɩɪɨɝɪɚɦɦɟ ɢɫɩɨɥɶɡɨɜɚɥɨɫɶ ɩɨɡɞɧɟɟ ɫɜɹɡɵɜɚɧɢɟ. ɑɬɨɛɵ ɫɨɤɪɚɬɢɬɶ ɤɨɥɢɱɟɫɬɜɨ ɨɛɪɚɳɟɧɢɣ ɤ ɢɧɬɟɪɮɟɣɫɚɦ ɫɫɵɥɤɢ ɧɚ ɨɛɴɟɤɬɵ, Document ɢ Select ɯɪɚɧɹɬɫɹ ɜ ɨɬɞɟɥɶɧɵɯ ɩɟɪɟɦɟɧɧɵɯ. ɉɨ ɨɤɨɧɱɚɧɢɢ ɪɚɛɨɬɵ ɜɫɟ ɫɫɵɥɤɢ ɧɚ ɨɛɴɟɤɬɵ ɫɟɪɜɟɪɚ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɧɟɨɛɯɨɞɢɦɨ ɭɞɚɥɢɬɶ, ɱɬɨ ɞɨɫɬɢɝɚɟɬɫɹ ɩɪɢɫɜɨɟɧɢɟɦ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɦ ɩɟɪɟɦɟɧɧɵɦ ɡɧɚɱɟɧɢɹ Null.
Selection.TypeBackspace; end; //ɧɚɱɚɥɨ ɛɭɞɭɳɟɣ ɬɚɛɥɢɰɵ Vr1 := TableBeg; //ɤɨɧɟɰ ɛɭɞɭɳɟɣ ɬɚɛɥɢɰɵ Vr2 := Selection.End; //ɜɵɛɢɪɚɟɬɫɹ ɞɢɚɩɚɡɨɧ Document.Range(Vr1,Vr2).Select; //ɩɪɟɨɛɪɚɡɨɜɚɧɢɟ ɜ ɬɚɛɥɢɰɭ Selection.ConvertToTable; ɋolɋount := 1; //ɡɚɞɚɸɬɫɹ ɲɢɪɢɧɵ ɤɨɥɨɧɨɤ for I := 0 to DataSet.FieldCount-1 do if DataSet.Fields[I].Visible then begin Document.Tables.Item(Document.Tables.Count).Columns.Item(ColCount). Width := DataSet.Fields[i].Tag; Inc(ColCount); end; //ɡɚɞɚɸɬɫɹ ɝɪɚɧɢɰɵ Selection.Cells.Borders.Item (wdBorderLeft). LineStyle:=wdLineStyleSingle; Selection.Cells.Borders.Item(wdBorderRight).LineStyle:= wdLineStyleSingle; Selection.Cells.Borders.Item(wdBorderHorizontal).LineStyle:= wdLineStyleSingle; Selection.Cells.Borders.Item(wdBorderTop).LineStyle:= wdLineStyleSingle; Selection.Cells.Borders.Item(wdBorderBottom).LineStyle:= wdLineStyleSingle; Selection.Cells.Borders.Item(wdBorderVertical).LineStyle:= wdLineStyleSingle; Document.Paragraphs.Add; Document.Paragraphs.Item(Document.Paragraphs.Count-1). Range.Select; Selection.ParagraphFormat.KeepWithNext:=0; 81
Ɂɚɞɚɱɢ «Ʉɥɢɟɧɬ-ɋɟɪɜɟɪ» ȼɨ ɜɫɟɯ ɜ ɜɚɪɢɚɧɬɚɯ ɡɚɞɚɱ ɬɪɟɛɭɟɬɫɹ ɫɨɡɞɚɬɶ COM-ɫɟɪɜɟɪ, ɩɪɟɞɨɫɬɚɜɥɹɸɳɢɣ ɭɤɚɡɚɧɧɵɣ ɢɧɬɟɪɮɟɣɫ, ɢ ɪɟɚɥɢɡɨɜɚɬɶ ɩɪɢɥɨɠɟɧɢɟ-ɤɥɢɟɧɬ, ɢɫɩɨɥɶɡɭɸɳɟɟ ɮɭɧɤɰɢɢ ɫɟɪɜɟɪɚ: 1.
ȼɵɱɢɫɥɟɧɢɟ ɬɪɢɝɨɧɨɦɟɬɪɢɱɟɫɤɢɯ ɮɭɧɤɰɢɣ.
2. Ʉɚɥɶɤɭɥɹɬɨɪ (ɩɨɞɞɟɪɠɢɜɚɸɳɢɣ ɫɥɨɠɟɧɢɟ, ɜɵɱɢɬɚɧɢɟ, ɭɦɧɨɠɟɧɢɟ, ɞɟɥɟɧɢɟ). 3. Ɉɛɪɚɛɨɬɤɚ ɮɚɣɥɚ: ɧɚɯɨɠɞɟɧɢɟ ɞɥɢɧɵ ɮɚɣɥɚ (ɜ ɫɢɦɜɨɥɚɯ), ɧɚɯɨɠɞɟɧɢɟ ɫɚɦɨɝɨ ɞɥɢɧɧɨɝɨ ɫɥɨɜɚ. 4. Ɉɛɪɚɛɨɬɤɚ ɮɚɣɥɨɜ: ɫɪɚɜɧɟɧɢɟ ɞɜɭɯ ɮɚɣɥɨɜ, ɧɚɯɨɠɞɟɧɢɟ ɨɞɢɧɚɤɨɜɵɯ ɫɥɨɜ ɜ ɮɚɣɥɚɯ, ɨɛɴɟɞɢɧɟɧɢɟ ɮɚɣɥɨɜ. 5.
Ɋɟɚɥɢɡɚɰɢɹ ɮɚɣɥɨɜɵɯ ɨɩɟɪɚɰɢɣ (ɨɬɤɪɵɬɢɟ, ɱɬɟɧɢɟ, ɡɚɩɢɫɶ ɢ ɬ. ɞ.).
6.
ɋɨɪɬɢɪɨɜɤɚ ɦɚɫɫɢɜɚ (ɥɸɛɵɦ ɫɩɨɫɨɛɨɦ).
7. Ɉɛɪɚɛɨɬɤɚ ɢɡɨɛɪɚɠɟɧɢɹ (ɨɫɜɟɬɥɟɧɢɟ, ɡɚɬɟɦɧɟɧɢɟ, ɭɫɬɚɧɨɜɤɚ ɩɪɨɡɪɚɱɧɨɫɬɢ). 8. Ʉɨɞɢɪɨɜɚɧɢɟ ɢɡɨɛɪɚɠɟɧɢɹ ɩɨ ɡɚɞɚɧɧɨɦɭ ɤɥɸɱɭ (ɧɚɩɪɢɦɟɪ, ɨɩɟɪɚɰɢɟɣ XOR). 9.
ɒɢɮɪɨɜɚɧɢɟ ɬɟɤɫɬɚ ɦɟɬɨɞɨɦ XOR.
10. Ɋɚɛɨɬɚ ɫɨ ɫɬɪɨɤɨɣ ɬɟɤɫɬɚ: ɜɵɱɢɫɥɟɧɢɟ ɞɥɢɧɵ, ɧɚɯɨɠɞɟɧɢɟ ɩɨɞɫɬɪɨɤɢ, ɧɚɯɨɠɞɟɧɢɟ ɤɨɥɢɱɟɫɬɜɚ ɜɯɨɠɞɟɧɢɣ ɩɨɞɫɬɪɨɤɢ. 11. Ɉɛɪɚɛɨɬɤɚ ɫɬɪɨɤɢ: ɩɟɪɟɜɨɞ ɫɬɪɨɤɢ ɜ ɜɟɪɯɧɢɣ ɢɥɢ ɧɢɠɧɢɣ ɪɟɝɢɫɬɪ. 12. ɉɟɪɟɜɨɞ ɱɢɫɟɥ ɜ ɬɟɤɫɬɨɜɨɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ (ɧɚɩɪɢɦɟɪ, 111 ĺ 'ɫɬɨ ɨɞɢɧɧɚɞɰɚɬɶ'). ɑɢɫɥɚ ɦɨɝɭɬ ɛɵɬɶ ɞɨ 1000000. 82
13. ɉɟɪɟɜɨɞ ɞɚɬ ɜ ɪɚɡɥɢɱɧɵɟ ɬɟɤɫɬɨɜɵɟ ɩɪɟɞɫɬɚɜɥɟɧɢɹ. 14. Ⱥɧɚɥɢɡ html-ɞɨɤɭɦɟɧɬɨɜ. ɇɟɨɛɯɨɞɢɦɨ ɨɛɟɫɩɟɱɢɬɶ ɨɩɟɪɚɰɢɢ ɢɡɜɥɟɱɟɧɢɹ ɫɩɢɫɤɚ ɚɞɪɟɫɨɜ (url) ɜɫɟɯ ɢɡɨɛɪɚɠɟɧɢɣ, ɫɨɞɟɪɠɚɳɢɯɫɹ ɜ ɞɨɤɭɦɟɧɬɟ, ɜɫɟɯ ɫɫɵɥɨɤ ɢ ɜɫɟɯ ɮɨɪɦ, ɚ ɬɚɤɠɟ ɢɡɜɥɟɱɟɧɢɟ ɬɟɤɫɬɨɜɨɝɨ ɫɨɞɟɪɠɚɧɢɹ ɞɨɤɭɦɟɧɬɚ (ɬ. ɟ. ɭɞɚɥɟɧɢɟ ɜɫɟɯ ɬɟɝɨɜ). 15. ɉɨɢɫɤ ɤɪɚɬɱɚɣɲɟɝɨ ɩɭɬɢ ɧɚ ɝɪɚɮɟ. ɉɪɟɞɭɫɦɨɬɪɟɬɶ ɜɨɡɦɨɠɧɨɫɬɶ ɡɚɝɪɭɡɤɢ ɝɪɚɮɚ ɢɡ ɬɟɤɫɬɨɜɨɝɨ ɩɪɟɞɫɬɚɜɥɟɧɢɹ/ɮɚɣɥɚ (ɬ. ɟ. ɬɚɤɠɟ ɬɪɟɛɭɟɬɫɹ ɪɚɡɪɚɛɨɬɚɬɶ ɮɨɪɦɚɬ ɬɟɤɫɬɨɜɨɝɨ ɩɪɟɞɫɬɚɜɥɟɧɢɹ). 16. ɉɟɪɟɜɨɞ ɬɟɤɫɬɚ. ɉɨɞ ɩɟɪɟɜɨɞɨɦ ɩɨɧɢɦɚɟɬɫɹ ɩɪɨɫɬɚɹ ɡɚɦɟɧɚ ɫɥɨɜ. Ɍɚɤɠɟ ɧɟɨɛɯɨɞɢɦɨ ɪɟɚɥɢɡɨɜɚɬɶ ɮɭɧɤɰɢɢ ɡɚɝɪɭɡɤɢ ɫɥɨɜɚɪɟɣ. 17. ȼɵɱɢɫɥɟɧɢɟ ɡɧɚɱɟɧɢɣ ɮɭɧɤɰɢɣ ɨɞɧɨɣ ɩɟɪɟɦɟɧɧɨɣ, ɡɚɞɚɧɧɵɯ ɜ ɬɟɤɫɬɨɜɨɣ ɮɨɪɦɟ, ɧɚɩɪɢɦɟɪ '=x^2+3'. ɂɧɬɟɪɩɪɟɬɚɬɨɪ ɞɨɥɠɟɧ ɩɨɞɞɟɪɠɢɜɚɬɶ ɤɚɤ ɩɪɨɫɬɵɟ ɦɚɬɟɦɚɬɢɱɟɫɤɢɟ ɨɩɟɪɚɰɢɢ (+, –, *, /, ^), ɬɚɤ ɢ ɧɟɤɨɬɨɪɵɣ ɧɚɛɨɪ ɮɭɧɤɰɢɣ (Cos, Sin ɢ ɬ. ɞ.). 18. ȼɵɩɨɥɧɢɬɶ ɩɪɟɞɵɞɭɳɭɸ ɡɚɞɚɱɭ ɞɥɹ ɮɭɧɤɰɢɣ ɧɟɫɤɨɥɶɤɢɯ ɩɟɪɟɦɟɧɧɵɯ. 19. ɏɟɲ-ɬɚɛɥɢɰɚ (ɞɥɹ ɯɪɚɧɟɧɢɹ ɱɢɫɟɥ, ɡɚɩɢɫɟɣ, ɫɬɪɨɤ ɢ ɬ. ɩ.). 20. Ɂɚɝɪɭɡɤɚ ɚɜɬɨɦɨɛɢɥɟɣ. ȿɫɬɶ ɫɩɢɫɨɤ ɚɜɬɨɦɨɛɢɥɟɣ ɢ ɫɩɢɫɨɤ ɝɪɭɡɨɜ, ɬɪɟɛɭɟɬɫɹ ɪɚɫɩɪɟɞɟɥɢɬɶ ɝɪɭɡ ɦɟɠɞɭ ɚɜɬɨɦɨɛɢɥɹɦɢ ɢ ɜ ɤɚɱɟɫɬɜɟ ɪɟɡɭɥɶɬɚɬɚ ɜɵɞɚɬɶ ɫɩɢɫɨɤ ɝɪɭɡɨɜ ɞɥɹ ɤɚɠɞɨɝɨ ɚɜɬɨɦɨɛɢɥɹ.
83
ɋɩɢɫɨɤ ɥɢɬɟɪɚɬɭɪɵ 1. Ⱥɪɯɚɧɝɟɥɶɫɤɢɣ Ⱥ. ə. ɉɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟ ɜ Delphi 6 / Ⱥ. ə. Ⱥɪɯɚɧɝɟɥɶɫɤɢɣ. – Ɇ. : ȻɂɇɈɆ, 2002. – 1120 ɫ. 2. Ȼɨɤɫ Ⱦ. ɋɭɳɧɨɫɬɶ ɬɟɯɧɨɥɨɝɢɢ COM. Ȼɢɛɥɢɨɬɟɤɚ ɩɪɨɝɪɚɦɦɢɫɬɚ / Ⱦ. Ȼɨɤɫ. – ɋɉɛ. : ɉɢɬɟɪ, 2001. – 400 ɫ. 3. Ʌɟɣɧɟɤɟɪ Ɋ. COM+. ɗɧɰɢɤɥɨɩɟɞɢɹ ɩɪɨɝɪɚɦɦɢɫɬɚ / Ɋ. Ʌɟɣɧɟɤɟɪ. – Ɇ. : Ⱦɢɚɋɨɮɬ, 2002. – 656 ɫ. 4. Ɋɨɞɠɟɪɫɨɧ Ⱦ. Ɉɫɧɨɜɵ COM / Ⱦ. Ɋɨɞɠɟɪɫɨɧ ; ɩɟɪ. ɫ ɚɧɝɥ. – 2-ɟ ɢɡɞ., ɢɫɩɪ. ɢ ɞɨɩ. – Ɇ. : Ɋɭɫɫɤɚɹ Ɋɟɞɚɤɰɢɹ, 2000. – 400 ɫ. 5. Ɋɨɮɷɣɥ ɗ. COM ɢ COM+. ɉɨɥɧɨɟ ɪɭɤɨɜɨɞɫɬɜɨ / ɗ. Ɋɨɮɷɣɥ, ə. ɒɨɯɚɭɞ ; ɩɟɪ. ɫ ɚɧɝɥ. – Ʉɢɟɜ : ȼȿɄ+, Ɇ. : ɗɧɬɪɨɩ, 2000. – 560 ɫ. 6. Ɍɟɣɤɫɟɣɪɚ ɋ. Delphi 4. Ɋɭɤɨɜɨɞɫɬɜɨ ɪɚɡɪɚɛɨɬɱɢɤɚ / ɋ. Ɍɟɣɤɫɟɣɪɚ, Ʉ. ɉɚɱɟɤɨ ; ɩɟɪ. ɫ ɚɧɝɥ. – ɋɩɛ. : ȼɢɥɶɹɦɫ, 1999. – 912 ɫ. 7. ɏɚɪɦɨɧ ɗ. Ɋɚɡɪɚɛɨɬɤɚ COM-ɩɪɢɥɨɠɟɧɢɣ ɜ ɫɪɟɞɟ Delphi : ɭɱɟɛ. ɩɨɫɨɛɢɟ / ɗ. ɏɚɪɦɨɧ. – Ɇ. : ȼɢɥɶɹɦɫ, 2000. – 464 ɫ.
ɋɫɵɥɤɢ ɜ Internet 1. MSDN Library. Microsoft Corporation. – http://msdn.microsoft.com/library/ en-us/fileio/base/file_management_functions.asp 2. Ƚɥɭɳɟɧɤɨ ɘ. ɗɤɫɩɨɪɬ ɢɡ ȻȾ ɜ Word. – http://www.delphimaster.ru/ articles/dbtoword/index.html. 3. ȿɥɦɚɧɨɜɚ ɇ. Ⱥɜɬɨɦɚɬɢɡɚɰɢɹ ɩɪɢɥɨɠɟɧɢɣ Microsoft Office ɜ ɩɪɢɦɟɪɚɯ ɑɚɫɬɶ 1. Microsoft Word ɢ Microsoft Excel. – http://www.compress.ru/ Archive/CP/2000/11/25/. 4. Ʉɨɪɨɥɟɜɫɬɜɨ Delphi. ȼɢɪɬɭɚɥɶɧɵɣ ɤɥɭɛ ɩɪɨɝɪɚɦɦɢɫɬɨɜ. http://www.delphikingdom.ru/ 5. ɋɬɚɬɶɢ ɩɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɸ. – http://www.wasm.ru 6. Ɍɟɯɧɨɥɨɝɢɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. – http://www.HiProg.com 7. ɗɥɟɤɬɪɨɧɧɵɟ ɤɧɢɝɢ ɢ ɭɱɟɛɧɢɤɢ ɩɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɸ. http://www.cnt.ru/~wh/x/books_n_manuals.html 8. ɗɥɟɤɬɪɨɧɧɵɣ ɤɚɬɚɥɨɝ ɇɚɭɱɧɨɣ ɛɢɛɥɢɨɬɟɤɢ ȼȽɍ. – http://www.lib.vsu.ru
84
ɍɱɟɛɧɨɟ ɢɡɞɚɧɢɟ
Ⱥɪɬɟɦɨɜ Ɇɢɯɚɢɥ Ⱥɧɚɬɨɥɶɟɜɢɱ, ȼɚɯɬɢɧ Ⱥɥɟɤɫɟɣ Ⱥɥɟɤɫɚɧɞɪɨɜɢɱ, ȼɨɳɢɧɫɤɚɹ Ƚɢɥɶɞɚ ɗɞɝɚɪɨɜɧɚ, Ɋɭɞɚɥɟɜ ȼɚɥɟɪɢɣ Ƚɟɧɧɚɞɶɟɜɢɱ
Ɉɫɧɨɜɵ ɋɈɆ-ɬɟɯɧɨɥɨɝɢɣ ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ
ɉɨɞɩɢɫɚɧɨ ɜ ɩɟɱɚɬɶ 20.08.07. Ɏɨɪɦɚɬ 60×84/16. ɍɫɥ. ɩɟɱ. ɥ. 5. Ɍɢɪɚɠ 50 ɷɤɡ. Ɂɚɤɚɡ 1765. ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. 394000, ɝ. ȼɨɪɨɧɟɠ, ɩɥ. ɢɦ. Ʌɟɧɢɧɚ, 10. Ɍɟɥ. 208-298, 598-026 (ɮɚɤɫ) http://www.ppc.vsu.ru; e-mail:
[email protected] Ɉɬɩɟɱɚɬɚɧɨ ɜ ɬɢɩɨɝɪɚɮɢɢ ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɨɝɨ ɰɟɧɬɪɚ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. 394000, ɝ. ȼɨɪɨɧɟɠ, ɭɥ. ɉɭɲɤɢɧɫɤɚɹ, 3. Ɍɟɥ. 204-133. 85