ASP网站制作之override deal with window closing in...
优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合activeX功能强大,很多php做不到的asp+activeX能做到,例如银行安全控件application|windowInthedatabaseapplicationdevelopment,theprogrammershouldoftendealwithonethingthatiswhentheusercloseawindow(calledForminDelphi)wheredatawasmaintained,theprogramshouldjudgewhetherthedatawaschangedwithoutsavingandwarntheuseraboutthiscase.Almostalltheprogrammercandealwiththiseasily,andthecodeisverysimpleasweknow.Thefollowingcode(writteninDelphi6)isthenormalmethodtodealwiththeproblem.ItisbaseononetablemaintenanceandthereareaDBGrid(namedDBGRid)whichshowsthedataofthetable,aDBEdit(namedDBEditName)whichcanbeusedtoeditthedataofthetableandsixButtons(respectivenamedBtnAdd,BtnModify,BtnDelete,BtnSave,BtnCancle,BtnClose).ThelastbuttonisusedtoclosetheFormandtheothersaredealingwiththedata.Ithinktheirnameshowtheirfunctionclearlyandnoexplanationisgivenhere.unitUnit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,ExtCtrls,StdCtrls,Buttons,Grids,DBGrids;
type
TForm1=class(TForm)
BtnModify:TBitBtn;
BtnCancel:TBitBtn;
BtnAdd:TBitBtn;
BtnDelete:TBitBtn;
BtnSave:TBitBtn;
BtnClose:TBitBtn;
DBGrid1:TDBGrid;
procedureFormCloseQuery(Sender:TObject;varCanClose:Boolean);
procedureBtnSaveClick(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
protected
{Protecteddeclarations}
functionDataModifiedWithoutSaving():Boolean;virtual;abstract;
end;
varForm1:TForm1;
implementation
{$R*.dfm}
procedureTForm1.FormCloseQuery(Sender:TObject;
varCanClose:Boolean);
begin
ifDataModifiedWithoutSavingthen
begin
ifMessageDlg(Thedatahasbechangedwithoutsaving,wouldyoulikesavethedata?,mtWarning,,0)=mrNothen
begin
CanClose:=True;
endelsebegin
BtnSaveClick(Self);
CanClose:=True;
end;
end;
end;
procedureTForm1.BtnSaveClick(Sender:TObject);
begin
//
end;
end.
Theabovecodeisnotverygood(maybeyoucangiveamoreeffectone),butitreallycandealwiththeproblemwementionedatthebeginningofthepaper.Butletushaveathoughtnow;ifwegottwentyformsweshouldcopythecodeoftheFormCloseQueryfunctiontwentytimes.Doyouthinkitisaboringthing?Maybenot,buthowaboutthattheteamleaderdonotthinkthecodeyouhavewrittenisverygoodandhegivesyouanotherone?Thencopyagain?Ithinkitisneededtofindaneffectmethodtodealwiththisproblem.ThetoolIshowtheexamplehereisDelphi,ofcoursemanyothertoolsareusedinthesoftwarefieldsuchasVirsualC++,VirsualBasicandsoon.Butmostofthem(almostallofthem)arethetoolswhichsupportOOP(object-oriented
programming).ThethreemainpropertyofOOPareEncapsulation,InheritanceandDynamic.WecanusetheDynamicpropertytodealwiththeproblem.Todoso,weneedaformwhichhastheFormCloseQueryfunctiontobetheparentformofthosewherethedataismaintained.NowyoumayaskmeaquestionthatishowabouttheDataModifiedWithoutSavingfunction,thisfunctionhastobedifferentineveryform,andtheprogramshouldcalltheoneinthechildFormnottheoneintheparentForm.Yes,itisabsolutelyrightanditisjustwhattheDynamicdoes.WhenusingDelphi,thevirtualanddynamicmethodsshowthepropertyofDynamic.Virtualanddynamicmethods,unlikestaticmethods,canbeoverriddenindescendantclasses.Whenanoverriddenmethodiscalled,theactual(runtime)typeoftheclassorobjectusedinthemethodcallDnotthedeclaredtypeofthevariableDdetermineswhichimplementationtoactivate.Dorememberthatthevirtualisneededhere,becausetheDelphiacceptthemethodtobestaticdefault.
FunctionDataModifiedWithoutSaving():Boolean;virtual;abstract;
Anotherthingwehavetodoismoveitfromprivateparttotheprotectedpart,sincetheprivatepartcannotaccessoutoftheclass.AndIthinktheimplementationpartofthefunctionisuseless,soIdeletethispartanddeclarethef</p>大家可以自己去看一看.可以说看得想呕吐.以前有次下了个动网来看.里面连基本内置函数的保护措施(函数没防御性)都没有.难怪经常补这个补那个了.可能现在.NET版会好点吧 Application:这个存储服务端的数据,如果不清除,会直到web应用程序结束才清除(例如重启站点) 另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件) 作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。 ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。 还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。 以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。 那么,ASP.Net有哪些改进呢? 尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。 Request:从字面上讲就是“请求”,因此这个是处理客户端提交的东东的,例如Resuest.Form,Request.QueryString,或者干脆Request("变量名")
页:
[1]