Разработка компонентов в DELPHI. Вощинская Г.Э. - 6 стр.

UptoLike

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

ɜɚɧɧɨɝɨ ɩɨɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɦɨɠɧɨ ɨɩɪɟɞɟɥɢɬɶ ɧɨɜɵɣ ɤɨɦɩɨɧɟɧɬ ɤɚɤ ɩɨ-
ɬɨɦɨɤ ɤɥɚɫɫɚ TCustomEdit ɢ ɫɞɟɥɚɬɶ ɧɭɠɧɵɟ ɦɨɞɢɮɢɤɚɰɢɢ.
Ʉɨɦɩɨɧɟɧɬɵ ɞɟɥɹɬɫɹ ɧɚ ɞɜɟ ɝɪɭɩɩɵɜɢɡɭɚɥɶɧɵɟ ɢ ɧɟɜɢɡɭɚɥɶɧɵɟ.
ȼɢɡɭɚɥɶɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɨɬɨɛɪɚɠɚɸɬɫɹ ɧɚ ɮɨɪɦɟ ɜɨ ɜɪɟɦɹ ɪɚɛɨɬɵ ɩɪɨ-
ɝɪɚɦɦɵ. Ɉɧɢ ɹɜɥɹɸɬɫɹ ɩɨɬɨɦɤɚɦɢ ɤɥɚɫɫɚ TControl ɢ ɩɨɷɬɨɦɭ ɢɧɨɝɞɚ ɧɚ-
ɡɵɜɚɸɬɫɹ ɷɥɟɦɟɧɬɚɦɢ ɭɩɪɚɜɥɟɧɢɹ. ɉɪɢɦɟɪɚɦɢ ɧɟɜɢɡɭɚɥɶɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ
ɹɜɥɹɸɬɫɹ ɤɨɦɩɨɧɟɧɬɵ Ttimer, TMenu, TOpenDialog, ɤɨɦɩɨɧɟɧɬɵ ɞɨɫ-
ɬɭɩɚ ɤ ɛɚɡɚɦ ɞɚɧɧɵɯ (TTable, TQuery ɢɬ. ɩ.). ɇɟɜɢɡɭɚɥɶɧɵɟ ɤɨɦɩɨɧɟɧ-
ɬɵ ɧɟ ɜɢɞɧɵ ɧɚ ɮɨɪɦɟ ɢ ɪɚɛɨɬɚɸɬ «ɡɚ ɤɭɥɢɫɚɦɢ» ɩɪɢɥɨɠɟɧɢɹ. ɂɯ ɩɪɟɞɤɨɦ
ɧɟ ɹɜɥɹɟɬɫɹ TControl, ɚ ɧɚɫɥɟɞɨɜɚɧɢɟ ɢɞɟɬ ɨɬ Tcomponent
.
ȼɢɡɭɚɥɶɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɞɟɥɹɬɫɹ ɧɚ ɞɜɟ ɝɪɭɩɩɵɝɪɚɮɢɱɟɫɤɢɟ ɢ ɨɤɨɧ-
ɧɵɟ. Ƚɪɚɮɢɱɟɫɤɢɟ ɤɨɦɩɨɧɟɧɬɵ ɩɨɪɨɠɞɚɸɬɫɹ ɨɬ TGraphicControl ɢɢɦɟ-
ɸɬ ɜɢɡɭɚɥɶɧɨɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ, ɧɨ ɧɟ ɩɨɥɭɱɚɸɬ ɮɨɤɭɫɚ ɜɜɨɞɚ. Ƚɥɚɜɧɨɣ ɨɫɨ-
ɛɟɧɧɨɫɬɶɸ ɩɨɬɨɦɤɨɜ TGraphicControl ɹɜɥɹɟɬɫɹ ɧɚɥɢɱɢɟ ɫɜɨɣɫɬɜɚ Can-
vas: TCanvas, ɩɨɡɜɨɥɹɸɳɟɝɨ ɜɵɜɨɞɢɬɶ ɢɡɨɛɪɚɠɟɧɢɟ ɩɪɹɦɨ ɧɚ ɩɨɜɟɪɯɧɨ-
ɫɬɢ ɤɨɦɩɨɧɟɧɬɚ. ɉɪɢɦɟɪɚɦɢ ɝɪɚɮɢɱɟɫɤɢɯ ɤɨɦɩɨɧɟɧɬɨɜ ɹɜɥɹɸɬɫɹ TImage,
TPaintBox, TLabel.
Ɉɤɨɧɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɩɪɨɢɫɯɨɞɹɬ ɨɬ TWinControl. Ɉɧɢ ɢɧɤɚɩɫɭ-
ɥɢɪɭɸɬ ɮɭɧɤɰɢɢ API ɞɥɹ ɪɚɛɨɬɵ ɫ ɨɤɧɚɦɢ Windows, ɭɦɟɸɬ ɩɨɥɭɱɚɬɶ ɮɨ-
ɤɭɫ ɜɜɨɞɚ ɢ ɫɨɞɟɪɠɚɬ ɫɜɨɣɫɬɜɨ Handle: THandle. Ⱦɚɧɧɨɟ ɫɜɨɣɫɬɜɨ ɯɪɚ-
ɧɢɬ ɞɟɫɤɪɢɩɬɨɪ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɨɤɨɧɧɨɝɨ ɨɛɴɟɤɬɚ Windows ɢ ɦɨɠɟɬ
ɛɵɬɶ ɢɫɩɨɥɶɡɨɜɚɧɨ ɞɥɹ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨɝɨ ɜɵɡɨɜɚ ɮɭɧɤɰɢɣ API ɢ ɨɛɦɟɧɚ
ɫɨɨɛɳɟɧɢɹɦɢ Windows ɦɟɠɞɭ ɤɨɦɩɨɧɟɧɬɚɦɢ.
ɂɧɨɝɞɚ ɞɥɹ ɫɨɡɞɚɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɝɨ ɷɥɟɦɟɧɬɚ ɭɩɪɚɜɥɟɧɢɹ ɢɫ-
ɩɨɥɶɡɭɟɬɫɹ ɤɥɚɫɫ TCustomControl. ɗɬɨ ɩɪɹɦɨɣ ɩɨɬɨɦɨɤ TWinControl,
ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɧɚɫɥɟɞɭɸɳɢɣ ɜɫɸ ɟɝɨ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ. ɇɨ ɞɨɩɨɥɧɢɬɟɥɶ-
ɧɨ ɨɧ ɜ ɫɟɤɰɢɢ Protected ɫɨɞɟɪɠɢɬ ɫɜɨɣɫɬɜɨ Canvas, ɧɟɨɛɯɨɞɢɦɨɟ ɞɥɹ
ɪɢɫɨɜɚɧɢɹ. ɑɬɨɛɵ ɢɫɩɨɥɶɡɨɜɚɬɶ ɷɬɨ ɫɜɨɣɫɬɜɨ ɜ ɩɨɬɨɦɤɚɯ
6
ɜɚɧɧɨɝɨ ɩɨɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɦɨɠɧɨ ɨɩɪɟɞɟɥɢɬɶ ɧɨɜɵɣ ɤɨɦɩɨɧɟɧɬ ɤɚɤ ɩɨ-
ɬɨɦɨɤ ɤɥɚɫɫɚ TCustomEdit ɢ ɫɞɟɥɚɬɶ ɧɭɠɧɵɟ ɦɨɞɢɮɢɤɚɰɢɢ.
     Ʉɨɦɩɨɧɟɧɬɵ ɞɟɥɹɬɫɹ ɧɚ ɞɜɟ ɝɪɭɩɩɵ – ɜɢɡɭɚɥɶɧɵɟ ɢ ɧɟɜɢɡɭɚɥɶɧɵɟ.
ȼɢɡɭɚɥɶɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɨɬɨɛɪɚɠɚɸɬɫɹ ɧɚ ɮɨɪɦɟ ɜɨ ɜɪɟɦɹ ɪɚɛɨɬɵ ɩɪɨ-
ɝɪɚɦɦɵ. Ɉɧɢ ɹɜɥɹɸɬɫɹ ɩɨɬɨɦɤɚɦɢ ɤɥɚɫɫɚ TControl ɢ ɩɨɷɬɨɦɭ ɢɧɨɝɞɚ ɧɚ-
ɡɵɜɚɸɬɫɹ ɷɥɟɦɟɧɬɚɦɢ ɭɩɪɚɜɥɟɧɢɹ. ɉɪɢɦɟɪɚɦɢ ɧɟɜɢɡɭɚɥɶɧɵɯ ɤɨɦɩɨɧɟɧɬɨɜ
ɹɜɥɹɸɬɫɹ ɤɨɦɩɨɧɟɧɬɵ Ttimer, TMenu, TOpenDialog, ɤɨɦɩɨɧɟɧɬɵ ɞɨɫ-
ɬɭɩɚ ɤ ɛɚɡɚɦ ɞɚɧɧɵɯ (TTable, TQuery ɢ ɬ. ɩ.). ɇɟɜɢɡɭɚɥɶɧɵɟ ɤɨɦɩɨɧɟɧ-
ɬɵ ɧɟ ɜɢɞɧɵ ɧɚ ɮɨɪɦɟ ɢ ɪɚɛɨɬɚɸɬ «ɡɚ ɤɭɥɢɫɚɦɢ» ɩɪɢɥɨɠɟɧɢɹ. ɂɯ ɩɪɟɞɤɨɦ
ɧɟ ɹɜɥɹɟɬɫɹ TControl, ɚ ɧɚɫɥɟɞɨɜɚɧɢɟ ɢɞɟɬ ɨɬ Tcomponent.
     ȼɢɡɭɚɥɶɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɞɟɥɹɬɫɹ ɧɚ ɞɜɟ ɝɪɭɩɩɵ – ɝɪɚɮɢɱɟɫɤɢɟ ɢ ɨɤɨɧ-
