{"id":948,"date":"2010-03-12T13:17:00","date_gmt":"2010-03-12T05:17:00","guid":{"rendered":""},"modified":"2013-11-17T11:48:38","modified_gmt":"2013-11-17T03:48:38","slug":"%e5%88%a9%e7%94%a8delphi%e7%9a%84datasnap%e7%bc%96%e5%86%99%e9%ab%98%e6%96%af%e6%ad%a3%e7%ae%97web%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/948.html","title":{"rendered":"\u5229\u7528Delphi\u7684DataSnap\u7f16\u5199\u9ad8\u65af\u6b63\u7b97WEB\u7a0b\u5e8f"},"content":{"rendered":"<p>\u5176\u5b9e\u7c7b\u4f3c\u4e8e\u8fd9\u79cd\u7684WEB\u5e94\u7528\u7a0b\u5e8f\u7528ASP.NET\u505a\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\uff0c\u56e0\u4e3aASP.NET\u6709\u5f3a\u5927\u7684C#\u8bed\u8a00\u4f5c\u4e3a\u540e\u76fe\u3002\u4f46\u662f\u4eca\u5929\u6211\u4e0a\u8bfe\u7684\u65f6\u5019\u7a81\u53d1\u5947\u60f3\uff0c\u60f3\u5229\u7528Delphi\u7684DataSnap\u6765\u505a\uff0c\u7b2c\u4e00\u60f3\u5230\u7684\u4fbf\u662fPHP+DataSnap\uff0c\u7528JSON\u4f5c\u4e3a\u4e2d\u95f4\u5c42\u6570\u636e\uff0c\u4f46\u662f\u540e\u6765\u4ed4\u7ec6\u4e00\u60f3\uff0c\u6709\u4e86JSON\uff0c\u90a3\u4f55\u5fc5\u7528PHP\u5462\uff0c\u6740\u9e21\u7109\u7528\u725b\u5200\uff01\u7528JavaScript\u811a\u672c\u5b8c\u5168\u8db3\u591f\u4e86\u3002\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u770b\u64cd\u4f5c\uff0c\u9996\u5148\u7528Delphi\u5efa\u7acb\u4e00\u4e2aDataSnap\u7a0b\u5e8f\uff0c\u76f4\u63a5File-&gt;New-&gt;Other\uff0c\u7136\u540e\u770b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/b2460c09601e46e463d9863a.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u786e\u5b9a\u540e\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/1cff731f19f042c11ad5763b.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u597d\u4e86\u540e\uff0c\u9996\u9875\u8bbe\u7f6e\u4e00\u4e0bDSHTTPService\u7ec4\u4ef6\u7684HttpPort\u5c5e\u6027\uff0c\u4e5f\u5c31\u662f\u8bbe\u7f6e\u6211\u4eec\u7684\u670d\u52a1\u5668\u7aef\u53e3\uff0c\u8bbe\u4e3a81\uff0c\u514d\u5f97\u4e0e\u6211\u672c\u673a\u7684\u7aef\u53e3\u76f8\u51b2\u7a81\u3002\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/43d0a565eea334c5f6365404.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u7136\u540e\u6765\u5230ServerMethodsUnit1\u5355\u5143\uff0c\u5148\u5f15\u7528\u5355\u5143Math\u548cDBXJson,\u5176\u4e2dDBXJson\u662fDelphi\u4e2dJson\u76f8\u5173\u7684\u5355\u5143\u3002\u7136\u540e\u6211\u4eec\u5728TServerMethods1\u7c7b\u91cc\u9762\u6dfb\u52a0\u6211\u4eec\u9700\u8981\u7684\u65b9\u6cd5\u548c\u51fd\u6570\uff0c\u5355\u5143\u7684\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nunit ServerMethodsUnit1;\r\n\r\ninterface\r\n\r\nuses\r\n  SysUtils, Classes, DSServer,Math,DBXJson;\r\n\r\ntype\r\n  TServerMethods1 = class(TDSServerModule)\r\n  private\r\n    { Private declarations }\r\n  public\r\n    { Public declarations }\r\n    \/\/*****************\u9ad8\u65af\u6295\u5f71\u6b63\u7b97\uff0c\u5df2\u77e5B\u3001L\u6c42x\u3001y\uff0cB\u3001L\u4e3a\u79d2\u503c********************\r\n    procedure GassBLToxy(B,L:extended;var x,y:extended);\r\n    \/\/*****************\u5c06\u89d2\u5ea6\u8f6c\u6362\u6210\u79d2\u503c\uff0c\u598230.20.10\u8f6c\u6362\u6210\u79d2\u503c**********************\r\n    function CoordinateToSeconds(Deg:string):extended;\r\n    function BLToxy(B,L:string): TJSONObject;\r\n  end;\r\n\r\nvar\r\n  ServerMethods1: TServerMethods1;\r\n\r\nimplementation\r\n\r\n{$R *.dfm}\r\n\r\n{ TServerMethods1 }\r\n\r\nfunction TServerMethods1.BLToxy(B, L: string): TJSONObject;\r\nvar x,y: Extended;\r\nbegin\r\n  GassBLToxy(CoordinateToSeconds(B),CoordinateToseconds(L),x,y);\r\n  Result := TJSONObject.Create;\r\n  Result.AddPair(TJSONPair.Create('x',FloatToStr(x)));\r\n  Result.AddPair(TJSONPair.Create('y',FloatToStr(y)));\r\nend;\r\n\r\nfunction TServerMethods1.CoordinateToSeconds(Deg: string): extended;\r\nvar deg1,deg2:string;\r\n    sum:extended;\r\n    temp:string;\r\nbegin\r\n    sum:=0;\r\n    temp:=Deg;\r\n    if copy(Deg,1,1)='-' then Deg:=Copy(Deg,2,Length(Deg)-1);\/\/\u5982\u679c\u4e3a\u8d1f\u6570\u5219\u5316\u4e3a\u6b63\u7684\r\n    if pos('.',Deg)=0 then\r\n      begin\r\n       sum:=StrToInt(Deg)*3600;\r\n      end;\r\n    if pos('.',Deg)&lt;&gt;0 then\r\n      begin\r\n        deg1:=copy(deg,pos('.',deg)+1,length(deg)-pos('.',deg));  \/\/deg1=30.20\r\n        deg2:=copy(deg,1,pos('.',deg)-1);                         \/\/deg2=60\r\n        sum:=StrToInt(deg2)*3600;                                 \/\/\u5316\u6210\u79d2\r\n        if pos('.',deg1)=0 then\r\n          begin\r\n           sum:=sum+StrToInt(deg1)*60;\r\n          end;\r\n        if pos('.',deg1)&lt;&gt;0 then\r\n          begin\r\n           deg2:=copy(deg1,1,pos('.',deg1)-1);\r\n           sum:=sum+StrToInt(deg2)*60;\r\n           deg2:=copy(deg1,pos('.',deg1)+1,length(deg1)-pos('.',deg1));\r\n           sum:=sum+StrToFloat(deg2);\r\n          end;\r\n      end;\r\n   result:=sum;\r\n   if copy(temp,1,1)='-' then result:=-result;\r\nend;\r\n\r\nprocedure TServerMethods1.GassBLToxy(B, L: extended; var x, y: extended);\r\nvar B_r,sinB,cosB,cosB2,l_cha,l_r,N,a0,a4,a6,a3,a5,l2:extended;\r\nbegin\r\n  B_r := B \/ 3600 \/ 180 * PI;  \/\/B_r\u4e3aB\u7684\u5f27\u5ea6\u503c\r\n  sinB := Sin(B_r);\r\n  cosB := Cos(B_r);\r\n  cosB2 := Sqr(cosB);\r\n  l_cha := L - (Round(L \/ (6 * 3600)) * 6 - 3) * 3600;\/\/\u63096\u5ea6\u5e26\uff0cl\u4e3aL\u4e0e\u4e2d\u592e\u5b50\u5348\u7ebf\u4e4b\u5dee\r\n  l_r := l_cha \/ 3600 \/ 180 * PI;                      \/\/l_r\u4e3al\u7684\u5f27\u5ea6\u503c\r\n  N := 6399698.902 - (21562.267 - (108.973 - 0.612 * cosB2) * cosB2) * cosB2;\r\n  a0 := 32140.404 - (135.3302 - (0.7092 - 0.004 * cosB2) * cosB2) * cosB2;\r\n  a4 := (0.25 + 0.00252 * cosB2) * cosB2 - 0.04166;\r\n  a6 := (0.166 * cosB2 - 0.084) * cosB2;\r\n  a3 := (0.3333333 + 0.001123 * cosB2) * cosB2 - 0.1666667;\r\n  a5 := 0.0083 - (0.1667 - (0.1968 + 0.004 * cosB2) * cosB2) * cosB2;\r\n  l2 := Sqr(l_r);\r\n  x := 6367558.4969 * B_r - (a0 - (0.5 + (a4 + a6 * l2) * l2) * l2 * N) * sinB * cosB;\r\n  y := (1 + (a3 + a5 * l2) * l2) * l_r * N * cosB;\r\nend;\r\n\r\nend.\r\n<\/pre>\n<p>\u597d\u4e86\uff0c\u73b0\u5728\u6211\u4eec\u8fd0\u884c\u6211\u4eec\u5199\u597d\u7684DataSnap\u670d\u52a1\u7a0b\u5e8f\uff0c\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/2612090939c95305e8248801.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u7136\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u5728IE\u4e2d\u8bbf\u95ee\u4e86\uff0c\u56e0\u4e3a\u6211\u4eec\u5728\u524d\u9762\u7684\u8bbe\u7f6e\u4e2d\u8bbe\u7f6e\u4e86\u6709TCP\/IP\u548cHTTP\u4e24\u79cd\u65b9\u5f0f\uff0c\u5f53\u7136\u6211\u9700\u8981\u7684\u662fHTTP\u3002\u5728IE\u4e2d\u8f93\u5165\u5730\u5740\uff1a<\/p>\n<p>http:\/\/127.0.0.1:81\/datasnap\/zaitian\/TServerMethods1\/BLToxy\/11.0\/12.0<\/p>\n<p>\u5176\u4e2ddatasnap\u662f\u56fa\u5b9a\u53c2\u6570\uff0czaitian\u662f\u4eec\u8bbe\u7f6e\u7684\uff0c\u5728\u56fe\u4e09\u4e2d\u6709\u8bf4\u660e\u3002TServerMethods1\u662f\u6211\u4eec\u7684\u7c7b\uff0cBLToxy\u662f\u6211\u4eec\u8c03\u7528\u7684\u51fd\u6570\uff0c11.0\u548c12.0\u662f\u51fd\u6570\u7684\u53c2\u6570\uff0c\u5404\u4e2a\u53c2\u6570\u4e4b\u95f4\u90fd\u7528\/\u7b26\u53f7\u5206\u5f00\u3002\u8bbf\u95ee\u540e\u6d4f\u89c8\u5668\u5c31\u663e\u793a\u51fa\u670d\u52a1\u5668\u8fd4\u56de\u7684JSON\u6570\u636e\uff0c\u5982\u4e0b\uff1a{&#8220;result&#8221;:[{&#8220;x&#8221;:&#8221;1218127.4049474&#8243;,&#8221;y&#8221;:&#8221;328008.141507914&#8243;}]}<\/p>\n<p>\u7136\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u7528JavaScript\u6765\u8c03\u51fa\u6211\u4eec\u7684x\u548cy\u7684\u503c\u4e86\uff0c\u5206\u522b\u7528data.result[0].x\u548cdata.result[0].y\u6765\u8c03\u7528\u3002<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/c4e48311721d7534203f2e0c.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u6700\u540e\u6211\u4eec\u7f16\u5199HTML\u670d\u52a1\u7aef\uff0c\u5728\u540e\u53f0\u8c03\u7528\u6211\u4eec\u7684DataSnap\u7a0b\u5e8f\uff0c\u5f97\u51fa\u7ed3\u679c\uff0cHTML\u7f51\u9875\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&quot;&gt;\r\n\r\n&lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot;&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot; \/&gt;\r\n\r\n&lt;title&gt;DataSnap\u5750\u6807\u8f6c\u6362&lt;\/title&gt;\r\n\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;JQuery.js&quot;&gt;&lt;\/script&gt;\r\n\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n\r\nfunction trans()\r\n\r\n{\r\n\r\n$.ajax({\r\n\r\n      type:&quot;get&quot;,\r\n\r\n      url:&quot;http:\/\/127.0.0.1:81\/DataSnap\/zaitian\/TServerMethods1\/BLToxy\/&quot;+$(\u2018#coor_B\u2019).val()+&quot;\/&quot;+$(\u2018#coor_L\u2019).val(),\r\n\r\n      dataType:&quot;json&quot;,\r\n\r\n      success:function(data){\r\n\r\n       $(\u2018#coor_x\u2019).val(data.result&#x5B;0].x);\r\n\r\n       $(\u2018#coor_y\u2019).val(data.result&#x5B;0].y);\r\n\r\n      }\r\n\r\n      })\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n\r\n&lt;body&gt;\r\n\r\n&lt;div style=&quot;text-align:center; margin-top:100px;&quot;&gt;\r\n\r\n&lt;label&gt;B\uff1a&lt;\/label&gt;&lt;input type=&quot;text&quot; id=&quot;coor_B&quot; value=&quot;11&quot;\/&gt;\r\n\r\n&lt;label&gt;L\uff1a&lt;\/label&gt;&lt;input type=&quot;text&quot; id=&quot;coor_L&quot; value=&quot;12&quot;\/&gt;\r\n\r\n&lt;input type=&quot;button&quot; value=&quot;\u8f6c\u6362&quot; onclick=&quot;trans()&quot;\/&gt;\r\n\r\n&lt;label&gt;x\uff1a&lt;\/label&gt;&lt;input type=&quot;text&quot; id=&quot;coor_x&quot; \/&gt;\r\n\r\n&lt;label&gt;y\uff1a&lt;\/label&gt;&lt;input type=&quot;text&quot; id=&quot;coor_y&quot; \/&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u6548\u679c\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/bb0655b4861c59fb37d3ca0e.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u7f51\u9875\u4ee3\u7801\u4e2d\u987b\u8981\u8bf4\u660e\u7684\u662f\uff0c\u8c03\u7528AJAX\u65f6\u91cc\u9762\u7684\u4ee3\u7801\u8981\u6ce8\u610f\u5927\u5c0f\u5199\uff0c\u6211\u521a\u5f00\u59cb\u5c31\u662f\u628adataType:&#8221;json&#8221;\u5199\u6210\u4e86datatype:&#8221;json&#8221;\u624d\u59cb\u7ec8\u4e0d\u80fd\u89e3\u91caJSON\u6570\u636e\u3002<\/p>\n<p>\u5176\u5b9eDataSnap\u8fd8\u53ef\u4ee5\u505a\u6210dll\u6587\u4ef6\uff0c\u7136\u540e\u4e0eIIS\u7ed3\u5408\u8d77\u6765\uff0c\u6216\u662f\u505a\u6210exe\u7684CGI\u6587\u4ef6\uff0c\u4e0eApache\u7ed3\u5408\u8d77\u6765\u3002\u53ea\u662f\u5728\u65b0\u5efa\u9879\u76ee\u7684\u65f6\u5019\u65b0\u5efaDataSnap WebBroker Application\u5c31\u53ef\u4ee5\u4e86\u3002\u6211\u8fd9\u91cc\u5c31\u4ee5CGI\u505a\u5b9e\u9a8c\u3002<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/3a1bc1fde7e8c6b7b801a010.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/b11ed355d822cb6dd1090684.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u7136\u540e\u5199\u7684\u4ee3\u7801\u5c31\u548c\u4e0a\u9762\u7684\u4e00\u6837\u4e86\u3002\u7f16\u8bd1\u540e\u751f\u6210\u6211\u4eec\u9700\u8981\u7684exe\u6587\u4ef6\uff0c\u7136\u540e\u6211\u4eec\u628a\u8be5\u6587\u4ef6\u653e\u5230Apache\u7684cgi-bin\u76ee\u5f55\u4e0b\u9762\u53bb\uff0c\u7136\u540e\u5728IE\u91cc\u9762\u8bbf\u95ee\u5c31\u53ef\u4ee5\u4e86\uff0cIE\u8bbf\u95ee\u5730\u5740\u4e3a\uff1a<\/p>\n<p>http:\/\/127.0.0.1\/cgi-bin\/project1.exe\/datasnap\/rest\/TServerMethods1\/BLToxy\/11\/12<\/p>\n<p>\u6ce8\u610f\u591a\u4e86\u4e2adatasnap\u8fd9\u4e2a\u56fa\u5b9a\u7684\u53c2\u6570\u3002<\/p>\n<p>\u5b9e\u73b0\u8fd9\u4e2a\u7684\u524d\u63d0\u662fApache\u8981\u914d\u7f6e\u597d\u652f\u6301CGI\u624d\u884c\uff0c\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u76f8\u5173\u4ee3\u7801\u4e3a\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;Directory &quot;E:\/www\/Apache2.2\/cgi-bin&quot;&gt;\r\n\r\n     AllowOverride None\r\n\r\n     Options None\r\n\r\n     Order allow,deny\r\n\r\n     Allow from all\r\n\r\n&lt;\/Directory&gt;\r\n\r\n\r\nAddHandler cgi-script .cgi .exe\r\n<\/pre>\n<p>\u6709\u4e86\u8fd9\u4e2a\u5c0f\u5c0f\u7684\u5b9e\u4f8b\uff0c\u5c31\u53ef\u4ee5\u53d1\u6325\u60f3\u50cf\u4e86\uff0c\u53ef\u4ee5\u505a\u8bb8\u591a\u7684WEB\u5e94\u7528\u7a0b\u5e8f\uff0c\u90fd\u6309\u7167\u8fd9\u79cd\u65b9\u5f0f\u505a\u3002\u7531\u4e8e\u5b9e\u73b0\u4e86Winodws\u5e94\u7528\u7a0b\u5e8f\u4e0eHTML\u7f51\u9875\u6216PHP\u7f51\u9875\u7684\u5206\u79bb\uff0c\u8fd9\u79cd\u591a\u5143\u5316\u7684\u5f00\u53d1\u65b9\u5f0f\u975e\u5e38\u65b9\u4fbf\u5b9e\u7528\uff0c\u800c\u4e14\u5b9e\u73b0\u4e86\u6570\u636e\u4e0e\u524d\u53f0\u9875\u9762\u7684\u5b8c\u5168\u5206\u79bb\uff0c\u66f4\u662f\u7f51\u9875\u8bbe\u8ba1\u7684\u5927\u52bf\u6240\u8d8b\u3002\u603b\u4e4b\uff0c\u4ee5\u540e\u6709\u5c3d\u91cf\u7528\u8fd9\u79cd\u6a21\u5f0f\u6765\u5f00\u53d1WEB\u5e94\u7528\u7a0b\u5e8f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5b9e\u7c7b\u4f3c\u4e8e\u8fd9\u79cd\u7684WEB\u5e94\u7528\u7a0b\u5e8f\u7528ASP.NET\u505a\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\uff0c\u56e0\u4e3aASP.NET\u6709\u5f3a\u5927\u7684C#\u8bed\u8a00\u4f5c\u4e3a\u540e\u76fe\u3002\u4f46\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-948","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=948"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/948\/revisions"}],"predecessor-version":[{"id":4566,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/948\/revisions\/4566"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}