«á¤@­¶
«e¤@­¶
¦^¥Ø¿ý
¦^­º­¶
²Ä¤G³¹¡@Delphi­±¦Vª«¥óªºµ{¦¡³]­p¤èªk¡]¥|¡^

2.1.10.7 ±N®w³æ¤¸¥[¤J¤uµ{¡@

        ±N®w³æ¤¸¥[¤J¤uµ{¬O¤ñ¸û²³æªº¡CµL½×¬O±z¦Û¤v«Ø¥ßªº®w³æ¤¸ÁÙ¬ODelphi«Ø¥ßªº»Pµ¡Å馳Ãöªº®w³æ¤¸¡A¦pªG¤w¸g§¹¦¨¡A«h¥ý¥´¶}±z·Q¥[¤J®w³æ¤¸ªº¤uµ{(¥i¥H¥ÎOpen Project¥´¶}¤uµ{)¡F¦A¿ï¥ÎFile|Open File¡AµM«á¿ï¾Ü±z·Q¥[¤Jªº­ì©lµ{¦¡(.PAS¤å¥ó)¡A¨Ã¿ï¾ÜOK§Y¥i¡C«h®w³æ¤¸³Q¥[¤J¨ìÀ³¥Îµ{¦¡¤¤¡C¡@

2.2 ¥ÎDelphiªºª«¥ó¶i¦æµ{¦¡³]­p¡@

        Delphi¬O°ò©ó­±¦Vª«¥óµ{¦¡³]­pªº¥ý¶i¶}µoÀô¹Ò¡C­±¦Vª«¥óªºµ{¦¡³]­p(OOP)¬Oµ²ºc¤Æ»y¨¥ªº¦ÛµM©µ¦ù¡COOPªº¥ý¶iµ{¦¡³]­p¤èªk¡A·|²£¥Í¤@­Ó²M´·¦Ó¤S®e©öÂX®i¤ÎºûÅ@ªºµ{¦¡¡C¤@¥¹±z¬°±zªºµ{¦¡«Ø¥ß¤F¤@­Óª«¥ó¡A±z©M¨ä¥Lªºµ{¦¡­û¥i¥H¦b¨ä¥Lªºµ{¦¡¤¤¨Ï¥Î³o­Óª«¥ó¡A§¹¥þ¤£¥²­«·s½s¨îÁc´_ªº¥N½X¡Cª«¥óªº­«½Æ¨Ï¥Î¥i¥H¤j¤j¦a¸`¬Ù¶}µo®É¶¡¡A¤Á¹ê¦a´£°ª±z©M¨ä¥L¤Hªº¤u§@®Ä²v¡C¡@

2.2.1 ¤°»ò¬Oª«¥ó¡@

        ¤@­Óª«¥ó¬O¤@­Ó¼Æ¾Ú«¬¦¡¡Cª«¥ó´N¶H°O¿ý¤@¼Ë¡A¬O¤@ºØ¼Æ¾Úµ²ºc¡C«ö³Ì²³æªº²z¸Ñ¡A§Ú­Ì¥i¥H±Nª«¥ó²z¸Ñ¦¨¤@­Ó°O¿ý¡C¦ý¹ê»Ú¤W¡Aª«¥ó¬O¤@ºØ©w¸q¤£½T¤Áªº³N»y¡A¥¦±`¥Î¨Ó©w¸q©â¶Hªº¨Æ°È¡A¬Oºc¦¨À³¥Îµ{¦¡ªº¶µ¥Ø¡A¨ä¤º²[»·¤ñ°O¿ý­nÂ×´I¡C¦b¥»®Ñ¤¤¡Aª«¥ó¥i³Q²z¸Ñ¬°¥iµø¤Æ³¡¥ó¦p«ö¶s¡B¼ÐÅÒ¡Bªíµ¥¡C

        ¤F¸Ñª«¥ó¡A³ÌÃöÁ䪺¬O´x´¤ª«¥óªº¯S©Ê¡C¤@­Óª«¥ó¡A¨ä³Ì¬ð¥Xªº¯S©º¦³¤T­Ó¡G«Ê¸Ë©Ê¡BÄ~©Ó©Ê¡B¦hºA©Ê¡C¡@

2.2.1.1 ª«¥óªº«Ê¸Ë©Ê¡@

        ¹ïª«¥ó³Ì°ò¥»ªº²z¸Ñ¬O§â¼Æ¾Ú©M¥N½X¸s¸s²Õ¦X¦b¦P¤@­Óµ²ºc¤¤¡A³o´N¬Oª«¥óªº«Ê¸Ë¯S©Ê¡C±Nª«¥óªº¼Æ¾ÚÄæ¦ì«Ê³¬¦bª«¥óªº¤º³¡¡A¨Ï±o¥~³¡µ{¦¡¥²»Ý¦Ó¥B¥u¯à¨Ï¥Î¥¿½Tªº¤èªk¤~¯à¹ï­nŪ¼gªº¼Æ¾ÚÄæ¦ì¶i¦æ¦s¨ú¡C«Ê¸Ë©Ê·N¨ýµÛ¼Æ¾Ú©M¥N½X¤@°_¥X²{¦b¦P¤@µ²ºc¤¤¡A¦pªG»Ý­nªº¸Ü¡A¥i¥H¦b¼Æ¾Ú©P³ò¬ä¤W¡§³òÀ𡨡A¥u¦³¥Îª«¥óÃþªº¤èªk¤~¯à¦b¡§³òÀ𡨤W¥´¶}¯Ê¤f¡C¡@

2.2.1.2 ª«¥óªºÄ~©Ó©Ê¡@

        Ä~©Ó©Êªº§t¸qª½±µ¦Ó¥BÅãµM¡C¥¦¬O«ü§â¤@­Ó·sªºª«¥ó©w¸q¦¨¬°¤w¦s¦bª«¥óªº«á¥N¡F·sª«¥óÄ~©Ó¤FÂÂÃþªº¤@¤ÁªF¦è¡C¦b©¹·sª«¥ó¤¤¥[¤J¥ô¦ó·s¤º®e¥H«e¡A¤÷Ãþªº¨C¤@­ÓÄæ¦ì©M¤èªk³£¤w¦s¦b©ó¤lÃþ¤¤¡A¤÷Ãþ¬O«Ø¥ß¤lÃþªº°ò¥Û¡C¡@

2.2.1.3 ª«¥óªº¦hºA©Ê¡@

        ¦hºA©Ê¬O¦bª«¥óÅé¨t¤¤§â³]·Q©M¹ê²{¤À¶}ªº¤â¬q¡C¦pªG»¡Ä~©Ó©Ê¬O¨t²Îªº§G§½¤â¬q¡A¦hºA©Ê´N¬O¨ä¥\¯à¹ê²{ªº¤èªk¡C¦hºA©Ê·N¨ýµÛ¬YºØ·§¬Aªº°Ê§@¥i¥H¥Ñ¯S©wªº¤è¦¡¨Ó¹ê²{¡A³o¨ú¨M©ó°õ¦æ¸Ó°Ê§@ªºª«¥ó¡C¦hºA©Ê¤¹³\¥HÃþ¦üªº¤è¦¡³B²zÃþÅé¨t¤¤Ãþ¦üªºª«¥ó¡C®Ú¾Ú¯S©wªº¥ô°È¡A¤@­ÓÀ³¥Îµ{¦¡³Q¤À¸Ñ¦¨³\¦hª«¥ó¡A¦hºA©Ê§â¶i¶¥³]­p³B²zªº³]·Q¦p·sª«¥óªº«Ø¥ß¡Bª«¥ó¦b¿Ã¹õ¤Wªº­«Åã¡Bµ{¦¡°õ¦æªº¨ä¥¦©â¶H´y­zµ¥¡A¯dµ¹ª¾¹D¸Ó¦p¦ó§¹¬üªº³B²z¥¦­Ìªºª«¥ó¥h¹ê²{¡C¡@

2.2.1.4 ³q¹LDelphi¹ê¨Ò¤F¸Ñª«¥ó¡@

      Åý§Ú­Ìµ²¦XDelphiªº¹ê¨Ò°Q½×ª«¥óªº·§©À:

      ·í±z­n«Ø¥ß¤@­Ó·s¤uµ{®É¡ADelphi ±NÅã¥Ü¤@­Óµ¡Åé§@¬°³]­pªº°ò¦¡C¦bµ{¦¡½s¿è¾¹¤¤¡ADelphi±N³o­Óµ¡Åé±Ô­z¬°¤@­Ó·sªºª«¥ó«¬¦¡¡A¨Ã¦P®É¦b»Pµ¡Åé¬ÛÃöÁpªº®w³æ¤¸¤¤²£¥Í¤F«Ø¥ß³o­Ó·sµ¡Å骫¥óªºµ{¦¡¥N½X¡C¡@

unit Unit1;¡@

interface¡@

uses SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs;¡@

type

TForm1 = class(TForm) {µ¡Å骺«¬¦¡±Ô­z¶}©l}

private

{ Private declarations }

public

{ Public declarations }

end; {µ¡Å骺«¬¦¡±Ô­zµ²§ô}¡@

var

Form1: TForm1; {±Ô­z¤@­Óµ¡ÅéÅܼÆ}¡@

implementation¡@

{$R *.DFM} ¡@

end.¡@

        ·sªºµ¡Å髬¦¡¬OTForm1¡A¥¦¬O±qTFormÄ~©Ó¤U¨Óªº¤@­Óª«¥ó¡C¥¦¨ã¦³ª«¥óªº¯S©º¡G§t¦³Äæ¦ì©Î¤èªk¡C¥Ñ©ó±z¥¼µ¹µ¡Åé¥[¤J¥ô¦ó³¡¥ó¡A©Ò¥H¥¦¥u¦³±qTFormÃþ¤¤Ä~©ÓªºÄæ¦ì©M¤èªk¡A¦bµ¡Å骫¥óªº«¬¦¡±Ô­z¤¤¡A±z¬O¬Ý¤£¨ì¥ô¦óÄæ¦ì¡B¤èªkªº±Ô­zªº¡CForm1ºÙ¬°TForm1«¬¦¡ªº¹ê¨Ò(instance)¡C±z¥i¥H±Ô­z¦h­Óª«¥ó«¬¦¡ªº¹ê¨Ò¡A¨Ò¦p¦b¦h¤åÀɤ¶­±(MDI)¤¤ºÞ²z¦h­Ó¤lµøµ¡®É´N­n¶i¦æ³o¼Ëªº±Ô­z¡C¨C¤@­Ó¹ê¨Ò³£¦³¦Û¤vªº±Ô­z¡A¦ý©Ò¦³ªº¹ê¨Ò«o¦@¥Î¬Û¦Pªº¥N½X¡C

         °²³]±z¦Vµ¡Å餤¥[¤J¤F¤@­Ó«ö¶s³¡¥ó¡A¨Ã¹ï³o­Ó«ö¶s«Ø¥ß¤F¤@­ÓOnClick¨Æ¥ó³B²z¹Lµ{¡C¦A¬d¬ÝUnit1ªº­ì©lµ{¦¡¡A·|µo²{TForm1ªº«¬¦¡±Ô­z³¡¤À¦p¤U¡G

type

TForm1 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;¡@

      ²{¦bTForm1ª«¥ó¦³¤F¤@­Ó¦W¬°Button1ªºÄæ¦ì¡G¥¦¬O±z¦bµ¡Å餤¥[¤Jªº«ö¶s¡CTButton¬O¤@­Óª«¥ó«¬¦¡¡AButton1¬OTbuttonªº¤@­Ó¹ê¨Ò¡C¥¦³QTForm1ª«¥ó©Ò¥]§t¡A§@¬°¥¦ªº¼Æ¾ÚÄæ¦ì¡C¨C·í±z¦bµ¡Å餤¥[¤J¤@­Ó³¡¥ó®É¡A³¡¥óªº¼Ðñ´N·|§@¬°TFom1ªºÄæ¦ì¥[¤J¨ì«¬¦¡±Ô­z¤¤¨Ó¡C¦bDelphi¤¤¡A±z©Ò½s¼gªº¨Æ¥ó³B²z¹Lµ{³£¬Oµ¡Å骫¥óªº¤èªk¡C¨C·í±z«Ø¥ß¤@­Ó¨Æ¥ó³B²z¹Lµ{¡A´N·|¦bµ¡Å骺ª«¥ó«¬¦¡¤¤±Ô­z¤@­Ó¤èªk¡C

       ·í±z¨Ï¥ÎObject Inspector¨Ó§ïÅܪ«¥ó(³¡¥ó)ªº¼Ðñ®É¡A³o­Ó¼Ðñªº§ïÅÜ·|¤Ï¬M¨ìµ{¦¡¤¤¡C¨Ò¦p¡A¦bObject Inspector¤¤±NForm1ªºNameÄÝ©Ê©R¦W¬°ColorBox¡A±z·|µo²{¦b«¬¦¡±Ô­z³¡¤À¡A·|±N«e¤åªºTForm1§ï¬°¡G¡@

TColorBox=class(TForm);¡@

         ¨Ã¥B¦bÅܼƱԭz³¡¤À¡A·|±Ô­zColorBox¬°TColorBox«¬¦¡ªºÅܼơA¥ÑDelphi¦Û°Ê²£¥Íªº¨Æ¥ó³B²z¹Lµ{¼Ðñ·|¦Û°Ê§ï¬°TColorBox.Button1Click¡F¦ý±z¦Û¦æ½s¼gªº¹ê²{³¡¤Àªº¥N½X«o¤£·|³Q¦Û°Ê­×§ï¡C¦]¦¹¡A¦pªG±z¦b§ïÅÜNameÄÝ©Ê«e½s¼g¤Fµ{¦¡¡A«h±z¥²¶·±N¨Æ¥ó³B²z¹Lµ{¤¤ªºª«¥ó¼Ðñ¶i¦æ§ïÅÜ¡C©Ò¥H¡A­ì¥ýªºForm1.Color­n§ï¬°ColorBox.Color¡C¡@

2.2.2 ±q¤@­Óª«¥ó¤¤Ä~©Ó¼Æ¾Ú©M¤èªk¡@

        «e­±ªºTForm1«¬¦¡¬O«Ü²³æªº¡A¦]¬°¥¦¥u§t¦³Äæ¦ìButton1©M¤èªkButton1Click¡C¦ý¬O¦b³o­Óµ¡Åé¤W¡A±z¥i¥H§ïÅܵ¡Å骺¤j¤p¡B¥[¤J©Î¸Ñ°£µ¡Å骺³Ì¤j³Ì¤p¤Æ«ö¶s¡A©Î³]©w³o­Óµ¡Å鬰MDI¤¶­±¡C¹ï©ó¤@­Ó¥u¥]§t¤@­ÓÄæ¦ì©M¤èªkªºª«¥ó¨ÓÁ¿¡A±z¨Ã¨S¦³¬Ý¨ìÅ㦡ªº¤ä´©µ{¦¡¡C¦bµ¡Åé¤W«ö¤@¤U·Æ¹«©Î¥ÎObject Inspectorªº¤WºÝªºObject Selector¿ï¤¤Form1ª«¥ó¡A«ö°ÊF1¬d¾\¥¦ªº¦b½u»²§U±Ô­z¡A±z·|¦bProperties©MMethod¤¤§ä¨ì¥¦ªºÄ~©Ó¨ìªº¥þ³¡ÄÝ©Ê©M¤èªk¡C³o¨Ç¬O¦bTForm«¬¦¡¤¤±Ô­zªº¡ATForm1¬OTFormªº¤lÃþ¡Aª½±µÄ~©Ó¤F¥¦©Ò¦³ªºÄæ¦ì¡B¤èªk¡BÄÝ©Ê©M¨Æ¥ó¡C¨Ò¦pµ¡Å骺ÃC¦âÄÝ©ÊColor´N¬O¦bTForm¤¤±Ô­zªº¡C·í±z¦b¤uµ{¤¤¥[¤J¤@­Ó·sµ¡Åé®É¡A´Nµ¥©ó¥[¤J¤F¤@­Ó°ò¥»¼Ò«¬¡C³q¹L¤£Â_¦a¦bµ¡Å餤¥[¤J³¡¥ó¡A±z´N¦Û¦æ©w¸q¤F¤@­Ó·sªºµ¡Åé¡C­n¦Û©w¸q¥ô¦óª«¥ó¡A±z³£±N±q¤w¸g¦s¦bªºª«¥ó¤¤Ä~©ÓÄæ¦ì©M¤èªk¡A«Ø¥ß¤@­Ó¸ÓºØª«¥óªº¤lÃþ¡C¨Ò¦pª«¥óTForm1´N³Q±Ô­z¬°ª«¥óTFormªº¤lÃþ¡A¾Ö¦³¤@­Óµ¡Å鳡¥óªº°ò¥»ÄݩʩΤèªk¡C¥u¦³·í±z¦bµ¡Å餤¥[¤J¤F³¡¥ó©Î½s¼g¤F¨Æ¥ó³B²z¹Lµ{®É¡AForm1¤~¦¨¬°±z¦Û¤vªº«¬¦¡¡C

        ¤@­Ó¤ñ¸û¯S®íªºª«¥ó¬O±q¤@­Ó½d³ò¸û¼s©Î¸û¤@¯ëªºª«¥ó¤¤Ä~©Ó¤U¨Óªº¡A¥¦¬O³o­Ó¯S§Oª«¥óªº¯ª¥ý¡A³o­Óª«¥ó«hºÙ¬°¯ª¥ýªº«á¥N¡C¤@­Óª«¥ó¥u¯à¦³¤@­Óª½±µªº¯ª¥ý¡A¦ý¬O¥¦¥i¥H¦³³\¦h«á¥N¡CTForm¬OTForm1«¬¦¡ªº¯ª¥ý¡A©Ò¦³ªºµ¡Å骫¥ó³£¬OTFormªº«á¥N¡C

       ¥ÎF1¬d¾\µ¡Å骺¦b½u»²§U±Ô­z®É¡A±z·|µo²{TForm³QºÙ¬°component(³¡¥ó)¡C³o¬O¦]¬°©Ò¦³ªº³¡¥ó³£¬Oª«¥ó¡C

        ¦b³o­Óµ²ºc¤¤©Ò¦³ªº³¡¥ó³£¬Oª«¥ó¡C³¡¥ó«¬¦¡TComponent±qTObject«¬¦¡¤¤Ä~©Ó¼Æ¾Ú©Mµ{¦¡¥N½X¡A¨Ã¨ã¦³ÃB¥~ªº¥i¥H¥Î§@¯S®í¥Î³~ªºÄÝ©Ê¡B¤èªk¡B¨Æ¥ó¡A©Ò¥H³¡¥ó¥i¥Hª½±µ©M¥Î¤á¥´¥æ¹D¡A°O¿ý¥¦ªºª¬ºA¨Ã¦s¶J¨ì¤å¥ó¤¤µ¥µ¥¡C±±¨î«¬¦¡TControl±qTComponent¤¤Ä~©Ó¦Ó¨Ó¡A¤S¼W¥[¤F·sªº¥\¯à¡A¦p¥¦¥i¥HÅã¥Ü¤@­Óª«¥ó¡C¦b¤W¹Ï¤¤¡AÁöµMTCheckBox¤£¬Oª½±µ¥ÑTObjectÄ~©Ó¨Óªº¡A¦ý¬O¥¦¤´µM¦³¥ô¦óª«¥ó©Ò¾Ö¦³ªºÄÝ©Ê¡A¦]¬°¦bVCLµ²ºc¤¤¡ATCheckBox²×¨sÁÙ¬O±qTObject ¤¤Ä~©Ó¤F©Ò¦³¥\¯àªº¯S®íª«¥ó¡A¦ý¥¦ÁÙ¦³¨Ç¦Û¦æ©w¸qªº¿W¨ìªº¥\¯à¡A¦p¥i¥H¿ï¾Ü°O¿ýª¬ºAµ¥¡C¡@

2.2.3 ª«¥óªº½d³ò¡@

2.2.3.1 Ãö©óª«¥óªº½d³ò¡@

        ¤@­Óª«¥óªº½d³ò¨M©w¤F¥¦ªº¼Æ¾ÚÄæ¦ì¡BÄÝ©Ê­È¡B¤èªkªº¬¡°Ê½d³ò©M¦s¨ú½d³ò¡C¦b¤@­Óª«¥óªº±Ô­z³¡¤À±Ô­zªº¼Æ¾ÚÄæ¦ì¡BÄÝ©Ê­È¡B¤èªk³£¥u¬O¦b³o­Óª«¥óªº½d³ò¤¤¡A¦Ó¥B¥u¦³³o­Óª«¥ó©M¥¦ªº«á¥N¤~¯à¾Ö¦³¥¦­Ì¡CÁöµM³o¨Ç¤èªkªº¹ê»Úµ{¦¡¥N½X¥i¯à¬O¦b³o­Óª«¥ó¤§¥~ªºµ{¦¡®w³æ¤¸¤¤¡A¦ý³o¨Ç¤èªk¤´µM¦b³o­Óª«¥óªº½d³ò¤º¡A¦]¬°¥¦­Ì¬O¦b³o­Óª«¥óªº±Ô­z³¡¤À¤¤±Ô­zªº¡C

        ·í±z¦b¤@­Óª«¥óªº¨Æ¥ó³B²z¹Lµ{¤¤½s¼gµ{¦¡¥N½X¨Ó¦s¨ú³o­Óª«¥óªºÄÝ©Ê­È¡B¤èªk©ÎÄæ¦ì®É¡A±z¤£»Ý­n¦b³o¨Ç¼ÐÃѲŤ§«e¥[¤W³o­Óª«¥óÅܼƪº¼Ðñ¡C¨Ò¦p¡A¦pªG±z¦b¤@­Ó·sµ¡Åé¤W¥[¤J¤@­Ó«ö¶s©M¤@­Ó½s¿è®Ø¡A¨Ã¬°³o­Ó«ö¶s½s¼gOnClick¨Æ¥ó³B²z¹Lµ{¡G¡@

procedure TForm1.Button1Click(Sender:Tobject);

begin

Color :=clFuchsia;

Edit1.Color :=clLime;

end; ¡@

        ¨ä¤¤ªº²Ä¤@¦æ»y¥y¬O¬°¾ã­Óµ¡ÅéForm1µÛ¦â¡C±z¤]¥i¥H½s¼g¦p¤U¡G

¡@

Form1.Color :=clFuchsia;¡@

        ¦ý±z¥i¥H¤£¥²¥[¤WForm1.¡A¦]¬°Button1Click¤èªk¬O¦bTForm1ª«¥óªº½d³òùØ¡C·í±z¦b¤@­Óª«¥óªº½d³ò¤¤®É¡A±z¥i¥H¬Ù²¤©Ò¦³³o­Óª«¥ó¤¤ªºÄÝ©Ê­È¡B¤èªk¡BÄæ¦ì¤§«eªºª«¥ó¼ÐÃѲšC¦ý¬O·í±z½s¼g²Ä¤G­Ó»y¥y§ïÅܽs¿è®Øªº©³¦â®É¡A¦]¬°¦¹®É±z·Q¦s¨úªº¬OTEdit1ª«¥óªºColorÄÝ©Ê¡A¦Ó¤£¬OTForm1«¬¦¡ªº¡A©Ò¥H±z»Ý­n³q¹L¦bÄÝ©Ê«e­±¥[¤W½s¿è®Øªº¼Ðñ¨Ó«ü©úColorÄݩʭȪº½d³ò¡C¦pªG¤£«ü©ú¡ADelphi·|¶H²Ä¤@­Ó»y¥y¤@¼Ë¡A±Nµ¡Å骺ÃC¦âÅܦ¨ºñ¦â¡C¦]¬°Edit1³¡¥ó¬O¦bµ¡Å餤ªº¡A¥¦¬Oµ¡Å骺¤@­Ó¼Æ¾ÚÄæ¦ì¡A©Ò¥H±z¦P¼Ë¤£¥²«ü©ú¨ä±qÄÝÃö«Y¡C

       ¦pªGEdit1¬O¦b¨ä¥Lµ¡Å餤¡A¨º»ò±z»Ý­n¦b½s¿è®Ø¤§«e¥[¤W³o­Ó²îÅ骫¥óªº¼Ðñ¤F¡C¨Ò¦p¡A¦pªGEdit1¬O¦bForm2¤§¤¤¡A¨º¥¦¬OForm2±Ô­zªº¤@­Ó¼Æ¾ÚÄæ¦ì¡A¨Ã¦ì©óForm2ªº½d³ò¤¤¡A¨º»ò±z»Ý­n±N²Ä¤G¥y§ï¬°¡G¡@

Form2.Edit1.Color := clLime;¡@

¦Ó¥B»Ý­n§âUnit2¥[¤JUnit1ªºuses¤l¥y¤¤¡C

        ¤@­Óª«¥óªº½d³òÂX®i¨ì³o­Óª«¥óªº©Ò¦³«á¥N¡CTFormªº©Ò¦³ÄÝ©Ê­È¡B¤èªk©M¨Æ¥ó³£¦bTForm1ªº½d³ò¤¤¡A¦]¬°TForm1¬OTFormªº«á¥N¡C±zªºÀ³¥Îµ{¦¡¤£¯à±Ô­z©M¯ª¥ýªº¼Æ¾ÚÄæ¦ì­«¦Wªº«¬¦¡¡BÅܼƵ¥¡C¦pªGDelphiÅã¥Ü¤F¤@­Ó¼ÐÃѲųQ­«½Æ©w¸qªº¸ê°T¡A´N¦³¥i¯à¬O¤@­Ó¼Æ¾ÚÄæ¦ì©M¨ä¯ª¥ýª«¥ó(¨Ò¦pTForm)ªº¤@­Ó¼Æ¾ÚÄæ¦ì¦³¤F¬Û¦Pªº¼Ðñ¡C¥i¥H¹Á¸Õ§ïÅܳo­Ó¼ÐÃѲŪº¼Ðñ¡C¡@

2.2.3.2 ­«¸ü¤@­Ó¤èªk¡@

        ±z¥i¥H­«¸ü(Override)¤@­Ó¤èªk¡C³q¹L¦b«á¥Nª«¥ó¤¤±Ô­z¤@­Ó»P¯ª¥ýª«¥ó­«¦Wªº¤èªk¡A´N¥i¥H­«¸ü¤@­Ó¤èªk¡C¦pªG·Q¨Ï³o­Ó¤èªk¦b«á¥Nª«¥ó¤¤§@©M¯ª¥ýª«¥ó¤¤¤@¼Ëªº¤u§@¦ý¬O¨Ï¥Î¤£¦Pªº¤è¦¡®É¡A±z´N¥i¥H­«¸ü³o­Ó¤èªk¡CDelphi¤£±ÀÂ˱z¸g±`­«¸ü¤èªk¡A°£«D±z·Q«Ø¥ß¤@­Ó·sªº³¡¥ó¡C­«¸ü¤@­Ó¤èªk¡ADelphi½sĶ¾¹¤£·|µ¹¥X¿ù»~©Îĵ§i´£¥Ü¸ê°T¡C

2.2.4 ª«¥ó¤½¦³Äæ¦ì©M¨p¦³Äæ¦ìªº±Ô­z¡@

        ·í¨Ï¥ÎDelphiªºÀô¹Ò¨Ó«Ø¥ßÀ³¥Îµ{¦¡®É¡A±z¥i¥H¦b¤@­ÓTFormªº«á¥Nª«¥ó¤¤¥[¤J¼Æ¾ÚÄæ¦ì©M¤èªk¡A¤]¥i¥H³q¹Lª½±µ­×§ïª«¥ó«¬¦¡±Ô­zªº¤èªk¨Ó¬°¤@­Óª«¥ó¥[¤WÄæ¦ì©M¤èªk¡A¦Ó¤£¬O§â¤@­Ó³¡¥ó¥[¤Jµ¡Åé©Î¨Æ¥ó³B²z¹Lµ{¤¤¡C

        ±z¥i¥H¦bª«¥óªºPublic©ÎPrivate³¡¤À¥[¤J·sªº¼Æ¾ÚÄæ¦ì©M¤èªk¡CPublic©MPrivate¬OObject Pascalªº«O¯d¦r¡C·í±z¦b¤uµ{¤¤¥[¤J·sªºµ¡Åé®É¡ADelphi¶}©l«Ø¥ß³o­Ó·sµ¡Å骫¥ó¡C¨C¤@­Ó·sªºª«¥ó³£¥]§tpublic©Mprivate«ü¥Ü¡A¥H«K±z¦b¥N½X¤¤¥[¤J¼Æ¾ÚÄæ¦ì©M¤èªk¡C¦bpublic³¡¤À¤¤±Ô­z¨ä¥¦®w³æ¤¸¤¤ª«¥óªº¤èªk¤]¥i¥H¦s¨úªº¼Æ¾ÚÄæ¦ì©Î¤èªk¡C¦bprivate³¡¤Àªº±Ô­z¦³¦s¨úªº­­¨î¡C¦pªG±z¦bprivate¤¤±Ô­zÄæ¦ì©M¤èªk¡A¨º»ò¥¦¦b±Ô­z³o­Óª«¥óªº®w³æ¤¸¥~¬O¤£³z©úªº¡A¦Ó¥B¤£¯à³Q¦s¨ú¡Cprivate¤¤¥i¥H±Ô­z¥u¯à³Q¥»®w³æ¤¸¤èªk¦s¨úªº¼Æ¾ÚÄæ¦ì©M¥»®w³æ¤¸ª«¥ó¦s¨úªº¤èªk¡C¹Lµ{©Î¨ç¼Æªºµ{¦¡¥N½X¥i¥H©ñ¦b®w³æ¤¸ªºimplementation³¡¤À¡C¡@

2.2.5 ¦s¨úª«¥óªºÄæ¦ì©M¤èªk¡@

       ·í±z·Q­n§ïÅܤ@­Óµ¡Å骫¥óªº¤@­ÓÄæ¦ìªº¬Y­ÓÄÝ©Ê¡A©Î¬O©I¥s¥¦ªº¤@­Ó¤èªk®É¡A±z¥²¶·¦b³o­ÓÄݩʼÐñ©Î©I¥s¤èªk¤§«e¥[¤W³o­Óª«¥óªº¼Ðñ¡C¨Ò¦p¡A¦pªG±zªºµ¡Åé¤W¦³¤@­Ó½s¿è®Ø³¡¥ó¡A¦Ó±z»Ý­n¦b°õ¦æ¤¤§ïÅÜ¥¦ªºTextÄÝ©Ê¡A»Ý­n½s¼g¤U¦Cªº¥N½X¡G¡@

Edit1.Text := 'Welcome to Delphi';

¦P¼Ë¡A²M°£½s¿è®Ø³¡¥ó¤¤¿ï¤¤ªº¤å¥»¡A¥i¥H©I¥sTEdit³¡¥óªº¬ÛÀ³¤èªk¡G¡@

Edit1.ClearSelection;¡@

        ¦pªG±z·Q§ïÅܤ@­Óµ¡Å骫¥ó¤¤¤@­Óª«¥óÄæ¦ìªº¦h­ÓÄݩʩΩI¥s¦h­Ó¤èªk®É¡A¨Ï¥Îwith»y¥y¥i¥H²¤Æ±zªºµ{¦¡¡Cwith»y¥y¦bª«¥ó¤¤¥i¥H©M¦b°O¿ý¤¤¤@¼Ë¤è«K¦a¨Ï¥Î¡C¤U­±ªº¨Æ¥ó³B²z¹Lµ{¦bÅTÀ³OnClick¨Æ¥ó®É¡A·|¹ï¤@­Ó¦C¥Ü¤è¶ô§@¦h­Ó½Õ¾ã¡G¡@

procedure TForm1.Button1Click(Sender:TObject);

begin

ListBox1.Clear;

ListBox1.MultiSelect :=True;

ListBox1.Item.Add('One');

ListBox1.Item.Add('Two');

ListBox1.Item.Add('Three');

ListBox1.Sorted :=Ture;

ListBox1.FontStyle :=[fsBold];

ListBox1.Font.Color :=clPurple;

ListBox1.Font.Name :='Times New Roman';

ListBox1.ScaleBy(125,100);

end;¡@

¦pªG¨Ï¥Î¤FWith»y¥y¡A«hµ{¦¡¦p¤U¡G¡@

procedure TForm1.Button1Click(Sender:TObject);

begin

with (ListBox1) do

begin

Clear;

MultiSelect :=True;

Item.Add('One');

Item.Add('Two');

Item.Add('Three');

Sorted :=Ture;

FontStyle :=[fsBold];

Font.Color :=clPurple;

Font.Name :='Times New Roman';

ScaleBy(125,100);

end;

end;¡@

       ¨Ï¥Îwith»y¥y¡A±z¤£¥²¦b¨C¤@­ÓÄݩʩΤèªk«e¥[¤WListBox1¼ÐÃѲšA¦bWith»y¥y¤§¤º¡A©Ò¦³ªºÄݩʩΩI¥s¤èªk¹ï©óListBox³o­Óª«¥ó¦Ó¨¥³£¬O¦b¥¦ªº½d³ò¤ºªº¡C¡@

2.2.6 ª«¥óÅܼƪº½á­È¡@

        ¦pªG¨â­ÓÅܼƫ¬¦¡¬Û¦P©Î¬Û®e¡A±z¥i¥H§â¨ä¤¤¤@­Óª«¥óÅܼƽᵹ¥t¤@­Óª«¥óÅܼơC¨Ò¦p¡Aª«¥óTForm1©MTForm2³£¬O±qTFormÄ~©Ó¤U¨Óªº«¬¦¡¡A¦Ó¥BForm1©MForm2¤w³Q±Ô­z¹L¡A¨º»ò±z¥i¥H§âForm1½áµ¹Form2:

Form2 :=Form1;

         ¥u­n½á­Èªºª«¥óÅܼƬO³Q½á­Èªºª«¥óÅܼƪº¯ª¥ý«¬¦¡¡A±z´N¥i¥H±N¤@­Óª«¥óÅܼƽᵹ¥t¤@­Óª«¥óÅܼơC¨Ò¦p¡A¤U­±¬O¤@­ÓTDataFormªº«¬¦¡±Ô­z¡A¦bÅܼƱԭz³¡¤À¤@¦@±Ô­z¤F¨â­ÓÅܼơGAForm©MDataForm¡C¡@

type

TDataForm = class(TForm)

Button1:TButton;

Edit1:TEdit;

DataGrid1:TDataGrid;

Database1:TDatabase;

TableSet1:TTableSet;

VisibleSession1:TVisibleSession;

private

{¨p¦³Äæ¦ì±Ô­z}

public

{¤½¦³Äæ¦ì±Ô­z}

end;

var

AForm:TForm;

DataForm:TDataForm;

       ¦]¬°TDataForm¬OTForm«¬¦¡ªº«á¥N¡A©Ò¥HDataform¬OAFormªº«á¥N¡A¦]¦¹¤U­±ªº½á­È»y¥y¬O¦Xªkªº¡G

AForm :=DataForm;

        ³o¤@ÂI¦bDelphi¤¤¬O·¥¬°­«­nªº¡CÅý§Ú­Ì¨Ó¬Ý¤@¤UÀ³¥Îµ{¦¡©I¥s¨Æ¥ó³B²z¹Lµ{ªº¹Lµ{¡A¤U­±¬O¤@­Ó«ö¶s³¡¥óªºOnClick¨Æ¥ó³B²z¹Lµ{¡G

procedure TForm1.Button1Click(Sender:TObject);

begin

end;

        ±z¥i¥H¬Ý¨ìTObjectÃþ¦bDelphiªºVisual Component Libraryªº³»³¡¡A³o´N·N¨ýµÛ©Ò¦³ªºDelphiª«¥ó³£¬OTObjectªº«á¥N¡C¦]¬°Sender¬OTObject«¬¦¡¡A©Ò¥H¥ô¦óª«¥ó³£¥i¥H½á­Èµ¹¥¦¡CÁöµM±z¨S¦³¬Ý¨£½á­Èªºµ{¦¡¥N½X¡A¦ý¨Æ¹ê¤Wµo¥Í¨Æ¥óªº³¡¥ó©Î±±¨î³¡¥ó¤w¸g½áµ¹Sender¤F¡A³o´N¬O»¡Senderªº­È¬OÅTÀ³µo¥Í¨Æ¥óªº³¡¥ó©Î±±¨î³¡¥óªº¡C

       ±z¥i¥H¨Ï¥Î«O¯d¦ris¨Ó´ú¸ÕSender¥H«K§ä¨ì©I¥s³o­Ó¨Æ¥ó³B²z¹Lµ{ªº³¡¥ó©Î±±¨î³¡¥óªº«¬¦¡¡CDelphi¤¤ªº¤@­ÓÅã¥Üdrag-and-dropªºDRAGDROP.DPR¤uµ{¡C¥[¸ü¥¦¡A¥i¥H¬d¾\¨ìDROPFONT.PAS®w³æ¤¸ªº¥N½X¡A¦bMemo1DragOver¤èªk¤¤Àˬd¤F¤@­Óª«¥óÅܼƪº«¬¦¡¡C¦b³oºØ±¡§Î¤U¡A°Ñ¼Æ¬OSource¦Ó¤£¬OSender¡C¡@

procrdure TForm1.Memo1DragOver(SenderSource:TObject;X,Y:integer;

State:TDragState;var Accept:Boolean);

begin

Accept :=Source is TLabel;

end; ¡@

        Source°Ñ¼Æ¤]¬OTObject«¬¦¡¡ASource³Q½á­È¬°¨º­Ó³Q©ì¦²ªºª«¥ó¡C¥ÎMemo1DragOver¤èªkªº¥Øªº¬O½T«O¥u¦³¼ÐÅÒ¥i¥H³Q©ì¦²¡CAccept¬O¥¬º¸«¬°Ñ¼Æ¡A¦pªGAccept¬°True¡A¨º»ò¥Î¤á¿ï¾Üªº³¡¥ó¥i¥H³Q©ì¦²¡F¤Ï¤§·íAcceptªº­È¬°False®É¡A¥Î¤á´N¤£¥i¥H©ì¦²¿ï¾Ü±±¨î³¡¥ó¡Cis«O¯d¦rÀˬdSource¬O§_TLabelªº«¬¦¡¡A©Ò¥HAccept¥u¦³¦b¥Î¤á©ì¦²¤@­Ó¼ÐÅҮɤ~¬°¯u¡A¨Ã§@¬°ÅÜ°Ñ¿é¥X¨ì¨ç¼Æ¤§¥~¡C

¤U­±ªºdrag-and-drop®i¥ÜªºMemo1DragDrop¨Æ¥ó³B²z¹Lµ{¤¤¤]¨Ï¥Î¤FSource°Ñ¼Æ¡C³o­Ó¤èªk¬O¬°¤F§âMemo³¡¥óªº¦r«¬§ïÅܦ¨©M©ñ¤J³o­Ó³Æµù±±¨î³¡¥óªº¼ÐÅÒ¤@¼Ëªº¦r«¬¡G¡@

procedure TForm1.Memo1DragDrop(SenderSource:TObject;

X,Y:Integer);

begin

Memo1.Font := (Source as TLabel).Font;

end;¡@

         ·í±z¦b³o­Ó¨Æ¥ó³B²z¹Lµ{¤¤½s¼g½á­È»y¥y®É¡A¶}µo¤H­û¨Ã¤£ª¾¹D¥Î¤á·|©ñ¤J­þ¤@­Ó¼ÐÅÒ¡A¥u¦³³q¹L°Ñ¦Ò³o­Ó¼ÐÅÒªº¼Ðñ(Source as TLabel)¥Î¤á¤~¯àª¾¹D¡A¨Ã§â¼ÐÅÒ«¬¦¡½áµ¹Memo1.TFont¡CSource¥]§t¤F¥Î¤á©ì©ñ±±¨î³¡¥óªº¼Ðñ¡A¥u¦³·íSource¬O¤@­Ó¼ÐÅҮɡA³o­Ó¨Æ¥ó³B²z¹Lµ{¤~¤¹³\³o­Ó½á­Èµo¥Í¡C

2.2.7 «Ø¥ß«D¥iµø¤Æª«¥ó¡@

        ±z¦bDelphi¤¤¨Ï¥Îªº¤j³¡¤Àª«¥ó³£¬O±z¦b³]­p©M°õ¦æ´Á¶¡¥i¥H¬Ý¨£ªº³¡¥ó¡A¨Ò¦p½s¿è®Ø¡B«ö¶sµ¥¡F¤@¨Ç³¡¥ó¡A¦p¤@¯ëªº¹ï¸Ü¤è¶ô(Common dialog box)µ¥¡A¦b³]­p®É¬Ý¤£¨£¡A¦Ó¦b°õ¦æ®É¥i¥H¬Ý¨£¡F¥t¥~¦³¨Ç³¡¥ó¡A¨Ò¦p­p®É¾¹(Timer)¡B¼Æ¾Ú·½(Data Source)³¡¥óµ¥¡A¦bµ{¦¡ªº°õ¦æ´Á¶¡¨S¦³¥ô¦ó¥iµø¤ÆªºÅã¥Ü¡A¦ý±z«o¥i¥H¦b±zªºÀ³¥Îµ{¦¡¤¤¨Ï¥Î¥¦­Ì¡C¡@

2.2.7.1±Ô­z¤@­Ó«D¥iµø¤Æª«¥ó¡@

        ¤U­±¡A³q¹L¤@­Ó²³æªº¨Ò¤lÁ¿­z¦p¦ó«Ø¥ß¦Û¤vªº«D¥iµø¤Æª«¥ó¡G

        ±z¥i¥H¥Î¦p¤Uªº¤èªk¡A«Ø¥ß¤@­Ó¦Û¤vªºTEmployee«D¥iµø¤Æª«¥ó¡G¡@

type

Temployee = class(TObject);

Name := String[25];

Title := String[25];

HourlyPayRate : Double;

function CalculatePayAmount:Double;

end;¡@

        ¦b³oºØ±¡ªp¤U¡ATEmployee±qTObjectÄ~©Ó¤U¨Ó¡A¥B¥]§t¤T­ÓÄæ¦ì©M¤@­Ó¤èªk¡C§â±z«Ø¥ßªº«¬¦¡±Ô­z©ñ¦b®w³æ¤¸¤¤ªº±Ô­z³¡¤À¡A¨Ã©Mµ¡Åé±Ô­z©ñ¦b¤@°_¡C¦b³o­Óµ{¦¡®w³æ¤¸ªºÅܼƱԭz³¡¤À¡A±Ô­z¤@­Ó·s«¬¦¡ªºÅܼơG¡@

var

Employee : TEmployee;¡@

2.2.7.2¥ÎCreate¤èªk«Ø¥ßª«¥ó¹ê¨Ò¡@

        TEmployee¥u¬O¤@­Óª«¥ó«¬¦¡¡C°£«D³q¹L¤@­Óºc³y¨ç¼Æªº©I¥s±q¦Ó³Q¹ê¨Ò¨ú¥N©Î«Ø¥ß¡A§_«h¤@­Óª«¥ó¨Ã¤£¦sÀx¦b°O¾ÐÅ餤¡Cºc³y¨ç¼Æ¬O¤@­Ó¤èªk¡A¥¦¬°·sª«¥ó²ÕºA°O¾ÐÅé¨Ã¥B«ü¦V³o­Ó·sªºª«¥ó¡C³o­Ó·sªºª«¥ó¤]³QºÙ¬°³o­Óª«¥ó«¬¦¡ªº¤@­Ó¹ê¨Ò¡C

        «Ø¥ß¤@­Óª«¥óªº¹ê¨Ò¡A»Ý­n©I¥sCreate¤èªk¡AµM«áºc³y¨ç¼Æ§â³o­Ó¹ê¨Ò½áµ¹¤@­ÓÅܼơC¦pªG±z·Q±Ô­z¤@­ÓTEmployee«¬¦¡ªº¹ê¨Ò¡A¦b±z¦s¨ú³o­Óª«¥óªº¥ô¦óÄæ¦ì¤§«e¡A±zªºµ{¦¡¥N½X¥²¶·©I¥sCreate¡C

Employee := TEmployee.Create;¡@

        Create¤èªk¨Ã¨S¦³¦bTEmployee«¬¦¡¤¤±Ô­z¡A¥¦Ä~©Ó¦ÛTObject«¬¦¡¡C¦]¬°TEmployee¬OTObjectªº¤lÃþ¡A©Ò¥H¥¦¥i¥H©I¥sCreate¤èªk¦Ó«Ø¥ß¤@­ÓTEmployee¹ê¨Ò¡CµM«á§â¥¦½áµ¹EmployeeÅܼơC¦b«Ø¥ß¤F¤@­Ó³o¼Ëªºª«¥ó«á¡A±z´N¥i¥H¶H¨Ï¥Î¨ä¥LªºDelphiª«¥ó¤@¼Ë¦s¨úEmployeeª«¥ó¤F¡C¡@

2.2.7.3 ºM¾Pª«¥ó¡@

        ·í±z¨Ï¥Î§¹ª«¥ó«á¡A±zÀ³¸Ó¤Î®ÉºM¾P¥¦¡A¥H«K§â³o­Óª«¥ó¦û¥Îªº°O¾ÐÅéÄÀ©ñ¥X¨Ó¡C±z¥i¥H³q¹L©I¥s¤@­Óµn¥X¤èªk¨ÓºM¾P±zªºª«¥ó¡A¥¦·|ÄÀ©ñ¤À°tµ¹³o­Óª«¥óªº°O¾ÐÅé¡C

        Delphiªºµn¥X¤èªk¦³¨â­Ó¡GDestroy©MFree¡CDelphi«Øij¨Ï¥ÎFree¡A¦]¬°¥¦¤ñDestroy§ó¬°¦w¥þ¡A¦P®É©I¥sFree·|²£¥Í®Ä²v§ó°ªªº¥N½X¡C

         ±z¥i¥H¥Î¤U¦Cªº»y¥yÄÀ©ñ¥Î§¹ªºEmployeeª«¥ó¡G¡@

Employee.Free;¡@

         ©MCreate¤èªk¤@¼Ë¡AFree¤èªk¤]¬OTEmployee±qTObject¤¤Ä~©Ó¹L¨Óªº¡C§â±zªºµn¥X©ñ¦btry¡Kfinallyµ{¦¡¼Ò¸s²Õªºfinally³¡¤À¡A¦Ó§âª«¥óªºµ{¦¡¥N½X©ñ¦btry³¡¤À¬Oµ{¦¡³]­pªº¦n²ßºD¡C³o¼Ë¡A§Y¨Ï±zªºµ{¦¡¥N½X¦b¨Ï¥Îª«¥ó®Éµo¥Í¤F²§±`¨Æ¥ó¡A¤]·|½T«O±z¬°³o­Óª«¥ó¤À°tªº°O¾ÐÅé·|³QÄÀ©ñ¡CÃö©ó²§±`³B²z©Mtry¡Kfinallyµ{¦¡¼Ò¸s²Õªº¸ê°T¥H¤Î«Ø¥ß«D¥iµø¤Æª«¥óªº¨Ò¤l¡A¦b«á¤å¤¤ÁÙ±N¥J²ÓÁ¿­z¡C



«á¤@­¶
«e¤@­¶
¦^¥Ø¿ý
¦^­º­¶