Введение в технологию программирования. Ч.1. Среда объектно-ориентированного программирования Delphi. Коржов Е.Н - 9 стр.

UptoLike

Составители: 

9
ɷɬɨɦ ɫɩɢɫɤɟ. ȼ ɨɬɥɢɱɢɟ ɨɬ ɩɪɟɞɵɞɭɳɢɯ ɜɟɪɫɢɣ ɪɚɫɤɪɵɜɚɸɳɢɣɫɹ ɫɩɢɫɨɤ
ɫɨɞɟɪɠɢɬ ɧɟ ɬɨɥɶɤɨ ɢɦɟɧɚ ɤɨɦɩɨɧɟɧɬɨɜ, ɧɨ ɢ ɢɯ ɤɥɚɫɫɵ.
1.4. Ɉɤɧɨ ɞɟɪɟɜɚ ɨɛɴɟɤɬɨɜ
ɗɬɨ ɨɤɧɨ ɩɨɹɜɢɥɨɫɶ ɜ ɜɟɪɫɢɢ 6 ɢ ɩɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɧɚɝɥɹɞɧɨɝɨ ɨɬɨ-
ɛɪɚɠɟɧɢɹ ɫɜɹɡɟɣ ɦɟɠɞɭ ɨɬɞɟɥɶɧɵɦɢ ɤɨɦɩɨɧɟɧɬɚɦɢ, ɪɚɡɦɟɳɟɧɧɵɦɢ ɧɚ ɚɤ-
ɬɢɜɧɨɣ ɮɨɪɦɟ ɢɥɢ ɜ ɚɤɬɢɜɧɨɦ ɦɨɞɭɥɟ ɞɚɧɧɵɯ. ɓɟɥɱɨɤ ɩɨ ɥɸɛɨɦɭ ɤɨɦɩɨ-
ɧɟɧɬɭ ɜ ɷɬɨɦ ɨɤɧɟ ɚɤɬɢɜɢɡɢɪɭɟɬ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɤɨɦɩɨɧɟɧɬ ɜ ɨɤɧɟ ɮɨɪ-
ɦɵ ɢ ɨɬɨɛɪɚɠɚɟɬ ɫɜɨɣɫɬɜɚ ɷɬɨɝɨ ɤɨɦɩɨɧɟɧɬɚ ɜ ɨɤɧɟ ɂɧɫɩɟɤɬɨɪɚ ɨɛɴɟɤɬɨɜ.
Ⱦɜɨɣɧɨɣ ɳɟɥɱɨɤ ɩɪɢɜɨɞɢɬ ɤ ɫɪɚɛɚɬɵɜɚɧɢɸ ɦɟɯɚɧɢɡɦɚ Code Insight, ɤɨɬɨ-
ɪɵɣ ɜɫɬɚɜɥɹɟɬ ɜ ɨɤɧɨ ɤɨɞɚ ɡɚɝɨɬɨɜɤɭ ɞɥɹ ɨɛɪɚɛɨɬɱɢɤɚ ɫɨɛɵɬɢɹ OnClick.
ɇɚɤɨɧɟɰ, ɤɨɦɩɨɧɟɧɬ ɦɨɠɧɨ «ɩɟɪɟɬɚɳɢɬɶ» ɜ ɨɤɧɟ ɢ ɬɚɤɢɦ ɨɛɪɚɡɨɦ ɩɨɦɟ-
ɧɹɬɶ ɟɝɨ ɜɥɚɞɟɥɶɰɚ (ɫɜɨɣɫɬɜɨ parent). ȼ ɩɪɟɞɵɞɭɳɢɯ ɜɟɪɫɢɹɯ ɬɚɤɭɸ ɡɚɦɟ-
ɧɭ ɦɨɠɧɨ ɛɵɥɨ ɫɞɟɥɚɬɶ ɬɨɥɶɤɨ ɫ ɩɨɦɨɳɶɸ ɦɟɠɩɪɨɝɪɚɦɦɧɨɝɨ ɛɭɮɟɪɚ ɨɛ-
ɦɟɧɚ Clipboard.
1.5. Ɉɤɧɨ ɤɨɞɚ ɩɪɨɝɪɚɦɦɵ
Ɉɤɧɨ ɤɨɞɚ ɩɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɫɨɡɞɚɧɢɹ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɬɟɤɫɬɚ ɩɪɨ-
ɝɪɚɦɦɵ. ɗɬɨɬ ɬɟɤɫɬ ɫɨɫɬɚɜɥɹɟɬɫɹ ɩɨ ɫɩɟɰɢɚɥɶɧɵɦ ɩɪɚɜɢɥɚɦ ɢ ɨɩɢɫɵɜɚɟɬ
ɚɥɝɨɪɢɬɦ ɪɚɛɨɬɵ ɩɪɨɝɪɚɦɦɵ. ɋɨɜɨɤɭɩɧɨɫɬɶ ɩɪɚɜɢɥ ɡɚɩɢɫɢ ɬɟɤɫɬɚ ɧɚɡɵɜɚ-
ɟɬɫɹ ɹɡɵɤɨɦ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. ȼ ɫɢɫɬɟɦɟ Delphi ɢɫɩɨɥɶɡɭɟɬɫɹ ɹɡɵɤ ɩɪɨ-
ɝɪɚɦɦɢɪɨɜɚɧɢɹ Object Pascal, ɤɨɬɨɪɵɣ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɪɚɫɲɢɪɟɧɧɭɸ ɢ
ɭɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɧɭɸ ɜɟɪɫɢɸ ɲɢɪɨɤɨ ɪɚɫɩɪɨɫɬɪɚɧɟɧɧɨɝɨ ɹɡɵɤɚ ɉɚɫɤɚɥɶ,
ɜɩɟɪɜɵɟ ɩɪɟɞɥɨɠɟɧɧɨɝɨ ɲɜɟɣɰɚɪɫɤɢɦ ɭɱɟɧɵɦ ɇ. ȼɢɪɬɨɦ ɟɳɟ ɜ 1970 ɝ. ɢ
ɭɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɧɨɝɨ ɫɨɬɪɭɞɧɢɤɚɦɢ ɤɨɪɩɨɪɚɰɢɢ Borland (ɫɨɡɞɚɧɧɵɟ ɢɦɢ
ɹɡɵɤɢ ɧɚɡɵɜɚɥɢɫɶ Turbo Pascal, Borland Pascal ɢ Object Pascal). ɇɟɫɦɨɬɪɹ
ɧɚ ɬɨ, ɱɬɨ ɜɢɡɭɚɥɶɧɚɹ ɫɪɟɞɚ Delphi ɛɟɪɟɬ ɧɚ ɫɟɛɹ ɦɧɨɝɢɟ ɪɭɬɢɧɧɵɟ ɚɫɩɟɤɬɵ
ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɡɧɚɧɢɟ ɹɡɵɤɚ Object Pascal ɹɜɥɹɟɬɫɹ ɧɟɩɪɟɦɟɧɧɵɦ ɭɫ
-
ɥɨɜɢɟɦ ɞɥɹ ɥɸɛɨɝɨ ɩɪɨɝɪɚɦɦɢɫɬɚ, ɪɚɛɨɬɚɸɳɟɝɨ ɜ ɷɬɨɣ ɫɪɟɞɟ.
ɉɪɨɝɪɚɦɦɚ ɜ ɫɪɟɞɟ Delphi ɫɨɫɬɚɜɥɹɟɬɫɹ ɤɚɤ ɨɩɢɫɚɧɢɟ ɚɥɝɨɪɢɬɦɨɜ, ɤɨ-
ɬɨɪɵɟ ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ, ɟɫɥɢ ɜɨɡɧɢɤɚɟɬ ɨɩɪɟɞɟɥɟɧɧɨɟ ɫɨɛɵɬɢɟ, ɫɜɹ-
ɡɚɧɧɨɟ ɫ ɮɨɪɦɨɣ (ɧɚɩɪɢɦɟɪ, ɳɟɥɱɨɤ ɦɵɲɢ ɧɚ ɤɧɨɩɤɟɫɨɛɵɬɢɟ OnClick,
ɫɨɡɞɚɧɢɟ ɮɨɪɦɵOnCreate). Ⱦɥɹ ɤɚɠɞɨɝɨ ɨɛɪɚɛɚɬɵɜɚɟɦɨɝɨ ɜ ɮɨɪɦɟ ɫɨ-
ɛɵɬɢɹ, ɫ ɩɨɦɨɳɶɸ ɫɬɪɚɧɢɰɵ Events ɢɧɫɩɟɤɬɨɪɚ ɨɛɴɟɤɬɨɜ ɜ ɬɟɤɫɬɟ ɩɪɨ-
ɝɪɚɦɦɵ ɨɪɝɚɧɢɡɭɟɬɫɹ ɩɪɨɰɟɞɭɪɚ (procedure), ɦɟɠɞɭ ɤɥɸɱɟɜɵɦɢ ɫɥɨɜɚɦɢ
begin ɢ end ɤɨɬɨɪɨɣ ɩɪɨɝɪɚɦɦɢɫɬ ɡɚɩɢɫɵɜɚɟɬ ɧɚ ɹɡɵɤɟ Object Pascal ɬɪɟ-
ɛɭɟɦɵɣ ɚɥɝɨɪɢɬɦ.
ɉɟɪɟɤɥɸɱɟɧɢɟ ɦɟɠɞɭ ɨɤɧɨɦ ɮɨɪɦɵ ɢ ɨɤɧɨɦ ɬɟɤɫɬɚ ɩɪɨɝɪɚɦɦɵ ɨɫɭ-
ɳɟɫɬɜɥɹɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɤɥɚɜɢɲɢ F12.
ɉɟɪɜɨɧɚɱɚɥɶɧɨ ɨɤɧɨ ɤɨɞɚ ɫɨɞɟɪɠɢɬ ɦɢɧɢɦɚɥɶɧɵɣ ɢɫɯɨɞɧɵɣ ɬɟɤɫɬ,
ɨɛɟɫɩɟɱɢɜɚɸɳɢɣ ɧɨɪɦɚɥɶɧɨɟ ɮɭɧɤɰɢɨɧɢɪɨɜɚɧɢɟ ɩɭɫɬɨɣ ɮɨɪɦɵ ɜ ɤɚɱɟɫɬɜɟ
ɩɨɥɧɨɰɟɧɧɨɝɨ Windows-ɨɤɧɚ. ȼ ɯɨɞɟ ɪɚɛɨɬɵ ɧɚɞ ɩɪɨɟɤɬɨɦ ɩɪɨɝɪɚɦɦɢɫɬ
ɷɬɨɦ ɫɩɢɫɤɟ. ȼ ɨɬɥɢɱɢɟ ɨɬ ɩɪɟɞɵɞɭɳɢɯ ɜɟɪɫɢɣ ɪɚɫɤɪɵɜɚɸɳɢɣɫɹ ɫɩɢɫɨɤ
ɫɨɞɟɪɠɢɬ ɧɟ ɬɨɥɶɤɨ ɢɦɟɧɚ ɤɨɦɩɨɧɟɧɬɨɜ, ɧɨ ɢ ɢɯ ɤɥɚɫɫɵ.

                         1.4. Ɉɤɧɨ ɞɟɪɟɜɚ ɨɛɴɟɤɬɨɜ
      ɗɬɨ ɨɤɧɨ ɩɨɹɜɢɥɨɫɶ ɜ ɜɟɪɫɢɢ 6 ɢ ɩɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɧɚɝɥɹɞɧɨɝɨ ɨɬɨ-
