<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_大名鼎鼎</title><subtitle type="text">大名鼎鼎个人信息管理系统</subtitle><id>http://feed.cnblogs.com/blog/u/5732/rss</id><updated>2011-05-20T16:15:36Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><generator>CNBlogs BlogServer</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/5732/rss"/><entry><id>http://www.cnblogs.com/Thinknet/articles/2052507.html</id><title type="text">多层数据库应用基于Delphi DataSnap方法调用的实现-----------------对象池技术</title><summary type="text">之前说到中间层通过向客户端暴露方法的方式提供服务，实现数据库数据的读取和更新。方法调用的方式，其潜在的意义，就是说中间层不保存客户端状态信息，就像WEB服务一样，客户端需要自己保存自己的状态信息。进一步说，就是中间层具体提供方法的业务对象实例，不是也不应该专属于某个客户端，它应该能够为不同的客户端调用提供服务。如果我们把业务对象实例放到对象池中集中存放，调用方法时随用随取，方法结束即放回池中。这样就可以实现业务对象实例服务于不同的客户端调用请求。更重要的是，利用对象池，能够最大化服务器各种资源的使用效率，而且对客户端的响应也更快了，因为业务对象实例早就创建好了，取来即用。其实，DataSnap</summary><published>2011-05-20T16:16:00Z</published><updated>2011-05-20T16:16:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2052507.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2052507.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: verdana, sans-serif; "&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;之前说到中间层通过向客户端暴露方法的方式提供服务，实现数据库数据的读取和更新。方法调用的方式，其潜在的意义，就是说中间层不保存客户端状态信息，就像WEB服务一样，客户端需要自己保存自己的状态信息。进一步说，就是中间层具体提供方法的业务对象实例，不是也不应该专属于某个客户端，它应该能够为不同的客户端调用提供服务。如果我们把业务对象实例放到对象池中集中存放，调用方法时随用随取，方法结束即放回池中。这样就可以实现业务对象实例服务于不同的客户端调用请求。更重要的是，利用对象池，能够最大化服务器各种资源的使用效率，而且对客户端的响应也更快了，因为业务对象实例早就创建好了，取来即用。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;其实，DataSnap构架，已经为我们的这种构想提供了现实支持。简单的说，就是改造工厂类（TDSServerClass），把LifeCycle属性改为Invocation方式；在OnCreateInstance事件中从对象池中取业务类对象实例；在OnDestroyInstance事件中把业务类对象实例放回对象池。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;...&lt;br /&gt;procedure TsmMainForm.dssMethodsCreateInstance(&lt;br /&gt;&amp;nbsp; DSCreateInstanceEventObject: TDSCreateInstanceEventObject);&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; DSCreateInstanceEventObject.ServerClassInstance := ServerMethodsPool.LockPoolObject;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;procedure TsmMainForm.dssMethodsDestroyInstance(&lt;br /&gt;&amp;nbsp; DSDestroyInstanceEventObject: TDSDestroyInstanceEventObject);&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; ServerMethodsPool.UnlockPoolObject(TPersistent(DSDestroyInstanceEventObject.ServerClassInstance));&lt;br /&gt;end;&lt;br /&gt;...&lt;br /&gt;当然，还有对象池类的创建和释放，也很简单，例如：&lt;br /&gt;procedure TsmMainForm.FormCreate(Sender: TObject);&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; ServerMethodsPool := ObjPoolMgr.TPoolManager.Create;&lt;br /&gt;&amp;nbsp; ServerMethodsPool.InstanceClass := uServerMethods.TPooledDM;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;procedure TsmMainForm.FormDestroy(Sender: TObject);&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; ServerMethodsPool.Free;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;下面就是如何实现对象池技术的问题。实现对象池并不复杂，另有两个问题需要注意：&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;１、多线程。中间层TDSTCPServerTransport对象提供的是多线程服务，允许同时有多个客户端请求。所以对象池类的实现，要考虑多线程情况下公共对象或变量的访问冲突问题。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;２、内存泄漏。业务类的基类，采用TDataModule、TComponent或者TPersistent都可以，但不要采用TDSServerModule，因为若采用此基类，TDSServerClass在Invocation方式下会产生内存泄漏。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;下面是对象池类最基本的实现代码：&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;&lt;br /&gt;unit ObjPoolMgr;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;interface&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;uses&lt;br /&gt;&amp;nbsp; Classes, SyncObjs, SysUtils, DSServer, DateUtils;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;type&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;PServerObject = ^TServerObject;&lt;br /&gt;&amp;nbsp; TServerObject = record&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ServerObject: TPersistent;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; InUse:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Boolean;&lt;br /&gt;&amp;nbsp; end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;TPoolManager = class&lt;br /&gt;&amp;nbsp; private&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FCriticalSection: TCriticalSection;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FServerObjects:&amp;nbsp;&amp;nbsp; TList;&lt;br /&gt;&amp;nbsp; private&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FInstanceClass: TPersistentClass;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function&amp;nbsp; CreateNewInstance: TPersistent; inline;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; procedure SetInstanceClass(const Value: TPersistentClass);&lt;br /&gt;&amp;nbsp; public&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; constructor Create;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; destructor Destroy; override;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //从对象池中取出一个业务类实例对象&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function&amp;nbsp; LockPoolObject: TPersistent;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //把一个业务类实例对象放回对象池中&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; procedure UnlockPoolObject(var Value: TPersistent);&lt;br /&gt;&amp;nbsp; public&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //指定放入池中的业务类。&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; property InstanceClass: TPersistentClass read FInstanceClass write SetInstanceClass;&lt;br /&gt;&amp;nbsp; end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;implementation&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;constructor TPoolManager.Create;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; FServerObjects := TList.Create;&lt;br /&gt;&amp;nbsp; FCriticalSection := TCriticalSection.Create;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;destructor TPoolManager.Destroy;&lt;br /&gt;var&lt;br /&gt;&amp;nbsp; I: Integer;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; for I := 0 to FServerObjects.Count - 1 do&lt;br /&gt;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PServerObject(FServerObjects[i]).ServerObject.Free;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FreeMem(PServerObject(FServerObjects[i]));&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp; FServerObjects.Free;&lt;br /&gt;&amp;nbsp; FCriticalSection.Free;&lt;br /&gt;&amp;nbsp; inherited Destroy;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;procedure TPoolManager.SetInstanceClass(const Value: TPersistentClass);&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; FInstanceClass := Value;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;function TPoolManager.CreateNewInstance: TPersistent;&lt;br /&gt;var&lt;br /&gt;&amp;nbsp; p: PServerObject;&lt;br /&gt;&amp;nbsp; Component: TComponent;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; if not Assigned(FInstanceClass) then Raise Exception.Create('Not specify class of instance!');&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;FCriticalSection.Enter;&lt;br /&gt;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if FInstanceClass.InheritsFrom(TComponent) then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Component := FInstanceClass.NewInstance as TComponent;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Component.Create(nil);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result := Component;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result := FInstanceClass.Create;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;New(p);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.ServerObject := Result;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.InUse&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; := True;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FServerObjects.Add(p);&lt;br /&gt;&amp;nbsp; finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FCriticalSection.Leave;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;function TPoolManager.LockPoolObject: TPersistent;&lt;br /&gt;var&lt;br /&gt;&amp;nbsp; i: Integer;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; FCriticalSection.Enter;&lt;br /&gt;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i := 0 to FServerObjects.Count - 1 do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not PServerObject(FServerObjects[I]).InUse then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PServerObject(FServerObjects[I]).InUse := True;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result := PServerObject(FServerObjects[i]).ServerObject;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp; finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FCriticalSection.Leave;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp; Result := CreateNewInstance;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;procedure TPoolManager.UnlockPoolObject(var Value: TPersistent);&lt;br /&gt;var&lt;br /&gt;&amp;nbsp; i: Integer;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; FCriticalSection.Enter;&lt;br /&gt;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i := 0 to FServerObjects.Count - 1 do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Value = PServerObject(FServerObjects[i]).ServerObject then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PServerObject(FServerObjects[i]).InUse := False;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value := nil;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp; finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FCriticalSection.Leave;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;end;&lt;br /&gt;...&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;&lt;br /&gt;上面的基本实现稍加修改，就可以完善更多的功能，比如设定实例数上限、定时清除超过某个时间未被使用的实例、查询当前池中对象实例数量等。&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2052507.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2052507.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/2052366.html</id><title type="text">利用DataSnap的回调功能在客户端显示服务器方法的执行进度</title><summary type="text">如果DataSnap服务器方法的执行时间比较长，这时候可能需要在客户端用进度条显示当前服务器方法的执行进度。要实现这种需求，现在可以利用DataSnap的回调功能，此功能是从Delphi 2010版本开始被引入的。要实现回调，服务器方法需要暴露给客户端一个或多个类型为TDBXCallback的参数。例如：...{$METHODINFO ON} TServerMethods1 = class(TComponent) private { Private declarations } public { Public declarations } function LongTimeRunFunc(In</summary><published>2011-05-20T14:15:00Z</published><updated>2011-05-20T14:15:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2052366.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2052366.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: verdana, sans-serif; "&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;如果DataSnap服务器方法的执行时间比较长，这时候可能需要在客户端用进度条显示当前服务器方法的执行进度。要实现这种需求，现在可以利用DataSnap的回调功能，此功能是从Delphi 2010版本开始被引入的。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;要实现回调，服务器方法需要暴露给客户端一个或多个类型为TDBXCallback的参数。例如：&lt;br /&gt;...&lt;br /&gt;{$METHODINFO ON}&lt;br /&gt;&amp;nbsp; TServerMethods1 = class(TComponent)&lt;br /&gt;&amp;nbsp; private&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { Private declarations }&lt;br /&gt;&amp;nbsp; public&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { Public declarations }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function LongTimeRunFunc(InitCallback, ProgCallback: TDBXCallback): boolean;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;{$METHODINFO OFF}&lt;br /&gt;...&lt;br /&gt;LongTimeRunFunc方法带有两个回调参数，InitCallback用来初始化客户端TProgressBar的设置，ProgCallback根据当前方法的执行进度，设置客户端TProgressBar.Position的属性。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;&lt;br /&gt;implementation&lt;br /&gt;...&lt;br /&gt;function TServerMethods1.LongTimeRunFunc(InitCallback, ProgCallback: TDBXCallback): boolean;&lt;br /&gt;var&lt;br /&gt;&amp;nbsp; Max: Integer;&lt;br /&gt;&amp;nbsp; I: Integer;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; Max := Random(120) + 1;&lt;br /&gt;&amp;nbsp; InitCallback.Execute(TJSONNumber.Create(Max)).Free;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;for I := 0 to Max do&lt;br /&gt;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProgCallback.Execute(TJSONNumber.Create(I)).Free;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sleep(1000);&lt;br /&gt;&amp;nbsp; end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;Result := True;&lt;br /&gt;end;&lt;br /&gt;...&lt;br /&gt;LongTimeRunFunc函数生成一个随机数，表示将执行的秒数。InitCallback和ProgCallback在execute时，将等待客户端执行完毕才继续。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;&lt;br /&gt;而客户端这边的代码，需要申明两个继承自TDBXCallback（抽象类）的类，并且重载Execute方法，&lt;br /&gt;...&lt;br /&gt;&amp;nbsp; TInitCallback = class(TDBXCallback)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function Execute(const Arg: TJSONValue): TJSONValue; override;&lt;br /&gt;&amp;nbsp; end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;TProgCallback = class(TDBXCallback)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function Execute(const Arg: TJSONValue): TJSONValue; override;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;...&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;&lt;br /&gt;implementation&lt;br /&gt;...&lt;br /&gt;function TProgCallback.Execute(const Arg: TJSONValue): TJSONValue;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; with Form2 do&lt;br /&gt;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProgressBar1.Position := TJSONNumber(Arg).AsInt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; btnStart.Enabled := (TJSONNumber(Arg).AsInt = ProgressBar1.Max);&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp; //刷新屏幕&lt;br /&gt;&amp;nbsp; Application.ProcessMessages;&lt;br /&gt;&amp;nbsp; Result := TJSONNull.Create;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;function TInitCallback.Execute(const Arg: TJSONValue): TJSONValue;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; with Form2 do&lt;br /&gt;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProgressBar1.Max := TJSONNumber(Arg).AsInt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProgressBar1.Step := 5;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Edit1.Text := '总时长：' + TJSONNumber(Arg).ToString + '秒';&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; btnStart.Enabled := False;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;&amp;nbsp; Result := TJSONNull.Create;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;procedure TForm2.btnStartClick(Sender: TObject);&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; ClientModule1.ServerMethods1Client.LongTimeRunFunc(InitCallback, ProgCallback);&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;Initialization&lt;br /&gt;&amp;nbsp; InitCallback := TInitCallback.Create;&lt;br /&gt;&amp;nbsp; ProgCallback := TProgCallback.Create;&lt;br /&gt;...&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2052366.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2052366.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/2052363.html</id><title type="text">利用DataSnap进行数据流(TStream)的传递</title><summary type="text">DataSnap服务器可以通过方法调用向客户端返回数据流，当然，也可以从客户端向服务器上传数据流，都是通过方法调用的方式来实现的。下面以一个简单的例子来演示。服务器端实现：{$METHODINFO ON} TFUService = class(TPersistent) public function ReplaceFile(FileName: string; FileStream: TStream): Integer; function GetFile(schema, FileName: string): TStream; end;{$METHODINFO OFF}//GetFile方法向客户</summary><published>2011-05-20T14:14:00Z</published><updated>2011-05-20T14:14:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2052363.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2052363.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: verdana, sans-serif; "&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;DataSnap服务器可以通过方法调用向客户端返回数据流，当然，也可以从客户端向服务器上传数据流，都是通过方法调用的方式来实现的。下面以一个简单的例子来演示。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;服务器端实现：&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;{$METHODINFO ON}&lt;br /&gt;&amp;nbsp; TFUService = class(TPersistent)&lt;br /&gt;&amp;nbsp; public&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function ReplaceFile(FileName: string; FileStream: TStream): Integer;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; function GetFile(schema, FileName: string): TStream;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;{$METHODINFO OFF}&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;//GetFile方法向客户端返回指定名称的文件数据流。ReplaceFile接收来自客户端的文件流，并替换服务器端的文件。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;const&lt;br /&gt;&amp;nbsp; BufferSize = 102400; // 100 KB&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;implementation&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;function TFUService.ReplaceFile(FileName: string; FileStream: TStream): Integer;&lt;br /&gt;var&lt;br /&gt;&amp;nbsp; fStream: TFilestream;&lt;br /&gt;&amp;nbsp; BytesReadCount: Integer;&lt;br /&gt;&amp;nbsp; Buffer: TBytes;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; Result := 0;&lt;br /&gt;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if SysUtils.FileExists(FileName) then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fStream := TFilestream.Create(FileName, fmOpenWrite or fmShareDenyNone)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else fStream := TFilestream.Create(FileName, fmCreate);&lt;br /&gt;&amp;nbsp; except on E: Exception do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit(-1);&lt;br /&gt;&amp;nbsp; end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetLength(Buffer, BufferSize);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fStream.Position := 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; repeat&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BytesReadCount := FileStream.Read(Buffer[0], BufferSize);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if BytesReadCount &amp;gt; 0 then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fStream.Write(Buffer[0], BytesReadCount);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; until BytesReadCount &amp;lt; BufferSize;&lt;br /&gt;&amp;nbsp; finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fStream.Free;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;end;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;function TFUService.GetFile(FileName: string): TStream;&lt;br /&gt;begin&lt;br /&gt;&amp;nbsp; Result := nil;&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;if SysUtils.FileExists(FileName) then&lt;br /&gt;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result := TFileStream.Create(FileName, fmOpenRead + fmShareDenyWrite);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Result &amp;lt;&amp;gt; nil then Result.Position := 0;&lt;br /&gt;&amp;nbsp; end;&lt;br /&gt;end;&lt;br /&gt;//Result.Position := 0;这一句很关键，返回数据流之前，一定要定位到流的开始处。&lt;/p&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "&gt;客户端代码的实现，跟上述两个方法的实现类似，只是方向相反而已。&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2052363.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2052363.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/2051427.html</id><title type="text">DataSnap 2009 系列之二 （方法篇）</title><summary type="text">在过去客户端要调用远程服务器的方法需要通过在TLB里添加接口并且在服务器对象中实现在DataSnap 2009中调用远程服务器的方法是基于delphi的RTTI机制的想要一个类允许被远程调用需要做以下两点1.把该类和DSServerClass连接在一起procedureTMainForm.DSServerClassGetClass(DSServerClass:TDSServerClass;varPersistentClass:TPersistentClass);beginPersistentClass:=TSM;end;DSServerClass的OnGetClass就是用于完成此任务的注意：</summary><published>2011-05-19T12:53:00Z</published><updated>2011-05-19T12:53:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2051427.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2051427.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: Arial; line-height: 25px; "&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在过去客户端要调用远程服务器的方法需要通过在TLB里添加接口并且在服务器对象中实现&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在DataSnap 2009中调用远程服务器的方法是基于delphi的RTTI机制的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;想要一个类允许被远程调用需要做以下两点&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;1.把该类和DSServerClass连接在一起&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DSServerClassGetClass(DSServerClass:&amp;nbsp;TDSServerClass;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;PersistentClass:&amp;nbsp;TPersistentClass);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;PersistentClass&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TSM;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DSServerClass的OnGetClass就是用于完成此任务的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;注意：DSServerClass必须设置要导出的类 否则会出现SOnGetClassNotSet的异常信息&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;2.该类必须使用$MethodInfo编译指令生成详细的RTTI信息&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #008000; "&gt;{&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008000; "&gt;$MethodInfo&amp;nbsp;ON&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008000; "&gt;}&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;TDSServerModule&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;class(TProviderDataModule)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008000; "&gt;{&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008000; "&gt;$MethodInfo&amp;nbsp;OFF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008000; "&gt;}&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;我们查看TDSServerModule的定义发现已经完成了该步骤&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;所以我们使用向导添加的ServerModule 不需要再手动添加$MethodInfo开关&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;同样我们也可以不用继承自TDSServerModule来实现我们的ServerClass&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;只要从TPersistent继承一个类 并且用{$MethodInfo ON}和{$MethodInfo OFF}包围就可以输出成员函数到客户端&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;注意：要输出的成员函数必须声明为public&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;客户端调用可以使用两种方法&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;1.使用SqlServerMethod组件&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;通过设置其ServerMethodName属性来进行远程调用 使用Params属性来传递参数和结果值&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;2.使用本地代理类&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;选中SQLConnection组件，在右键菜单中单击Generate Datasnap client classe 生成代理类单元。&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;下面我们通过一个简单的DEMO来展示DataSnap 2009的远程方法调用&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;我们在服务端定义了4个输出的成员函数&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;TSM&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;class(TDSServerModule)&lt;br /&gt;public&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Hello(Message:&amp;nbsp;String):&amp;nbsp;String;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;VariantMethod(Value:&amp;nbsp;OleVariant):&amp;nbsp;OleVariant;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;StreamMethod:&amp;nbsp;TStream;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;VarOutMethod(out&amp;nbsp;OutParam:&amp;nbsp;OleVariant;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;VarParam:&amp;nbsp;OleVariant):&amp;nbsp;string;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;br /&gt;由于在DataSnap内部是使用TDBXValue来管理参数列表的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;所以使用string等delphi语言自带的类型将会进行相应的映射&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;使用TDBXValue也是效率最高的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;以下是可以作为参数使用的TDBXValue列表&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;TDBXWideStringValue&lt;br /&gt;TDBXAnsiStringValue&lt;br /&gt;TDBXInt16Value&lt;br /&gt;TDBXInt32Value&lt;br /&gt;TDBXInt64Value&lt;br /&gt;TDBXSingleValue&lt;br /&gt;TDBXDoubleValue&lt;br /&gt;TDBXBcdValue&lt;br /&gt;TDBXTimeValue&lt;br /&gt;TDBXDateValue&lt;br /&gt;TDBXTimeStampValue&lt;br /&gt;TDBXBooleanValue&lt;br /&gt;TDBXReaderValue&lt;br /&gt;TDBXStreamValue&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;我们分别使用SqlServerMethod和代理类完成对服务端Hello方法的调用&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;SqlServerMethod.ServerMethodName&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;TSM.Hello&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;SqlServerMethod.Params[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;].AsString&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Name.Text;&lt;br /&gt;SqlServerMethod.ExecuteMethod;&lt;br /&gt;Memo.Lines.Add(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;Use&amp;nbsp;SqlServerMethod:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;+&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SqlServerMethod.Params[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;1&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;].AsString);&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;br /&gt;这里参数使用了索引值进行访问 传递的顺序是从左到右添加到Params列表 返回值是在列表的最后一个位置&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;同样也可以使用ParamByName(参数名称).Value的形式传递参数 返回值的名称默认是'ReturnParameter'&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;使用代理类调用的方法和调用本地方法区别不大 因为远程调用的具体过程已经被代理类封装&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;可以看下代理类中生成的Hello方法&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TSMClient.Hello(Message:&amp;nbsp;string):&amp;nbsp;string;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FHelloCommand&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;nil&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FHelloCommand&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FDBXConnection.CreateCommand;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FHelloCommand.CommandType&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TDBXCommandTypes.DSServerMethod;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FHelloCommand.Text&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;TSM.Hello&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FHelloCommand.Prepare;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;FHelloCommand.Parameters[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;].Value.SetWideString(Message);&lt;br /&gt;&amp;nbsp;&amp;nbsp;FHelloCommand.ExecuteUpdate;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Result&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FHelloCommand.Parameters[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;1&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;].Value.GetWideString;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;br /&gt;我们看到代理类使用了比SqlServerMethod更低级的DBXCommand进行了封装 以更友好的方式给我们使用&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;with&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TSMClient.Create(SQLConnection.DBXConnection)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;do&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Memo.Lines.Add(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;Use&amp;nbsp;Proxy:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;+&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Hello(Name.Text));&lt;br /&gt;&amp;nbsp;&amp;nbsp;Free;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;下面我们用TStream返回一个结构体并且在客户端读出&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;服务端部分&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;TName&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;packed&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;record&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;FirstName:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;array&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;..&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;99&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;of&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Char;&lt;br /&gt;&amp;nbsp;&amp;nbsp;LastName:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;array&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;..&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;99&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;of&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Char;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TSM.StreamMethod:&amp;nbsp;TStream;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Name:&amp;nbsp;TName;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Name.FirstName&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;爱新觉罗&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Name.LastName&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;玄烨&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Result&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMemoryStream.Create;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Result.Seek(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;,&amp;nbsp;soFromBeginning);&lt;br /&gt;&amp;nbsp;&amp;nbsp;Result.Write(Name,&amp;nbsp;SizeOf(TName));&lt;br /&gt;&amp;nbsp;&amp;nbsp;Result.Seek(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;,&amp;nbsp;soFromBeginning);&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;返回到客户端的数据是从position开始的&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: red; "&gt;注意：写完数据以后需要定位到头部 否则客户端得到的数据长度为0&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;br /&gt;客户端部分&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.StreamTestClick(Sender:&amp;nbsp;TObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Name:&amp;nbsp;TName;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SQLConnection.Connected&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;with&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TSMClient.Create(SQLConnection.DBXConnection)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;do&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StreamMethod.ReadBuffer(Name,&amp;nbsp;SizeOf(TName));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Memo.Lines.Add(Format(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;(StreamMethod)FirstName:&amp;nbsp;%s&amp;nbsp;LastName:&amp;nbsp;%s&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;,[Name.FirstName,&amp;nbsp;Name.LastName]));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Free;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;最后一个函数演示了使用var和out关键字来返回参数&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;以下是可以使用这两个关键字的标量值类型&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;boolean&lt;br /&gt;SmallInt&lt;br /&gt;Integer&lt;br /&gt;Int64&lt;br /&gt;Single&lt;br /&gt;Double&lt;br /&gt;AnsiString&lt;br /&gt;String&lt;br /&gt;TDBXTime&lt;br /&gt;TDBXDate&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;再加上其他的参数类型&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;TStream&lt;br /&gt;TDataSet&lt;br /&gt;TParams&lt;br /&gt;TDBXReader&lt;br /&gt;TDBXConnection&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;但是在实际测试过程中发现在使用string类型做out和var的参数时 无法使用&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;跟踪发现源码中ansistring和string的相关代码已经被注释掉 估计是有BUG存在所以不支持 以后应该可以修复&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;以下摘自DSReflect单元的procedure TDSMethodValues.AssignParameterValues(Parameters: TDBXParameterArray);&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TDBXDataTypes.AnsiStringType:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;s&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value.GetAnsiString;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetMem(p,&amp;nbsp;SizeOf(Pointer));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UniqueString(s);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PPointer(p)^&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Pointer(s);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FMethodValues[i]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;MakeRefVar(varString,&amp;nbsp;p);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TDBXDataTypes.BytesType:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SetLength(bytes,&amp;nbsp;value.GetValueSize);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Value.GetBytes(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;,&amp;nbsp;bytes,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;,&amp;nbsp;Length(Bytes));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetMem(p,&amp;nbsp;Length(bytes));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Move(bytes[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;],&amp;nbsp;p^,&amp;nbsp;Length(bytes));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FMethodValues[i]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;MakeRefVar(varByte&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;or&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;varArray,&amp;nbsp;p);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TDBXDataTypes.WideStringType:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;w&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value.GetWideString;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetMem(p,&amp;nbsp;SizeOf(Pointer));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UniqueString(w);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PPointer(p)^&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Pointer(w);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FMethodValues[i]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;MakeRefVar(varUString,&amp;nbsp;p);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;贴上效果图&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/gfkz/DataSnapDemo2.jpg" width="807" height="460" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-style: initial; border-color: initial; " /&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;附上DEMO源码&amp;nbsp;&lt;a title="DataSnapDemo_2.rar" href="http://files.cnblogs.com/gfkz/DataSnapDemo_2.rar" style="color: #1d58d1; text-decoration: none; "&gt;DataSnapDemo_2.rar&lt;/a&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2051427.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2051427.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/2051428.html</id><title type="text">DataSnap 2009 系列之三 （生命周期篇）</title><summary type="text">DataSnap 2009 系列之三 （生命周期篇）DataSnap 2009的服务器对象的生命周期依赖于DSServerClass组件的设置当DSServer启动时从DSServerClass组件读取LifeCycle属性的值注意：LifeCycle的值由于在启动时就已经读取 启动后再修改LifeCycle的值将没有任何效果LifeCycle属性的值可以是以下三种字符串之一1.Session该选项为默认设置每个连接都会建立一个独立的服务器对象为客户端提供服务，服务器对象在连接关闭后释放因此多个客户端访问的是不同的服务器对象，是线程安全的2.Invocation对于每次服务端方法调用建立一个独</summary><published>2011-05-19T12:53:00Z</published><updated>2011-05-19T12:53:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2051428.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2051428.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: Arial; line-height: 25px; "&gt;&lt;p&gt;&lt;strong&gt;&lt;a id="homepage1_HomePageDays_DaysList_DayItem_2_DayList_2_TitleUrl_0" href="http://www.cnblogs.com/gfkz/archive/2009/03/24/1420652.html" style="color: #223355; text-decoration: none; "&gt;DataSnap 2009 系列之三 （生命周期篇）&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DataSnap 2009的服务器对象的生命周期依赖于DSServerClass组件的设置&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;当DSServer启动时从DSServerClass组件读取LifeCycle属性的值&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: red; "&gt;注意：LifeCycle的值由于在启动时就已经读取 启动后再修改LifeCycle的值将没有任何效果&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;LifeCycle属性的值可以是以下三种字符串之一&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;1.Session&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;该选项为默认设置&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;每个连接都会建立一个独立的服务器对象为客户端提供服务，服务器对象在连接关闭后释放&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;因此多个客户端访问的是不同的服务器对象，是线程安全的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;2.Invocation&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;对于每次服务端方法调用建立一个独立的服务器对象为客户端提供服务，服务器对象在调用结束后释放&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;这个同样也是线程安全的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;但是每次调用都创建和释放服务器对象对于频繁调用的系统影响很大，如果把服务端对象用对象池管理配合此种方式将是个非常不错的解决方案&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;3.Server&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;所有的客户端使用同一个服务端对象，也就是该对象是单例的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;需要开发人员自己来进行同步的控制，不是线程安全的&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在服务端对象创建和释放时将触发DSServerClass的两个重要的事件OnCreateInstance和OnDestroyInstance&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在这里我们可以使用自定义创建和释放服务器对象 同样我们可以用于服务端对象池&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;下面我们把上一次的DEMO稍微改动下来观察下服务端对象的生命周期&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;我们先将DSServer组件的AutoStart设置为False 然后拖上两个Button分别完成Start和Stop的调用&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.StartClick(Sender:&amp;nbsp;TObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;DSServer.Start;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.StopClick(Sender:&amp;nbsp;TObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;DSServer.Stop;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在OnGetClass中记录服务启动时使用的生命周期&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DSServerClassGetClass(DSServerClass:&amp;nbsp;TDSServerClass;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;PersistentClass:&amp;nbsp;TPersistentClass);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;DSServerClass.LifeCycle&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;LifeCycles.Items.Strings[LifeCycles.ItemIndex];&lt;br /&gt;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;生命周期：&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;+&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;DSServerClass.LifeCycle);&lt;br /&gt;&amp;nbsp;&amp;nbsp;PersistentClass&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TSM;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;LifeCycles是一个TRadioGroup存放了生命周期使用的三个字符串&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;最后在OnCreateInstance和OnDestroyInstance事件中记录服务器对象的创建和释放&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DSServerClassCreateInstance(&lt;br /&gt;&amp;nbsp;&amp;nbsp;DSCreateInstanceEventObject:&amp;nbsp;TDSCreateInstanceEventObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;服务端对象创建&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DSServerClassDestroyInstance(&lt;br /&gt;&amp;nbsp;&amp;nbsp;DSDestroyInstanceEventObject:&amp;nbsp;TDSDestroyInstanceEventObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;服务端对象释放&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;DSDestroyInstanceEventObject.ServerClassInstance.Free;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;效果图&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/gfkz/DataSnapDemo3.jpg" width="625" height="460" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-style: initial; border-color: initial; " /&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;通过Demo我们可以明显的看出三种生命周期的区别 注意切换生命周期需要先停止服务器再启动&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;但是在我们使用Invocation的时候 会造成内存泄露&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;打开服务端的ReportMemoryLeaksOnShutdown 调用了两次方法后关闭服务端可以看到如下提示&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/gfkz/DataSnapLeak.jpg" width="537" height="160" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-style: initial; border-color: initial; " /&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;可以看到服务端对象并没有释放&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;这里需要我们通过在OnDestroyInstance手动释放&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DSDestroyInstanceEventObject.ServerClassInstance.Free;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;但是我们会发现内存泄露依然存在TDSProviderDataModuleAdapter依然没有释放&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;这是由于DataSnap2009中继承自TProviderDataModule的类都使用了适配器模式来支持旧的IAppServer接口&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在服务端对象创建的过程TDSServerClass.CreateInstance中我们可以看到&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;(Instance&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;lt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;nil&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;and&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Instance.InheritsFrom(TProviderDataModule)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;CreateInstanceEventObject.ServerClassInstance&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TDSProviderDataModuleAdapter.Create(Instance);&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;因此在服务端释放的TDSServerClass.DestroyInstance中需要释放TDSProviderDataModuleAdapter对象&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;DestroyInstanceEventObject.ServerClassInstance&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;is&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TDSProviderDataModuleAdapter&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Adapter&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;DestroyInstanceEventObject.ServerClassInstance&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;as&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TDSProviderDataModuleAdapter;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DestroyInstanceEventObject.ServerClassInstance&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Adapter.FProviderDataModule;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Adapter.FProviderDataModule&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;nil&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;else&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Adapter&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;nil&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;当使用Invocation生命周期时 传递的ServerClassInstance并不是TDSProviderDataModuleAdapter的对象&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;所以尽管我们手动释放了我们的服务端对象 适配器对象任然造成了内存泄露&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;附上DEMO源码&amp;nbsp;&lt;a title="DataSnapDemo_3.rar" href="http://files.cnblogs.com/gfkz/DataSnapDemo_3.rar" style="color: #1d58d1; text-decoration: none; "&gt;DataSnapDemo_3.rar&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2051428.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2051428.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/2051426.html</id><title type="text">DataSnap 2009 系列之一 （连接篇）</title><summary type="text">Delphi 的MIDAS出来了这么多年终于有改进的版本了COM-FREE的DataSnap 2009真是清爽了很多DataSnap 2009 除了不支持回调和Intercept组件以外 其它的该有的都有了 而且还有很多强大的特性第一篇就先写点DataSnap 2009连接方面可能要用到的东西以后再继续写写关于生命周期的管理 对象池的应用 以及远程管理 远程方法调用等方面的东西吧。首先 建立个DataSnap 2009的服务器工程一共用到三个组件DSServer 服务配置组件 用于绑定其它的组件DSServerClass 可以看作是一个类的工厂 用于导出需要远程调用的服务端模块DSTCPSer</summary><published>2011-05-19T12:52:00Z</published><updated>2011-05-19T12:52:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2051426.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2051426.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: Arial; line-height: 25px; "&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;Delphi 的MIDAS出来了这么多年终于有改进的版本了&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;COM-FREE的DataSnap 2009真是清爽了很多&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DataSnap 2009 除了不支持回调和Intercept组件以外 其它的该有的都有了 而且还有很多强大的特性&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;第一篇就先写点DataSnap 2009连接方面可能要用到的东西&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;以后再继续写写关于生命周期的管理 对象池的应用 以及远程管理 远程方法调用等方面的东西吧。&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;首先 建立个DataSnap 2009的服务器工程&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;一共用到三个组件&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DSServer&amp;nbsp; 服务配置组件 用于绑定其它的组件&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DSServerClass 可以看作是一个类的工厂 用于导出需要远程调用的服务端模块&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DSTCPServerTransport 传输组件 这里使用的是indy的tcpserver&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;将DSServerClass和DSTCPServerTransport的Server设置成DSServer就可以了&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;客户端连接和断开连接时会触发DSServer的两个事件OnConnect和OnDisConnect&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;参数为TDSConnectEventObject&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;我们看下该类的定义&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;TDSConnectEventObject&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;class&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;(TDSEventObject)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;public&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;constructor&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Create(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ADbxContext:&amp;nbsp;TDBXContext;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;AServer:&amp;nbsp;TDSCustomServer;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ATransport:&amp;nbsp;TDSServerTransport;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;AChannelInfo:&amp;nbsp;TDBXChannelInfo;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ADbxConnection:&amp;nbsp;TDBXConnection;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;AConnectProperties:&amp;nbsp;TDBXProperties);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;private&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;FConnectProperties:&amp;nbsp;TDBXProperties;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;FChannelInfo:&amp;nbsp;TDBXChannelInfo;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;public&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ConnectProperties:&amp;nbsp;TDBXProperties&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FConnectProperties&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FConnectProperties;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ChannelInfo:&amp;nbsp;TDBXChannelInfo&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FChannelInfo;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;10&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;我们可以看到其中包含了两个属性ConnectProperties和ChannelInfo&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;ConnectProperties包含了客户端连接所传递的参数 Params 也就是一个TStrings的内容&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;ChannelInfo里面有个很重的属性就是它的ID 其实是TIdTCPConnection对象的ID 所以我们可以直接强制转换成TIdTCPConnection&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;然后 建立个DataSnap 2009的客户端工程&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;由于使用的DbExpress框架 客户端连接用的是TSQLConnection组件&amp;nbsp;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;只要把Driver设置成Datasnap即可&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;连接的服务器地址通过HostName和Port来进行设定&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;下面我们就实现个简单的DEMO 客户端通过用户名和密码连接服务端 如果密码不争取服务端则断开连接&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;客户端主要函数&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.ConnectClick(Sender:&amp;nbsp;TObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SQLConnection.Params.Values[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;User_Name&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;UserName.Text;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SQLConnection.Params.Values[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;PassWord&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Password.Text;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;try&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLConnection.Open;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Connect.Enabled&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;False;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DisConnect.Enabled&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;True;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;except&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;10&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowMessage(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;连接服务器失败!&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;11&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;12&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;13&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;14&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DisConnectClick(Sender:&amp;nbsp;TObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;15&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;16&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SQLConnection.Close;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;17&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;Connect.Enabled&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;True;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;18&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;DisConnect.Enabled&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;False;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;19&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;服务端主要函数&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DSServerConnect(DSConnectEventObject:&amp;nbsp;TDSConnectEventObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SRemoteConnected&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;远程客户端连接&amp;nbsp;%s:%d&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SUserNameAndPassword&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;用户名:&amp;nbsp;%s&amp;nbsp;密码:&amp;nbsp;%s&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SAuthSuccess&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;用户名密码认证成功&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SAuthFailed&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;用户名密码认证失败&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;Conn:&amp;nbsp;TIdTCPConnection;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;10&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;Conn&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TIdTCPConnection(DSConnectEventObject.ChannelInfo.Id);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;11&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;Format(SRemoteConnected,&amp;nbsp;[Conn.Socket.Binding.PeerIP,&amp;nbsp;Conn.Socket.Binding.PeerPort]));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;12&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;with&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;DSConnectEventObject.ConnectProperties&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;do&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;13&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;14&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;Format(SUserNameAndPassword,&amp;nbsp;[Values[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;User_Name&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;],&amp;nbsp;Values[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;PassWord&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]]));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;15&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;(Values[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;User_Name&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;Admin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;and&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;(Values[&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;PassWord&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;]&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;123456&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;16&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;SAuthSuccess)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;17&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;else&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;18&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;19&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;SAuthFailed);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;20&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Conn.Disconnect;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;21&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;22&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;23&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;24&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;25&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TMainForm.DSServerDisconnect(DSConnectEventObject:&amp;nbsp;TDSConnectEventObject);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;26&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;27&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;SRemoteDisConnected&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;远程客户端断开连接&amp;nbsp;%s:%d&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;28&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;var&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;29&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;Conn:&amp;nbsp;TIdTCPConnection;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;30&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;31&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;Conn&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TIdTCPConnection(DSConnectEventObject.ChannelInfo.Id);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;32&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;&amp;nbsp;LogMessage(Memo,&amp;nbsp;Format(SRemoteDisConnected,&amp;nbsp;[Conn.Socket.Binding.PeerIP,&amp;nbsp;Conn.Socket.Binding.PeerPort]));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #008080; "&gt;33&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: red; "&gt;&lt;span style="color: #ff0000; "&gt;&lt;span style="color: #ff0000; "&gt;注意：OnConnect事件中还可以使用另外一种方式拒绝客户端连接&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: #ff0000; "&gt;&lt;span style="color: #ff0000; "&gt;&lt;span style="color: red; "&gt;在代码中抛出个异常即可 在客户端会捕捉到一个TDBXError的异常 显示'Remote error '&amp;nbsp;加上异常显示的消息。&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;效果图如下：&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/gfkz/DataSnapDemo.jpg" width="623" height="459" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-style: initial; border-color: initial; " /&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;附上DEMO源码&amp;nbsp;&lt;a href="http://www.cnblogs.com/gfkz/admin/DataSnapDemo_1.rar" style="color: #1d58d1; text-decoration: none; "&gt;DataSnapDemo_1.rar&lt;/a&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2051426.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2051426.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/2051423.html</id><title type="text">DataSnap 2009 客户端扩展</title><summary type="text">DataSnap 2009的客户端采用了原始的TClientSocket组件实现了通讯层 即简单效率也不错但是如果我们想要设置连接超时怎么办？想要设置代理服务器又该怎么办呢？能不能利用我们常用的网络控件(indy ics synapse...)来替代呢？在这里我基于synapse控件实现了一个自己的DataSnap客户端驱动注:synapase是一套比较不错的开源的第三方控件 这里我们要使用它的TCP控件来扩展支持代理服务器的使用 synapse 官方网址http://www.synapse.ararat.cz/doku.php synapse svn地址https://synalist.sv</summary><published>2011-05-19T12:51:00Z</published><updated>2011-05-19T12:51:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/2051423.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/2051423.html"/><content type="html">&lt;div&gt;&lt;span style="font-family: Arial; line-height: 25px; font-size: 21px;"&gt;&lt;strong&gt;&lt;div&gt;&lt;span style="color: #000000; font-weight: normal; font-size: 14px; "&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;DataSnap 2009的客户端采用了原始的TClientSocket组件实现了通讯层 即简单效率也不错&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;但是如果我们想要设置连接超时怎么办？想要设置代理服务器又该怎么办呢？能不能利用我们常用的网络控件(indy ics synapse...)来替代呢？&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;在这里我基于synapse控件实现了一个自己的DataSnap客户端驱动&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: red; "&gt;注:&amp;nbsp;&lt;/span&gt;&lt;span style="color: red; "&gt;synapase是一套比较不错的开源的第三方控件 这里我们要使用它的TCP控件来扩展支持代理服务器的使用&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: red; "&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; synapse 官方网址&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.synapse.ararat.cz/doku.php" target="_blank" style="color: #1d58d1; text-decoration: none; "&gt;&lt;span style="color: red; "&gt;http://www.synapse.ararat.cz/doku.php&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;synapse svn地址&amp;nbsp;&lt;a href="https://synalist.svn.sourceforge.net/svnroot/synalist/trunk" target="_blank" style="color: #1d58d1; text-decoration: none; "&gt;&lt;span style="color: red; "&gt;https://synalist.svn.sourceforge.net/svnroot/synalist/trunk&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;首先我们必须注册一个新的驱动&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;客户端驱动定义&lt;br /&gt;TCfSynaTCPDatasnapDriver&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;class&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;(TDBXClientDriver)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;protected&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;CreateChannel:&amp;nbsp;TDbxChannel;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;public&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;constructor&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Create(DriverDef:&amp;nbsp;TDBXDriverDef);&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;驱动名称&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SDriverName&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;CfSynaTCPDataSnap&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;单元初始化时注册驱动&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;initialization&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;TDBXDriverRegistry.RegisterDriverClass(SDriverName,&amp;nbsp;TCfSynaTCPDatasnapDriver);&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: #000000; "&gt;TDBXClientDriver的CreateChannel方法默认创建的是TDBXSocketChannel 所以我们要在我们的类中覆盖它并且创建一个自己的Channel&lt;/span&gt;&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Synapse&amp;nbsp;实现的TCP通道&lt;br /&gt;TCfSynaTCPChannel&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;class&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;(TDBXChannel)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;private&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;FTcpClient:&amp;nbsp;TTCPBlockSocket; // Synapse的TCP控件&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;protected&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetChannelInfo:&amp;nbsp;TDBXChannelInfo;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;public&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;destructor&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Destroy;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Open;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Close;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Read(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Buffer:&amp;nbsp;TBytes;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Offset:&amp;nbsp;Integer;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Count:&amp;nbsp;Integer):&amp;nbsp;Integer;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Write(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Buffer:&amp;nbsp;TBytes;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Offset:&amp;nbsp;Integer;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Count:&amp;nbsp;Integer):&amp;nbsp;Integer;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;那么我们如何读取SQLConnection设置的参数值呢 比如服务器信息 代理服务器信息之类的设置呢&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;为了减少代码量我在这里直接继承TDBXDatasnapProperties类实现了TCfSynaTCPDatasnapProperties类来设置代理服务器信息&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;//&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;包含代理服务器配置的属性类&lt;br /&gt;TCfSynaTCPDatasnapProperties&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;class&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;(TDBXDatasnapProperties)&lt;br /&gt;strict&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;private&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyIP:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyPort:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyUsername:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyPassword:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyTimeout:&amp;nbsp;Integer;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;function&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyType:&amp;nbsp;TProxyType;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyIP(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyPort(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyUsername(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyPassword(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyTimeout(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value:&amp;nbsp;Integer);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyType(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;const&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;Value:&amp;nbsp;TProxyType);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;published&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyIP:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyIP&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyIP;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyPort:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyPort&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyPort;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyUsername:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyUsername&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyUsername;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyPassword:&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;string&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyPassword&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyPassword;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyTimeout:&amp;nbsp;Integer&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyTimeout&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyTimeout;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;property&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyType:&amp;nbsp;TProxyType&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;read&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;GetProxyType&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;write&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;SetProxyType;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;然后通过TCfSynaTCPDatasnapDriver的构造函数传递&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;复制DbxDatasnap单元TDBXDatasnapDriver的代码 把TDBXDatasnapProperties改成TCfSynaTCPDatasnapProperties&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;这样我们就可以根据参数的配置来连接服务器&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;procedure&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TCfSynaTCPChannel.Open;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Close;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;FTcpClient&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;nil&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TTCPBlockSocket.Create;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;with&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TCfSynaTCPDatasnapProperties(DbxProperties)&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;do&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;if&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyIP&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;lt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;''&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;then&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;case&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyType&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;of&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ptSocks4:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksType&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ST_Socks4;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ptSocks5:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksType&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ST_Socks5;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;case&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyType&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;of&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ptSocks4,&amp;nbsp;ptSocks5:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksIP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyIP;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksPort&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyPort;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksUsername&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyUsername;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksPassword&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyPassword;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.SocksTimeout&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyTimeout;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ptHTTP:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.HTTPTunnelIP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyIP;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.HTTPTunnelPort&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyPort;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.HTTPTunnelUser&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyUsername;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.HTTPTunnelPass&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyPassword;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.HTTPTunnelTimeout&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;ProxyTimeout;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FTcpClient.Connect(HostName,&amp;nbsp;IntToStr(Port));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;FChannelInfo&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;TDBXSocketChannelInfo.Create(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800080; "&gt;0&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;,&amp;nbsp;FTcpClient.GetLocalSinIP);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;调用代码示例&lt;/p&gt;&lt;div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;with&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;DM.SQLConnection&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;do&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;begin&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Close;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TCfSynaTCPNames.ProxyType]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&amp;nbsp;IntToStr(Integer(ptHTTP));&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TCfSynaTCPNames.ProxyIP]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;localhost&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TCfSynaTCPNames.ProxyPort]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;80&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TCfSynaTCPNames.ProxyUsername]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;abc&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TCfSynaTCPNames.ProxyPassword]&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;123&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TDBXPropertyNames.HostName]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;localhost&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Params.Values[TDBXPropertyNames.Port]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;:&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;1217&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #800000; "&gt;'&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;try&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Open;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;except&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #0000ff; "&gt;end&lt;/span&gt;&lt;span style="font-family: 'Courier New'; color: #000000; "&gt;;&lt;/span&gt;&lt;/div&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;单元实现完整代码&amp;nbsp;&lt;a href="http://files.cnblogs.com/gfkz/CfSynaTCPChannel.rar" target="_blank" style="color: #1d58d1; text-decoration: none; "&gt;CfSynaTCPChannel.rar&lt;/a&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: #ff0000; "&gt;注: 该单元可以直接引用也可以新建个包安装 最好在Register函数中调用InstallSynaDriver&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 5px; margin-right: auto; margin-left: auto; margin-bottom: 5px; text-indent: 0px; "&gt;&lt;span style="color: #ff0000; "&gt;否则IDE中SQLConnection控件的Driver设置成CfSynaTCPDataSnap下次打开的时候可能会报错&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/Thinknet/aggbug/2051423.html?type=2" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/Thinknet/articles/2051423.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/1577858.html</id><title type="text">高性能的socket通讯服务器（完成端口模型--IOCP）[转载]</title><summary type="text"/><published>2009-10-03T17:40:00Z</published><updated>2009-10-03T17:40:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/1577858.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/1577858.html"/></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/1576619.html</id><title type="text">WebBrowser操作Html[转]</title><summary type="text"/><published>2009-09-29T13:31:00Z</published><updated>2009-09-29T13:31:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/1576619.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/1576619.html"/></entry><entry><id>http://www.cnblogs.com/Thinknet/articles/1576614.html</id><title type="text">WebBrowser、MSHTML在Delphi中的使用[转]</title><summary type="text"/><published>2009-09-29T13:26:00Z</published><updated>2009-09-29T13:26:00Z</updated><author><name>大名鼎鼎</name><uri>http://www.cnblogs.com/Thinknet/</uri></author><link rel="alternate" href="http://www.cnblogs.com/Thinknet/articles/1576614.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/Thinknet/articles/1576614.html"/></entry></feed>