ɧɵɟ. Ƚɪɚɮɢɱɟɫɤɢɟ ɤɨɦɩɨɧɟɧɬɵ ɩɨɪɨɠɞɚɸɬɫɹ ɨɬ TGraphicControl ɢ ɢɦɟ-
ɸɬ ɜɢɡɭɚɥɶɧɨɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ, ɧɨ ɧɟ ɩɨɥɭɱɚɸɬ ɮɨɤɭɫɚ ɜɜɨɞɚ. Ƚɥɚɜɧɨɣ ɨɫɨ-
ɛɟɧɧɨɫɬɶɸ ɩɨɬɨɦɤɨɜ TGraphicControl ɹɜɥɹɟɬɫɹ ɧɚɥɢɱɢɟ ɫɜɨɣɫɬɜɚ Can-
vas: TCanvas, ɩɨɡɜɨɥɹɸɳɟɝɨ ɜɵɜɨɞɢɬɶ ɢɡɨɛɪɚɠɟɧɢɟ ɩɪɹɦɨ ɧɚ ɩɨɜɟɪɯɧɨ-
ɫɬɢ ɤɨɦɩɨɧɟɧɬɚ. ɉɪɢɦɟɪɚɦɢ ɝɪɚɮɢɱɟɫɤɢɯ ɤɨɦɩɨɧɟɧɬɨɜ ɹɜɥɹɸɬɫɹ TImage,
TPaintBox, TLabel.
     Ɉɤɨɧɧɵɟ ɤɨɦɩɨɧɟɧɬɵ ɩɪɨɢɫɯɨɞɹɬ ɨɬ TWinControl. Ɉɧɢ ɢɧɤɚɩɫɭ-
ɥɢɪɭɸɬ ɮɭɧɤɰɢɢ API ɞɥɹ ɪɚɛɨɬɵ ɫ ɨɤɧɚɦɢ Windows, ɭɦɟɸɬ ɩɨɥɭɱɚɬɶ ɮɨ-
ɤɭɫ ɜɜɨɞɚ ɢ ɫɨɞɟɪɠɚɬ ɫɜɨɣɫɬɜɨ Handle: THandle. Ⱦɚɧɧɨɟ ɫɜɨɣɫɬɜɨ ɯɪɚ-
ɧɢɬ ɞɟɫɤɪɢɩɬɨɪ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɨɤɨɧɧɨɝɨ ɨɛɴɟɤɬɚ Windows ɢ ɦɨɠɟɬ
ɛɵɬɶ ɢɫɩɨɥɶɡɨɜɚɧɨ ɞɥɹ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨɝɨ ɜɵɡɨɜɚ ɮɭɧɤɰɢɣ API ɢ ɨɛɦɟɧɚ
ɫɨɨɛɳɟɧɢɹɦɢ Windows ɦɟɠɞɭ ɤɨɦɩɨɧɟɧɬɚɦɢ.
     ɂɧɨɝɞɚ ɞɥɹ ɫɨɡɞɚɧɢɹ ɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɝɨ ɷɥɟɦɟɧɬɚ ɭɩɪɚɜɥɟɧɢɹ ɢɫ-
ɩɨɥɶɡɭɟɬɫɹ ɤɥɚɫɫ TCustomControl. ɗɬɨ ɩɪɹɦɨɣ ɩɨɬɨɦɨɤ TWinControl,
ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɧɚɫɥɟɞɭɸɳɢɣ ɜɫɸ ɟɝɨ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ. ɇɨ ɞɨɩɨɥɧɢɬɟɥɶ-
ɧɨ ɨɧ ɜ ɫɟɤɰɢɢ Protected ɫɨɞɟɪɠɢɬ ɫɜɨɣɫɬɜɨ Canvas, ɧɟɨɛɯɨɞɢɦɨɟ ɞɥɹ
ɪɢɫɨɜɚɧɢɹ.   ɑɬɨɛɵ    ɢɫɩɨɥɶɡɨɜɚɬɶ    ɷɬɨ    ɫɜɨɣɫɬɜɨ   ɜ    ɩɨɬɨɦɤɚɯ

                                  6