«á¤@¶ «e¤@¶ ¦^¥Ø¿ý ¦^º¶ |
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´yzµ¥¡A¯dµ¹ª¾¹D¸Ó¦p¦ó§¹¬üªº³B²z¥¦Ìªºª«¥ó¥h¹ê²{¡C¡@ 2.2.1.4 ³q¹LDelphi¹ê¨Ò¤F¸Ñª«¥ó¡@ Åý§Ú̵²¦XDelphiªº¹ê¨Ò°Q½×ª«¥óªº·§©À: ·í±zn«Ø¥ß¤@Ó·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µøµ¡®É´Nn¶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.Colorn§ï¬°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ªºµ¡Åé¡Cn¦Û©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·Qn§ïÅܤ@Óµ¡Å骫¥óªº¤@ÓÄæ¦ìªº¬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; ¥un½áȪºª«¥óÅܼƬ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¨Ò¦pp®É¾¹(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¤@¶ ¦^¥Ø¿ý ¦^º¶ |