ɛɪɚɠɟɧɢɹ ɫɜɹɡɟɣ ɦɟɠɞɭ ɨɬɞɟɥɶɧɵɦɢ ɤɨɦɩɨɧɟɧɬɚɦɢ, ɪɚɡɦɟɳɟɧɧɵɦɢ ɧɚ ɚɤ-
ɬɢɜɧɨɣ ɮɨɪɦɟ ɢɥɢ ɜ ɚɤɬɢɜɧɨɦ ɦɨɞɭɥɟ ɞɚɧɧɵɯ. ɓɟɥɱɨɤ ɩɨ ɥɸɛɨɦɭ ɤɨɦɩɨ-
ɧɟɧɬɭ ɜ ɷɬɨɦ ɨɤɧɟ ɚɤɬɢɜɢɡɢɪɭɟɬ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɤɨɦɩɨɧɟɧɬ ɜ ɨɤɧɟ ɮɨɪ-
ɦɵ ɢ ɨɬɨɛɪɚɠɚɟɬ ɫɜɨɣɫɬɜɚ ɷɬɨɝɨ ɤɨɦɩɨɧɟɧɬɚ ɜ ɨɤɧɟ ɂɧɫɩɟɤɬɨɪɚ ɨɛɴɟɤɬɨɜ.
Ⱦɜɨɣɧɨɣ ɳɟɥɱɨɤ ɩɪɢɜɨɞɢɬ ɤ ɫɪɚɛɚɬɵɜɚɧɢɸ ɦɟɯɚɧɢɡɦɚ Code Insight, ɤɨɬɨ-
ɪɵɣ ɜɫɬɚɜɥɹɟɬ ɜ ɨɤɧɨ ɤɨɞɚ ɡɚɝɨɬɨɜɤɭ ɞɥɹ ɨɛɪɚɛɨɬɱɢɤɚ ɫɨɛɵɬɢɹ OnClick.
ɇɚɤɨɧɟɰ, ɤɨɦɩɨɧɟɧɬ ɦɨɠɧɨ «ɩɟɪɟɬɚɳɢɬɶ» ɜ ɨɤɧɟ ɢ ɬɚɤɢɦ ɨɛɪɚɡɨɦ ɩɨɦɟ-
ɧɹɬɶ ɟɝɨ ɜɥɚɞɟɥɶɰɚ (ɫɜɨɣɫɬɜɨ parent). ȼ ɩɪɟɞɵɞɭɳɢɯ ɜɟɪɫɢɹɯ ɬɚɤɭɸ ɡɚɦɟ-
ɧɭ ɦɨɠɧɨ ɛɵɥɨ ɫɞɟɥɚɬɶ ɬɨɥɶɤɨ ɫ ɩɨɦɨɳɶɸ ɦɟɠɩɪɨɝɪɚɦɦɧɨɝɨ ɛɭɮɟɪɚ ɨɛ-
ɦɟɧɚ Clipboard.

                         1.5. Ɉɤɧɨ ɤɨɞɚ ɩɪɨɝɪɚɦɦɵ
      Ɉɤɧɨ ɤɨɞɚ ɩɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɫɨɡɞɚɧɢɹ ɢ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɬɟɤɫɬɚ ɩɪɨ-
