«á¤@¶ «e¤@¶ ¦^¥Ø¿ý ¦^º¶ |
§Q¥ÎGotoNearest¤èªk°õ¦æ¤£ºë½T§ä¨ì µ¡Å餤ªº¡§¤£ºë½T§ä¨ì¡¨«ö¶sªº¨Æ¥ó³B²z¹Lµ{¥N½X¦p¤U¡G procedure TForm1.Button1Click(Sender: TObject); begin with table1 do begin IndexFieldNames:='Company'; setkey; FieldByName('Company').AsString:=Edit1.text; GotoNearest; label3.caption:=FieldByName('Company').AsString; end; end; ŪªÌ¥i¥H§Q¥Î FindNearest ¤èªk°õ¦æ¤W±ªº¤£ºë½T§ä¨ì¡A ¨ãÅé¨Ï¥Î¤èªk¥i¥H°Ñ¬ÝFindkey¤èªkªº¨Ï¥Î¡C ¦b¤W±ªº¨Ò¤l¤¤n³]©wtable1ªºIndexFieldNamesÄݩʬ°Company¡C GotoNearest¤èªk¶i¦æ¤£ºë½T§ä¨ì 14.6 קï¸ê®Æ®w¤¤ªº°O¿ý¡@ §ÚÌ´x´¤¤FÄæ¦ìª«¥óªº·§©À©M¦p¦ó§ä¨ì¸ê®Æ®w¤¤ªº°O¿ý¤§«á¡A¤U±§Ú«K¥i¥H«Ü¤è«K¦aקï¸ê®Æ®w¤¤²{¦sªº°O¿ý¤F¡A¤@¯ë¨Ó»¡¡A¦bµ{¦¡¤¤×§ï¸ê®Æ®w¤¤ªº°O¿ý¥]¬A¤U±³o¨Ç¨BÆJ¡G ¢°¡B¦b¸ê®Æ®w¤¤§ä¨ìnק諸°O¿ý¡A¨Ã±N°O¿ý«ü¼Ð²¾¦Ü¸Ó°O¿ý¡C ¢±¡B©I¥sEdit¤èªk±N»P¸ê®Æ®wªí¬Û³sªºTTable³¡¥ó³]©w¦¨½s¿èª¬ºA¡C ¢²¡Bקï¤@өΦhÓÄæ¦ì¡C ¢³¡B©I¥spost¤èªk±Nקï«áªº°O¿ý¼g¤J¸ê®Æ®w¡C ¥H¤W³o´XÓ¨BÆJ¥u¬O·§z©Êªº¡A¨ãÅé¹ê²{®ÉÁÙ¦³«Ü¦h²Ó¸`»Ýn¯d¤ß¡A§Ú̳q¹L¤@Ó¨Ò¤l¨Óºt¥Ü¤W±ªº¥þ¹Lµ{¡A¥H«KÅýŪªÌ¶i¤@¨B¦a¤F¸Ñ©M´x´¤×§ï°O¿ýªº¤èªk¡C ¨Ò14.6 §Ú̬°¥|Ó«ö¶s¤À§O½s¼g¤F¨Æ¥ó³B²z¹Lµ{¡A¥Î¨Ó¹M¾ä¸ê®Æ®w¤¤ªº°O¿ý¨Ã¹ï¨CӥΤá°O¿ýªºCompanyÄæ¦ì¶i¦æקï¡A ¦bµ{¦¡¹ï°O¿ý¶i¦æ§ó·s¾Þ§@®Éµøµ¡¤¤ªº±±¥ó³£¬OµL®Äªº¡A¦b³oÓ¨Ò¤l¤¤§ÚÌÁÙ½s¼g¤F¤@Ó²³æªº²§±`¥N½X¶ô¥Î¨Ó½T«O¦b§ó·s¹Lµ{¤¤¥X²{²§±`®É¨Ï±±¥ó«ì´_¥¿±`¾Þ§@¡C¡@ קï¸ê®Æ®w°O¿ý 14.6.1 Edit¤èªkPost¤èªk¡@ ¬°¤F¯àÅý¥Î¤á³q¹Lµ{¦¡×§ï¸ê®Æ®wªí¤¤ªº°O¿ý¡ATTable³¡¥ó¥²¶·n³B¦b½s¿èª¬ºA¤U¡C¦b¤j¦h¼Æ±¡ªp¤U¡A¸ê®Æ®wªí³£¬O¥HÂsÄý¡]°ßŪ¤è¦¡¡^¤è¦¡¥´¶}ªº¡A¤]´N¬O»¡¥¦ªº¨C¤@ÓÄæ¦ì¥i¥H³QŪ¨ú¤¶¤£¯à³Q½s¿èקï¡C©I¥sEdit ¤èªk¯à°÷±N TTable ³¡¥ó¸m¦¨½s¿èª¬ºA¡A ·íTTable³¡¥ó³B©ó½s¿èª¬ºA«á¡A§Ṳ́~¥i¥H³q¹Lµ{¦¡×§ï¥Ø«e°O¿ý«ü¼Ð©Ò«ü¦Vªº°O¿ý¡A¦ý³o¼Ëקï«áªº°O¿ý¤£·|¥ß§Y³Q¼g¤J¨ìºÏºÐ¤Wªº¹ê»Ú¸ê®Æ®wªí¤¤¡Cn·Q¦sÀɹï°O¿ýªº×§ï¡A¥²¶·n©I¥sPost¤èªk¡APost¤èªk¤~¯u¥¿±N§Ú̹ï°O¿ýªº×§ï¼g¤J¹ê»Úªº¸ê®Æ®wªí¤¤¡C ¤@¯ë¨Ó»¡¡A¥Î¨Ó±½´y¾ãÓ¸ê®Æ®wªí¨Ãקï¨CÓ°O¿ýªº¬Y¤@ÓÄæ¦ìªºµ{¦¡¦p¤U©Ò¥Ü¡G with Table Do begin DisableControls;{¦bקï°O¿ýªº¹Lµ{¤¤¡A¨Ï¨ä¥¦³¡¥óµL®Ä} First; {±N°O¿ý«ü¼Ð«ü¦V²Ä¤@±ø°O¿ý} while not EOF do begin <Ū¨ú°O¿ýªº¤@ÓÄæ¦ìȨì¤@ÓÅܼƤ¤> <°µ¾A·íªº×§ï> Edit; {±NTTable³¡¥ó¸m¦¨½s¿èª¬ºA} <±Nקï«áªºÄæ¦ìȼg¦^¨ì¨ä¹ïÀ³ªºÄæ¦ì> post; {±Nקï«áªº°O¿ý¼g¦^¸ê®Æ®w} next; {קï¤U¤@±ø°O¿ý} end; enablecontrols; {«ì´_¨ä¥¦³¡¥óªº¥\¯à} end; µ{¦¡³£¬O¹ïTTable³¡¥ó¶i¦æ¾Þ§@¡A¦]¦¹¨Ï¥ÎWith»y¥y¨Ó¨¾¤î¿ù»~ªºÂX´²¬O«Ü¦³·N¸qªº¡C¦b³oùØnª`·NDisablecontrols¤èªk©MEnableControls¤èªkªº¨Ï¥Î¡CDisableControls¤èªk¬O¦bµ{¦¡×§ïTTable³¡¥ó¤¤ªº°O¿ý®É¡A¤ÁÂ_TTable³¡¥ó»P¼Æ¾Ú¦s¨ú³¡¥óTDatasource ³¡¥óªºÁpô¡C§_«h¡A¦b¹ïTTable¤¤ªº¨C¤@ק蠟«á¡ATDataSource ³¡¥ó³£·|§ó·sµ¡Å餤©Ò¦³¼Æ¾ÚÂsÄý³¡¥óªºÅã¥Ü¤º®e¡A³o¼Ë·|«æ¼@´îºC³B²z¹Lµ{¦Ó¥B®ö¶O®É¶¡¡CEnableControls¤èªk¬O»PDisableControle¤èªk°õ¦æ¬Û¤Ïªº¾Þ§@¡A¥¦¬O¥Î¨Ó«ì´_TTable³¡¥ó»PTDatasource³¡¥óªºÁpô¨Ã«P¨Ï©Ò¦³ªº¼Æ¾ÚÂsÄý³¡¥ó§ó·sÅã¥Ü¡C ©I¥sFirst¤èªk¬O±N°O¿ý«ü¼Ð²¾¨ì¸ê®Æ®wªí¤¤ªº²Ä¤@±ø°O¿ý¡A ½T«Oµ{¦¡±qªí¤¤ªº²Ä¤@±ø°O¿ý¶}©l¶i¦æקï¡C©I¥sNext¤èªk¬O±N°O¿ý«ü¼Ð±q¥Ø«eªº°O¿ý²¾¨ì¤U¤@±ø°O¿ý¡A³o¼Ë«OÃÒ¤F±qªí¤¤ªº²Ä¤@±ø°O¿ý¶}©l³v±ø°O¿ý¶i¦æקï¡Aª½¨ìק粒³Ì«á¤@±ø°O¿ý¡C¦pªG¤£©I¥sNext¤èªk¡Aµ{¦¡±N·|³´¤JµL½aªº¦º¦^°é¡C¡@ 14.6.2 ¹ê²{²§±`«OÅ@ªºTRY...FINALLY»y¥y¡@ ¤W±ªºµ{¦¡¦s¦bµÛ¼ç¦bªº¦MÀI¡A¦b¹ê»ÚÀ³¥Î¹Lµ{¤¤¡A¥i¯à¦]¬°¬Y¨Çì¦]¨Ï±o¹ï¸ê®Æ®wªíªº§ó·s¤£¯à¶i¦æ¤U¥h¡C¦p·íµ{¦¡¸Õ¹Ï°õ¦æPost¤èªk±Nקï«áªº°O¿ý¼g¦^ºÏºÐ®É¡A¦Ó¤S¦]¬°¬YºØì¦]ºÏºÐ¨S¦³·Ç³Æ¦n¡A³o®É«K¥X²{¤F²§±`¡C·í¥X²{²§±`®É¡AÀ³¥Îµ{¦¡·|¼È°±¤U¨Ó¨Ã¥B·|¼u¥X¤@¹ï¸Ü¤è¶ôÅã¥Ü¦³Ãöªº¿ù»~¸ê°T¡A¦b¥Î¤á«ö¤@¤U¿ù»~¸ê°T¹ï¸Ü¤è¶ô¤§«á¡Aµ{¦¡±NÄ~Äò°õ¦æ¨ì¬Y¤@Ó¦a¤è¥h¡A¦Ó³oÓ¦a¤è±`±`¤£¬O¥Î¤á©Ò¯à¹w®Æ¨ìªº¡C ¦b§Ú̪ºµ{¦¡¤¤¡A ¦b°õ¦æPost¤èªk¤§«e¡Aµ¡Å餤©Ò¦³ªº³¡¥ó»PTTable³¡¥ó³£¤w¥¢¥hÁpô¡C¦]¦¹¡A³oºØ²§±`±N¾ÉPµ¡Å餤Åã¥Üªº¼Æ¾Ú©M¸ê®Æ®wµLÃö¡C Object Pascal¤¤ªºTry...Finally»y¥y¬°§Ú̸ѨM¤Wz²§±`°ÝÃD´£¨Ñ¤F¤@ӸѨM¤èªk¡C¦bDelphi¤¤¤´µM±Ä¥Î¤F³o¤@»y¥y¥Î¨Ó³B²z²§±`°ÝÃD¡C¹ê»Ú¤W¡ATry...Finally »y¥y¬O§â¨â¸s¸s²Õ»y¥y¸s¸s²Õ¦X¦b¤@°_¡C»y¥yªºTry³¡¤À¥]§t¤F¥i¯à²£¥Í²§±`ªºµ{¦¡¥N½X¡AFinally³¡¤À¥]§t¤F§Y¨Ïµo¥Í¤F²§±`¤]¥²¶·°õ¦æªº¤@±ø©Î¦h±ø»y¥y¡C ¦b¥»¨Ò¤¤¡A Finally ³¡¤À¥u¥]§t¤FEnableControls¤èªk©I¥s³o¤@±ø»y¥y¡A§Ú̱N«e±ªº¥N½X§ï¼g¨Ã¸s¸s²Õ¦X¶iTry...Finally »y¥y¡G¡@ with Table Do begin DisableControls;{¦bקï°O¿ýªº¹Lµ{¤¤¡A¨Ï¨ä¥¦³¡¥óµL®Ä} Try; First; {±N°O¿ý«ü¼Ð«ü¦V²Ä¤@±ø°O¿ý} while not EOF do begin <Ū¨ú°O¿ýªº¤@ÓÄæ¦ìȨì¤@ÓÅܼƤ¤> <°µ¾A·íªº×§ï> Edit; {±NTTable³¡¥ó¸m¦¨½s¿èª¬ºA} <±Nקï«áªºÄæ¦ìȼg¦^¨ì¨ä¹ïÀ³ªºÄæ¦ì> post; {±Nקï«áªº°O¿ý¼g¦^¸ê®Æ®w} next; {קï¤U¤@±ø°O¿ý} end; enablecontrols; Finally;{¥X²{²§±`®É,°õ¦æ¤U±ªºµ{¦¡} enablecontrols; {«ì´_¨ä¥¦³¡¥óªº¥\¯à} end; {µ²§ôTry...Finally»y¥y} end; ¦b«O¯d¦rTry©MFinally¤§¶¡ªº¥N½X¸ò«e±ªº¥N½X¬O¤@¼Ëªº¡A¥¦Ì¥Î©ó¦b°O¿ý¤§¶¡²¾°Ê°O¿ý«ü¼Ð¨Ã³B²z¹ï°O¿ýªº×§ï¡A³o¤@¬q¥N½X¥i¯à·|¥X²{²§±`¡A·í²§±`µo¥Í®É¡A§ÚÌ·Q«OÃÒ°õ¦æEnableControls¡A ¥H«Kµ¡Å餤¦U±±¥ó«ì´_»P TTable ³¡¥óªºÁpô¡A ¦]¦¹§ÚÌ¥²¶·±NEnableControls»y¥y©ñ¦bFinally©Mµ²§ô»y¥yEnd¤§¶¡¡C ¦b³oùØn¯S§Oª`·N¡A½ÐŪªÌ̤£n²V²c¤FTry...Finally»y¥y©MTry...Except »y¥y¡C¦pªG¯u¥¿·Q¦bµo¥Í²§±`®É±Ä¨ú¬ÛÀ³ªº³B²z¡A´Nn¨Ï¥ÎTry...Except»y¥y¡CTry... Finally»y¥y¥u¬O¥Î¨Ó³B²z·í²§±`¥X²{®É¡A¨ÏÀ³¥Îµ{¦¡°õ¦æFinally³¡¤Àªº»y¥y¡A ¨Ïµ{¦¡Ä~Äò°õ¦æ¤U¥h¡CTry...Except»y¥y¬O¹ê²{²§±`³B²z¡ATry...Finally»y¥y¬O¹ê²{²§±`«OÅ@¡C ¦³¤F¤Wz³o¨Ç·§©À¡A§ÚÌ«K¥i¥H´£¨Ñ³oÓ¨Ò¤lªº¤@¨Çµ{¦¡¥N½X¡A¥¦¯A¤Î¤F©Ò¦³³o¨Ç¤º®e¡C µ{¦¡²M³æ¡Gקï¸ê®Æ®w¤¤ªº°O¿ý¡@ unit Unit26; interface¡@ uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, ExtCtrls, DB, DBTables, Buttons;¡@ type TForm1 = class(TForm) DataSource1: TDataSource; customerTable: TTable; Panel1: TPanel; DBGrid1: TDBGrid; Panel2: TPanel; UpperCaseFirstAddBtn: TButton; UpperCaseSecondAddBtn: TButton; MixedCaseFirstAddBtn: TButton; MixedCaseSecondAddBtn: TButton; BitBtn1: TBitBtn; procedure ForceCase(TargetField:String;ToUpper:Boolean); procedure UpperCaseFirstAddBtnClick(Sender: TObject); procedure MixedCaseFirstAddBtnClick(Sender: TObject); procedure UpperCaseSecondAddBtnClick(Sender: TObject); procedure MixedCaseSecondAddBtnClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;¡@ var Form1: TForm1;¡@ implementation const upper=true; Mixed=False;¡@ {$R *.DFM} Function IsUpper(ch:char):Boolean; begin If (ch>='A')and(ch<='Z')then IsUpper:=true else IsUpper:=False; end; procedure TForm1.ForceCase(TargetField:String;ToUpper:Boolean); var WorkBuffer:string; i:Integer; begin with customerTable do begin DisableControls; TRY First; {±N°O¿ý«ü¼Ð²¾¨ì²Ä¤@±ø°O¿ý³B } While not EOF do begin WorkBuffer:=FieldByName(TargetField).AsString; If ToUpper then for i:=1 to Length(WorkBuffer)do WorkBuffer[i]:=UpCase(WorkBuffer[i]) else begin for i:=1 to Length(WorkBuffer) do If IsUpper(WorkBuffer[i]) then WorkBuffer[i]:=chr(ord(WorkBuffer[i])+32); WorkBuffer[1]:=UpCase(WorkBuffer[1]) end; Edit; FieldByName(TargetField).AsString:=WorkBuffer; post; Next; end; Finally enableControls; end; end; end;¡@ procedure TForm1.UpperCaseFirstAddBtnClick(Sender: TObject); begin ForceCase('Addr1',Upper); end;¡@ procedure TForm1.MixedCaseFirstAddBtnClick(Sender: TObject); begin ForceCase('Addr1',Mixed); end; ¡@ procedure TForm1.UpperCaseSecondAddBtnClick(Sender: TObject); begin ForceCase('Addr2',Upper); end; ¡@ procedure TForm1.MixedCaseSecondAddBtnClick(Sender: TObject); begin ForceCase('Addr2',Mixed); end; ¡@ procedure TForm1.FormCreate(Sender: TObject); begin customerTable.open; end;¡@ end.¡@ 14.7 ´¡¤J©M¸Ñ°£°O¿ý¡@ ÁöµM§Ų́ϥÎDBD©ÎªÌ¦bÀ³¥Îµ{¦¡µ¡Å餤¥ÎTDBNavigator¥i¥H´¡¤J¡B¸Ñ°£ªí¤¤ªº°O¿ý¡A¦ý¬O¥ô¦ó«nªº¸ê®Æ®wÀ³¥Îµ{¦¡³£¬O®Ú¾Ú³Ì²×¥Î¤áªº©R¥O§¹¦¨¦¹Ãþ¾Þ§@ªº¡C¦P¼Ë¡A¦pªG§ÚÌ´x´¤¤FÄæ¦ìª«¥ó¤Î¨ä¥Îªk¡Aקï¸ê®Æ®w¤¤ªº°O¿ý¡A´¡¤J©M¸Ñ°£°O¿ý±NÅܱo«D±`®e©ö¡C n·Q¸Ñ°£ªí¤¤ªº¬Y¤@±ø°O¿ý¡Aº¥ý±N°O¿ý«ü¼Ð²¾¨ì¸Ó°O¿ý³B¡AµM«á©I¥sdelete¤èªk¡A³o¼Ë¡A¥Ø«e«ü¼Ð©Ò¦bªº°O¿ý´N·|³Q¸Ñ°£¡A¦Ó¥B§Ú̦b¶i¦æ¸Ñ°£¾Þ§@®É¡A¤£¥²±NTTable³¡¥ó³]©w¦¨½s¿èª¬ºA¡C¥Ø«e«ü¼Ð©Ò¦bªº°O¿ý³Q¸Ñ°£¤§«á¡A³Q¸Ñ°£°O¿ý¤U±ªº©Ò¦³°O¿ý³£¦V«e²¾°Ê¡A°O¿ý«ü¼Ð¦Û°Ê²¾¨ìºò®ÁµÛ³Q¸Ñ°£ªº°O¿ýªº¤U¤@±ø°O¿ý¡C¦b¸Ñ°£°O¿ýªº¹Lµ{¤¤¨S¦³´£¿ô¥Î¤á¬O§_¯uªº·Q¸Ñ°£¥Ø«e°O¿ýªº¸ê°T½T»{®Ø¡A¦]¦¹¦b¶i¦æ¦¹¶µ¾Þ§@®Én¿¥[¤p¤ß¡A¦pªG¬O¶}µoÀ³¥Îµ{¦¡¡A³Ì¦nªº¿ìªk¬O´£¨Ñ¤@Ó½T»{¸ê°T®Ø½T«O¥Î¤á¤£·|·N¥~¸Ñ°£°O¿ý¡C ´¡¤J¤@±ø°O¿ý¤]«Ü²³æ¡ADelphi¬°¥Î¤á´£¨Ñ¨âºØ¤èªk¥Î¨Ó´¡¤J°O¿ý¨ì²{¦s¸ê®Æ®wªí¤¤¡A¤@ºØ¤èªk¬O¦b¥Ø«e°O¿ý«ü¼Ð©Ò¦bªº°O¿ý³B´¡¤J°O¿ý¡F¥t¤@ºØ¤èªk¬O¦b¸ê®Æ®wªíªº§À³¡´¡¤J°O¿ý¡C³o¨âºØ¤èªk¬O¤À§O©I¥sInsert¤èªk©MAppend¤èªk¹ê²{ªº¡C¦ý¬OµL½×¬O©I¥sInsert¤èªkÁÙ¬O©I¥sAppend¤èªk¦b¨ã¦³¯Á¤Þªº¸ê®Æ®wªí¤¤´¡¤J°O¿ý¡A¼W¥[¨ì¯Á¤Þªí¤¤ªº°O¿ý³£±N«ö·Ó¯Á¤Þ¶¶§Ç¼g¤J¨ì¸ê®Æ®wªí¤¤¡A¤]´N¬O»¡¹ï©ó¯Á¤Þªí¡A©I¥sInsert©MAppend¤èªkªº®ÄªG¬O¤@¼Ëªº¡C¨Æ¹ê¤W¡AAppend¤èªk¥u¾A¥Î©ó¨º¨Ç¨S¦³¯Á¤Þªºªí¡A³oºØ¨S¦³¯Á¤Þªºªí¨Ã¤£¤Q¤À¦³¥Î¦]¦Ó³q±`¤£«Ø¥ß³oºØªí¡C´X¥G¥ô¦ó±¡ªp¤U§Ú̳£¬O¥ÎInsert¤èªk¨Ó´¡¤J°O¿ý¡C ¥Î¤á¦b´¡¤J°O¿ý®É¤@¯ë¥i¥H±Ä¥Î¨âºØ¤è¦¡´¡¤J¡G³v¨B´¡¤J§Yº¥ý«Ø¥ß¤@±øªÅ°O¿ý¡AµM«á¦A¶ñ¥R°O¿ýªº¦UÓÄæ¦ì¡A³Ì«á¦A±N°O¿ý¼g¦^¨ìºÏºÐ¡A¦@¤À¤TÓ¿W¥ßªº¾Þ§@¨BÆJ¡F¦Ó¨Ï¥ÎInsertRecord¤èªk«K¥i¥H¤@¦¸±N´¡¤J°O¿ýªº¾Þ§@§¹¦¨¡C¡@ 14.7.1 ³v¨B´¡¤J¤èªk¡@ ³v¨B´¡¤J¤èªk¤À¬°¤TÓ©ú½Tªº¨BÆJ¡G¥ý©I¥sTTable³¡¥óªºInsert¤èªk¦bTTable¤¤«Ø¥ß¤@±ø·sªºªÅ°O¿ý¡AµM«á¶ñ¥R¸Ó°O¿ýªº¦UÓÄæ¦ì¡A³Ì«á©I¥spost¤èªk§â·s°O¿ý¼g¨ìºÏºÐ¤Wªº¹ê»Ú¸ê®Æ®w¤å¥ó¤¤¡A¦b¶ñ¥R¨ÃÂà°e°O¿ý¥H«e¡A¦Ò¼{´¡¤J°O¿ý¨ìªí¤¤ªº¤°»ò¦ì¸m¬O²@µL·N¸qªº¡A°²³]´¡¤Jªºªí¬O¦³¯Á¤Þªº¡A¦b©I¥spost¤èªk®É¡ADelphi·|¦Û°Ê¦a§â´¡¤Jªº·s°O¿ý«ö·Ó¯Á¤Þ¶¶§Ç´¡¤J¨ìªí¤¤ªº¥¿½T¦ì¸m¡C¦pªG´¡¤Jªºªí¤¤¨S¦³¯Á¤Þ¡A¨º»ò·s°O¿ý±N´¡¤J¨ì¥Ø«e«ü¼Ð©Ò¦b°O¿ýªº«á±¡C ¦]¦¹¡A±Ä¥Î³v¨B´¡¤J¤èªk´¡¤J°O¿ýªºµ{¦¡¥N½X¤@¯ë¦p¤U§Î¦¡¡G With Table do begin Insert; {´¡¤J¤@±øªÅ¥Õ°O¿ý} <¶ñ¥R¸Ó°O¿ýªº¦UÓÄæ¦ì> post; {±N´¡¤Jªº°O¿ý¼g¦^¨ìºÏ¤ùÀÉ} end; ¹ï©ó¨S¦³¯Á¤Þªº¸ê®Æ®wªí¡A¥i¥H¥ÎAppend¤èªk´À¥NInsert¤èªk§â·s°O¿ý´¡¤J¨ìªíªº§À³¡¡C¡@ 14.7.2 ©I¥sInsertRecord´¡¤J°O¿ý¡@ ¹ï©ó²³æªºÀ³¥Îµ{¦¡¡ADelphi¤¹³\¥Î¤á¥Î¤@±ø»y¥y´¡¤J¤@Ó·s°O¿ý¡A¦Ó¥B³oÓ·s°O¿ý¥i¥H±a¦³¥ô·N¦hÓ·sÄæ¦ìÈ¡CInsertRecord¤èªk§â·s°O¿ý¤¤Äæ¦ìªº½áÈ»y¥y©Mpsot¤èªk©I¥s¸s¸s²Õ¦X¶i¤@±ø»y¥y¤¤¡C InsertRecord¤èªk§â°O¿ýªº¦UÓÄæ¦ìȸs¸s²Õ¦X¦¨¤@ÓÄæ¦ìȼƸs¸s²Õ§@¬°¥¦ªº°ß¤@°Ñ¼Æ¡C¦bÄæ¦ìȼƸs¸s²Õ¤¤¡A¥i¥H¬°´¡¤Jªº°O¿ýªº¨CÓÄæ¦ì´£¨Ñ¤@ÓÄæ¦ìÈ¡A©Î±q³Ì¥ª¤@¦C¶}©l¨Ì¦¸¬°¥ô·N¦hÓÄæ¦ì½áÈ¡C ¤]´N¬O»¡¥Î¤á¥i¥H±qªíªº³Ì¥ªÃä¤@¦C°_¡A §â¦hÓ¦CªºÈ¦P®É¶Ç»¼µ¹InsertRecord¡Aª½¨ì©Ò¦³Äæ¦ì³£³Q½áÈ¡C¥Î¤á¤]¥i¥H¬Ù²¤«á±ªºÄæ¦ì¡AInsertRecord·|¥ÎªÅȶñ¥R³o¨Ç¨S¦³½áȪºÄæ¦ì¡C¥Î¤áÁÙ¥i¥H¹ï¨º¨Ç©ú½T§Æ±æ¥ÎªÅȶñ¥RªºÄæ¦ì¶Ç»¼«O¯d¦rNIL¨Ó¼Ð©ú¸ÓÄæ¦ì¬°ªÅ¡C ¦p§Ú̧Ʊæ¦bCustomer.DBªí¤¤´¡¤J¤@±ø°O¿ý¡A¥i¥H¥Î¤U±ªº¥N½X¨Ó¹ê²{¡G¡@ InsertRecord(['2000',NIL,NIL,NIL]);¡@ ¦b¤W±ªºµ{¦¡¥N½X¤¤¡A§ÚÌ¥u¶ñ¥R¤F¥|ÓÄæ¦ì¡GCustNo¡BCompany¡BAdd1 ¡B Add2 ¡CInsertRecord·|¦Û°Ê±N¨ä¥¦Äæ¦ì½á¥HªÅÈ¡C ¨Ò14.7 ¦b³oÓ¨Ò¤l¤¤¡A§Ú̦bCustNo.DBªí¤¤´¡¤J©M¸Ñ°£°O¿ý¡A³£¬O¦bµ{¦¡¤¤§¹¦¨³oÃþ¾Þ§@ªº¡A¦Ó¤£¦A¬O¨Ï¥ÎDBD©Î¼Æ¾ÚÂsÄý³¡¥ó§¹¦¨¡C¡@ ´¡¤J/¸Ñ°£°O¿ý¡@ µ{¦¡²M³æ¡G unit tt;¡@ interface¡@ uses SysUtils, Windows, Messages, Classes, Graphics, Controls, StdCtrls, Forms, DBCtrls, DB, DBGrids, Buttons, DBTables, Grids, ExtCtrls,Mask,Dialogs; ¡@ type TForm1 = class(TForm) DBGrid1: TDBGrid; DBNavigator: TDBNavigator; Panel1: TPanel; DataSource1: TDataSource; Panel2: TPanel; customerTable: TTable; BitBtn1: TBitBtn; Label1: TLabel; Label2: TLabel; BitBtn2: TBitBtn; BitBtn3: TBitBtn; CustNoEdit: TEdit; CompEdit: TEdit; procedure FormCreate(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure BitBtn3Click(Sender: TObject); procedure FormActivate(Sender: TObject); private { private declarations } public { public declarations } end; ¡@ var Form1: TForm1; ¡@ implementation ¡@ {$R *.DFM} ¡@ procedure TForm1.FormCreate(Sender: TObject); begin customerTable.Open; end; ¡@ procedure TForm1.BitBtn2Click(Sender: TObject); begin If (Length(CustNoEdit.text)=0)and (Length(CompEdit.text)=0) then MessageDlg('¨S¦³¿é¤J·s°O¿ýªºÄæ¦ìÈ!',mtError,[mbCancel],0) else with customerTable do begin IndexFieldNames:='CustNo'; If FindKey([CustNoEdit.text]) then MessageDlg('¤w¸g¦s¦b³o±ø°O¿ý!',mtError,[mbCancel],0) else InsertRecord([StrToInt(CustNoEdit.text),CompEdit.text,nil]); CustNoEdit.text:=' '; CompEdit.text:=' '; end; ¡@ end; ¡@ procedure TForm1.BitBtn3Click(Sender: TObject); begin If (Length(CustNoEdit.text)=0)and (Length(CompEdit.text)=0) then MessageDlg('¨S¦³¿é¤J¸Ñ°£ªº°O¿ýªºÄæ¦ìÈ!',mtError,[mbCancel],0) else with customerTable do begin IndexFieldNames:='CustNo'; If FindKey([CustNoEdit.text]) then begin If MessageDlg('§A½T©wn¸Ñ°£³o±ø°O¿ý¶Ü¡H',mtConfirmation, [mbYes,mbno],0)=mrYes then Delete; end else MessageDlg('¨S¦³§An¸Ñ°£ªº°O¿ý!',mtError,[mbCancel],0); CustNoEdit.text:=' '; CompEdit.text:=' '; end; end; ¡@ procedure TForm1.FormActivate(Sender: TObject); begin CustNoEdit.setfocus; end;¡@ end.¡@ 14.8 ¿é¤J¼Æ¾Úªº¦³®Ä©ÊÅçÃÒ¡@ ·í¥Î¤á¦V¤@Ó¸ê®Æ®wªí¤¤´¡¤J·s°O¿ý©Îקï즳°O¿ý®É¡A§ÚÌ¥²¶·½T«O¥Î¤á¿é¤Jªº¼Æ¾Ú¬O¦³®Äªº¡A¬°¦¹Delphi³q¹L¤TºØ¤£¦Pªº³~®|¥Î¨ÓÅçÃҥΤá¿é¤Jªº¼Æ¾Ú¬O§_¦³®Ä¡C ³o¤TºØ³~®|¬O¡G°ò©ó¸ê®Æ®wªíªº¦³®Ä©ÊÅçÃÒ¡B°ò©óÄæ¦ìªº¦³®Ä©ÊÅçÃÒ¡B°ò©ó°O¿ýªº¦³®Ä©ÊÅçÃÒ¡C °ò©ó¸ê®Æ®wªíªº¦³®Ä©ÊÅçÃÒ¡G ¦b¥Î¤á«Ø¥ß¸ê®Æ®wªí®É´N«Ø¥ß¦³®Ä©ÊÅçÃÒ¾÷¨î¡A¦p¦b¨Ï¥ÎDBD«Ø¥ß¤@Óªí®É¡A §ÚÌ¥i¥H¬°«Ø¥ßªº¸ê®Æ®wªí±Ôz¤@¨ÇÅçÃÒ¤â¬q¡A¥]¬AÄæ¦ìªº³Ì¤jÈ¡A³Ì¤pÈ¡A¹Ï§ÎÄæ¦ìªºÅã¥Ü®æ¦¡µ¥µ¥¡C¦b³]©w³o¨Ç¦³®Ä©ÊÅçÃÒ¾÷¨î®É¡A¤£»Ýn½s¼g¥ô¦óµ{¦¡¥N½X¡C°ò©ó¸ê®Æ®wªíªº¦³®Ä©ÊÅçÃÒ¬O·í¼Æ¾Ú¼g¨ì¸ê®Æ®w¤§«e¡A¥Ñ¸ê®Æ®w¥»¨¨Ó°õ¦æ¡CDelphi¤]°õ¦æ¤@¨Ç¦³®Ä©ÊÅçÃÒ¡A¦p¦b¼Æ¾Ú¼g¨ì¸ê®Æ®w¤§«eDelphi·|ÅçÃÒ¨C¤@ÓÄæ¦ì¬O§_³Q¶ñ¤J¬ÛÀ³ªºÈ¡A¦³Ãö³oºØ³~®|¨ÓÅçÃҼƾڪº¦³®Ä©Êªº¸Ô²Ó±¡ªp½Ð°Ñ¦ÒDBDªº¨Ï¥Î¡C °ò©óÄæ¦ìªº¦³®Ä©ÊÅçÃÒ¡G ¤@¯ë¦³¨âºØ¤èªk¨Ó¶i¦æ³oºØ¤è¦¡ªº¦³®Ä©ÊÅçÃÒ¡C Æ¡¬°°O¿ý¤¤»Ýn³]©w¦³®Ä©ÊÅçÃÒªºÄæ¦ì½s¼gOnvalidate¨Æ¥ó³B²z¹Lµ{¡C³o¼Ë¨C·í¸ÓÄæ¦ìªºÈ³Qקï®É¡A¸ÓÄæ¦ìªºOnValidate¨Æ¥ó³B²z¹Lµ{´N·|³Q©I¥s¡A¶i¦Ó¹ï³Qק諸Äæ¦ìȶi¦æÅçÃÒ¡C Æ¢¹ï©ó°O¿ý¤¤n¨D«DªÅªºÄæ¦ì¡]¦p±K½X©ÎÃöÁä¦rµ¥¡^¡A§ÚÌ¥²¶·º¥ý³]©w³o¨ÇÄæ¦ìªºRequiredÄݩʬ°True¡AµM«á¬°³o¨ÇÄæ¦ì½s¼gOnValidate¨Æ¥ó³B²z¹Lµ{¡A³o¼Ë¦bקï²{¦s°O¿ý©Î´¡¤J·s°O¿ý®É¡A¦b¼g¤J¸ê®Æ®w¤§«e¡A¦pªGn¨D«DªÅªºÄæ¦ì¤¤¨S¦³¶ñ¤J¾A·íªºÄæ¦ìÈ¡A¨º»ò·|¥X²{¿ù»~¸ê°T´£¥Ü¥Î¤á¥²¶·¿é¤JÄæ¦ìÈ¡C °ò©ó°O¿ýªº¦³®Ä©ÊÅçÃÒ¡G ³oºØÅçÃҤ覡¤@¯ë¦bTTable³¡¥óªºBeforePost¨Æ¥ó³B²z¹Lµ{¤¤¶i¦æ³B²z¡A§Y¦b°O¿ý¼g¦^¨ì¸ê®Æ®w¤§«e¹ï°O¿ýªº¨CÓÄæ¦ìȶi¦æ¦³®Ä©ÊÅçÃÒ¡C ¨Ò14.8 ¦bµ{¦¡¤¤¹ïÄæ¦ìȪº¦³®Ä©Ê¶i¦æÅçÃÒ¡C 1. «Ø¥ß¤@Ó¥ÎTEdit³¡¥óÂsÄýORDERS.DBªíªºÀ³¥Î¡A¦p¹Ï14.25©Ò¥Ü¡C 2. קïTDataSource³¡¥óªºAutoEditÄݩʬ°True¡C 3. ³sÄò«ö¨â¤UTTable³¡¥ó¥´¶}Äæ¦ì½s¿è¾¹Fields Editor¡A¨Ã«ö¤@¤USaleDateÄæ¦ì¡C 4. ¦bObject Inspector¤¤³sÄò«ö¨â¤USaleDateÄæ¦ìª«¥óªºOnValidate¨Æ¥ó¡A ¬°¸ÓÄæ¦ìª«¥ó½s¼g¨Æ¥ó³B²z¹Lµ{¦p¤U¡G¡@ TForm1.Table1SaleDateValidate(Sender:TField); begin If SaleDate.Value>Now then raise Exception.Create('¤£¯à¿é¤J¤@Ó¥¼¨Óªº¤é´Á'); end; ·í³oÓÀ³¥Îµ{¦¡°õ¦æ®É¡A¥Î¤áקï©Î´¡¤JORDERS.DB¤¤ªº°O¿ý®É¡A ¸ÓÀ³¥Îµ{¦¡·|¹ï¾P°â¤é´Á¡]SaleDate¡^Äæ¦ìªºÈ¶i¦æÅçÃÒ¡A¸ÓÄæ¦ìȤ£¯à±ß©ó¨t²Îªº¥Ø«e¤é´Á¡Aµ{¦¡¤¤©I¥sNow¤èªkÀò±o¨t²Îªº¥Ø«e¤é´Á¡C¦pªGÄæ¦ìȤj©ó¨t²Îªº¥Ø«e¤é´Á·|¥X²{¤@¿ù»~¸ê°T´£¥Ü®Ø¡A§iª¾¥Î¤á¤£¯à¿é¤J¤@Ó¥¼¨Óªº¤é´Á¡C ¨Ï¥ÎTDBComBox³¡¥ó©MTDBLookupComBox³¡¥ó¨Ó¨î¥Î¤á¿é¤JÄæ¦ìȪº½d³ò¡C «Ø¥ß¬d¬Ýorders.dbªíªºÀ³¥Î¡A«Ø¥ß¦nªºµ¡Åé¦p¹Ï14.25©Ò¥Ü¡Cµ¡Å餤Åã¥ÜTerms Äæ¦ìªº¬OTDBComBox³¡¥ó¡AÅã¥ÜEmpNoÄæ¦ìªº¬OTDBLookupComBox³¡¥ó¡C¡@ ¹Ï14.25 ¥Î¼Æ¾ÚÂsÄý³¡¥ó¨î¥Î¤áªº¿é¤J¡@ TDBComBox©MTDBLookupComBox³¡¥óªºÄÝ©ÊȦpªí14.8©Ò¥Ü¡G¡@ ªí14.8 µ¡Å餤¦U³¡¥óªºÄݩʳ]©w ¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w ³¡ ¥ó ÄÝ ©Ê ÄÝ ©Ê È ¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X DataField Terms DBComBox1 DataSource DataSource1 Items Prepaid Net 30 COD ¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X DataField EmpNo DataSource DataSource1 DBLookupComBox LookupSource DataSource2 KeyField EmpNo LookupField EmpNo ¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X DataSource1 DataSet Table1 AutoEdit True ¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X DataSource2 DataSet Table1 AutoEdit True ¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X Table1 DatabaseName DemosDB TableName orders.db ¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X¡X Table2 DatabaseName DemosDB TableName orders.db ¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w ¸ÓÀ³¥Î°õ¦æ®É¡A·í¥Î¤áקï©M´¡¤J°O¿ý¨ìORDERS.DBªí¤¤®É¡ATermsÄæ¦ìªºÈ¥i¥H±q¸s¸s²Õ¦X®Ø¤¤ªºPrepaid¡BNet30¡BCOD¤TÓȤ¤¥ô¿ï¡AEmpNoÄæ¦ìªºÈ¬O±q¥t¤@ÓªíEmployee¤¤Àò±oªº¶±û¸¹½X¡A¥Î¤á¥i¥H±q¤¤¿ï¾Ü¡C ¡@ |
«á¤@¶ «e¤@¶ ¦^¥Ø¿ý ¦^º¶ |