delphi开发web程序常见问题(common problems of developing web program in delphi)

delphi开发web程序常见问题(common problems of developing web program in delphi)

ID:12334049

大小:32.50 KB

页数:10页

时间:2018-07-16

上传者:xinshengwencai
delphi开发web程序常见问题(common problems of developing web program in delphi)_第1页
delphi开发web程序常见问题(common problems of developing web program in delphi)_第2页
delphi开发web程序常见问题(common problems of developing web program in delphi)_第3页
delphi开发web程序常见问题(common problems of developing web program in delphi)_第4页
delphi开发web程序常见问题(common problems of developing web program in delphi)_第5页
资源描述:

《delphi开发web程序常见问题(common problems of developing web program in delphi)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

delphi开发web程序常见问题(CommonproblemsofdevelopingwebprograminDelphi)CommonproblemsofdevelopingWebprograminDELPHI--------------------------------------------------------------------------------2004-05-27Webprogramdevelopmentpresentsagreatchallengeforthedevelopmentoftools,inthefaceofnumeroususersdemand,manycompanieslaunchedadevelopmentplatform:thedevelopmentofdesktopapplicationsandC/Sapplications,middleware,Webserver.Thisputsprogrammersinthefaceofapileoftools.DELPHIandotherdevelopmenttools,becauseitisanopensystem,aslongastheflexibleuseofsomecontrols,todevelopasystemofvarioustypes,regardlessofwhethertheNTieprogram,multi-threadedprogram,distributedcomputingprogram(includingDCOMandCORBAR),TCPprogramandWebprogram,ActiveX,middleware,pushtheprogram(Push)even,youcanuseittowriteassembler.DELPHIneatlyencapsulatesISAPI/NSAPI/CGI/WCGIandsoonintoaclassthatallowsuserstogetdifferentsystemsaslongastheycompiletheresultsatcompiletime.InDELPHI4,InprisehasfurtherstrengtheneditssupportforWebprogramdevelopmenttodevelopbetterandstrongersystems.HereareafewcommonproblemsindevelopingWebapplications foryourreference.Ifnospecialdeclarationismade,theprogramisrununderDELPHI4.HowdoIreturnanimagefromtheWebServerApplication?WebServerApplicationnotonlygeneratescomplexpagedocuments,butalsoreturnsdifferentimagesbasedonuserrequests.Ofcourse,thereisasimplerway,dependingontheinputparameter,the"imgSRC..."flagalsopointstodifferentURLaddresses.Herewedonotusethismethod,butinsteaduseDLLtoreturntheimage.Ofcourse,firstyouhavetobuildapagecontainer(page,producer),whichreadsasfollows:"HTML""Body",This,is,a,test,BR,IMG,src=,/scripts/mydll.dll/picture,/body"/html"Next,wesettheactioneventcorrespondingtothePathInfoandreturntheimageresult.Thesourcecodeisasfollows:(Note:theJPEGdeclarationisincludedinthecelldeclaration.)ProcedureTWebModule1.WebModule1WebActionItem1Action(Sender:TObject); Request:TWebRequest;Response:TWebResponse;VARHandled:Boolean);VarJpgalign=left:TJpegImage;S:TMemoryStream;BeginJpgalign=left:=TJpegImage.Create;TryJpg,align=left.LoadFromFile(`test');S:=TMemoryStream.Create;TryJpgalign=left.SaveToStream(S);S.Position:=0;Response.contenttype:=′image/jpeg′;response.contentstream:=s;//必须在流释放前完成 response.sendresponse;finallyp.free;than;finallyjpgand=left.free;than;than;实际上用这种方法和前面提到的简单做法相比,具有更安全和更灵活的特点.在某些地方灵活使用,以此为基础稍加修改可以产生一般开发工具难以实现的效果.如何在isapi/nsapi动态连接库(teach)中使用本地数据库驱动程序(nativeaccessdrives)?这是因为dao3.0或者dao3.5是所谓thread-safe(线程安全程序),而一个web服务器(例如iis)会随用户请求产生多个线程,同时把isapi对应的dll也列为线程.这时isapi就会通过bde通知dao,告诉它不符合线程安全规定.解决的方法有很多,如果你一定要访问access95/97库,那么可以通过odbc访问.odbc不会经过dao,而且也是一个线程安全程序.此外还有一些第三方的控件集,通过他们可以直接由bde访问access 95/97,效率更高.用户访问我web服务器上的isapiteach,可是报告:"invalidfilename"(无效的文件名),然而文件的确存在的.对了,我的数据库在一台novell服务器上.这是为什么呢?你没有设定对应于你iusr_xxx账户的驱动器路径映射(maping).因为novell不是采用fat,所以要手工添加路径映射.当然,可以做成开机登录脚本.请牢记,如果你运行iis作为web服务器,而又涉及novell,无论作为文件服务器或数据库服务器,都要定义好路径映射."invalidconfigurationparameterofthealias(alias_name}"(无效的别名配置),当我设置一个odbcdsn,并通过它访问isapi/nsapi服务器时就出现这样一个错误.你如果要为访问的用户(iis用户)建立一个odbc别名,那么要注意创建一个systemdsn(系统dns),而不要创建"用户dns",虽然"用户dns"是缺省设定.如何取得客户机(访问机器)的名称和ip地址?实现这个功能用tcp控件来做非常容易.从internet页面上选取一个tcp控件,然后直接就可以得到你所需要的:memo1.lines.add(tcp1.localhostname);memo1.lines.add(tcp1.LocalIp);Ofcourse,ifyoudon'twanttodoit,there'samorecomplicated approach:UsesWinsock;ProcedureTForm1.FormCreate(Sender:TObject);VarWVersionRequested:WORD;WsaData:TWSAData;Begin{createWinSock}WVersionRequested:=MAKEWORD(1,1);WSAStartup(wVersionRequested,wsaData);End;ProcedureTForm1.Button1Click(Sender:TObject);VarP:PHostEnt;s:array[0..128],of,char;P2:pchar;Begin{getthecomputername}GetHostName(@s,128); P:=GetHostByName(@s);Memo1.Lines.Add(p^.h_Name);{getthemachineIPaddress}P2:=iNet_ntoa(PInAddr(p^.h_addr_list^)^);Memo1.Lines.Add(P2);End;ProcedureTForm1.FormDestroy(Sender:TObject);Begin{releaseWinSock}WSACleanup;End;Thisisastand-aloneunitthatcallsWINSOCK,andyoucanembeditdirectlyintoyourprogram.InDELPHI3,whycan'tyoucreaterealmultithreadedDLL?AlthoughtheISAPIDLLwizardinDELPHI3hasgeneratedalargeamountofcodeforcreatingmultithreadedDLL,thereisaseriousflaw:thereisnoclaimthattheapplicationisa multithreadedprogram.Soyouneedtoaddaword:IsMultiThread:=TRUE;PutthewordsintheDPRprogramBeginendblockatthebeginning,makingitthefirstsentence.HowdoIknowifI'mconnectedtoInternetnow?TheeasiestwayistouseaTCPcomponenttogetyourcurrentIPanddeterminewhethertoconnecttotheInternetbyjudgingIP.Suchas:IfTCP1.LocalIp='0.0.0.0'thenShowMessage(nolinktoInternetatpresent!');It'simportanttonotethatsinceInternetandIntranetarenotfundamentallydifferent,itisgenerallyimpossibletodeterminewhethertoconnecttoInternetorjustjoinIntranet.Ofcourse。YoucanalsoaddaPINGcomponent,gotoPING,arelativelystable,fastersite,ifconnected,itshowsthatyouhaveaccesstoInternet.However,thisapproachisnotuniversal.HowdoIprintaWebpage?YoucanchoosetheAutoPrintmethodoftheHTMLcontrol.Suchas:UsesPrinters; ProcedureTForm1.Button1Click(Sender:TObject);VarOldCur:TCursor;BeginOldCur:=Screen.Cursor;用打印机开始begindoc;html1自动打印(处理);标题:=html1.url;EndDoc;结束;屏幕上的光标:=oldcur;结束;此外还可以利用其PrintPage方法。不过我推荐你采用自动打印,因为这样控制更灵活,可以过滤一些你不希望打印的内容。结语 最后我还要向你推荐几套Delphi编写Web程序的增强控件集,它们是:1)CGI专家4由Lars德国公司出品,编写壳-CGI、赢得-CGI、ISAPI和NSAPI程序特别方便。2)互联网控件集Netmaster的。Delphi4中的互联网控件集就是它们的杰作,和Delphi结合得非常好。你可以去下载它们的最新版,功能更强大,而且对Delphi用户是免费的。3)省通信出品的powertcp的确非常强大,如果编写专业级TCP应用程序必不可少提供的有很多功能实际是由DLL。

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
大家都在看
近期热门
关闭