ɝɪɚɦɦɵ. ɗɬɨɬ ɬɟɤɫɬ ɫɨɫɬɚɜɥɹɟɬɫɹ ɩɨ ɫɩɟɰɢɚɥɶɧɵɦ ɩɪɚɜɢɥɚɦ ɢ ɨɩɢɫɵɜɚɟɬ
ɚɥɝɨɪɢɬɦ ɪɚɛɨɬɵ ɩɪɨɝɪɚɦɦɵ. ɋɨɜɨɤɭɩɧɨɫɬɶ ɩɪɚɜɢɥ ɡɚɩɢɫɢ ɬɟɤɫɬɚ ɧɚɡɵɜɚ-
ɟɬɫɹ ɹɡɵɤɨɦ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. ȼ ɫɢɫɬɟɦɟ Delphi ɢɫɩɨɥɶɡɭɟɬɫɹ ɹɡɵɤ ɩɪɨ-
ɝɪɚɦɦɢɪɨɜɚɧɢɹ Object Pascal, ɤɨɬɨɪɵɣ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɪɚɫɲɢɪɟɧɧɭɸ ɢ
ɭɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɧɭɸ ɜɟɪɫɢɸ ɲɢɪɨɤɨ ɪɚɫɩɪɨɫɬɪɚɧɟɧɧɨɝɨ ɹɡɵɤɚ ɉɚɫɤɚɥɶ,
ɜɩɟɪɜɵɟ ɩɪɟɞɥɨɠɟɧɧɨɝɨ ɲɜɟɣɰɚɪɫɤɢɦ ɭɱɟɧɵɦ ɇ. ȼɢɪɬɨɦ ɟɳɟ ɜ 1970 ɝ. ɢ
ɭɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɧɨɝɨ ɫɨɬɪɭɞɧɢɤɚɦɢ ɤɨɪɩɨɪɚɰɢɢ Borland (ɫɨɡɞɚɧɧɵɟ ɢɦɢ
ɹɡɵɤɢ ɧɚɡɵɜɚɥɢɫɶ Turbo Pascal, Borland Pascal ɢ Object Pascal). ɇɟɫɦɨɬɪɹ
ɧɚ ɬɨ, ɱɬɨ ɜɢɡɭɚɥɶɧɚɹ ɫɪɟɞɚ Delphi ɛɟɪɟɬ ɧɚ ɫɟɛɹ ɦɧɨɝɢɟ ɪɭɬɢɧɧɵɟ ɚɫɩɟɤɬɵ
ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɡɧɚɧɢɟ ɹɡɵɤɚ Object Pascal ɹɜɥɹɟɬɫɹ ɧɟɩɪɟɦɟɧɧɵɦ ɭɫ-
ɥɨɜɢɟɦ ɞɥɹ ɥɸɛɨɝɨ ɩɪɨɝɪɚɦɦɢɫɬɚ, ɪɚɛɨɬɚɸɳɟɝɨ ɜ ɷɬɨɣ ɫɪɟɞɟ.
      ɉɪɨɝɪɚɦɦɚ ɜ ɫɪɟɞɟ Delphi ɫɨɫɬɚɜɥɹɟɬɫɹ ɤɚɤ ɨɩɢɫɚɧɢɟ ɚɥɝɨɪɢɬɦɨɜ, ɤɨ-
ɬɨɪɵɟ ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ, ɟɫɥɢ ɜɨɡɧɢɤɚɟɬ ɨɩɪɟɞɟɥɟɧɧɨɟ ɫɨɛɵɬɢɟ, ɫɜɹ-
ɡɚɧɧɨɟ ɫ ɮɨɪɦɨɣ (ɧɚɩɪɢɦɟɪ, ɳɟɥɱɨɤ ɦɵɲɢ ɧɚ ɤɧɨɩɤɟ – ɫɨɛɵɬɢɟ OnClick,
ɫɨɡɞɚɧɢɟ ɮɨɪɦɵ – OnCreate). Ⱦɥɹ ɤɚɠɞɨɝɨ ɨɛɪɚɛɚɬɵɜɚɟɦɨɝɨ ɜ ɮɨɪɦɟ ɫɨ-
ɛɵɬɢɹ, ɫ ɩɨɦɨɳɶɸ ɫɬɪɚɧɢɰɵ Events ɢɧɫɩɟɤɬɨɪɚ ɨɛɴɟɤɬɨɜ ɜ ɬɟɤɫɬɟ ɩɪɨ-
ɝɪɚɦɦɵ ɨɪɝɚɧɢɡɭɟɬɫɹ ɩɪɨɰɟɞɭɪɚ (procedure), ɦɟɠɞɭ ɤɥɸɱɟɜɵɦɢ ɫɥɨɜɚɦɢ
begin ɢ end ɤɨɬɨɪɨɣ ɩɪɨɝɪɚɦɦɢɫɬ ɡɚɩɢɫɵɜɚɟɬ ɧɚ ɹɡɵɤɟ Object Pascal ɬɪɟ-
ɛɭɟɦɵɣ ɚɥɝɨɪɢɬɦ.
      ɉɟɪɟɤɥɸɱɟɧɢɟ ɦɟɠɞɭ ɨɤɧɨɦ ɮɨɪɦɵ ɢ ɨɤɧɨɦ ɬɟɤɫɬɚ ɩɪɨɝɪɚɦɦɵ ɨɫɭ-
ɳɟɫɬɜɥɹɟɬɫɹ ɫ ɩɨɦɨɳɶɸ ɤɥɚɜɢɲɢ F12.
      ɉɟɪɜɨɧɚɱɚɥɶɧɨ ɨɤɧɨ ɤɨɞɚ ɫɨɞɟɪɠɢɬ ɦɢɧɢɦɚɥɶɧɵɣ ɢɫɯɨɞɧɵɣ ɬɟɤɫɬ,
ɨɛɟɫɩɟɱɢɜɚɸɳɢɣ ɧɨɪɦɚɥɶɧɨɟ ɮɭɧɤɰɢɨɧɢɪɨɜɚɧɢɟ ɩɭɫɬɨɣ ɮɨɪɦɵ ɜ ɤɚɱɟɫɬɜɟ
ɩɨɥɧɨɰɟɧɧɨɝɨ Windows-ɨɤɧɚ. ȼ ɯɨɞɟ ɪɚɛɨɬɵ ɧɚɞ ɩɪɨɟɤɬɨɦ ɩɪɨɝɪɚɦɦɢɫɬ

                                   9