Q
qinzusong
Unregistered / Unconfirmed
GUEST, unregistred user!
在 RemoteDataModule引用如下<br> public<br> CommObj1:tSrvComObject;<br> RemoteDataModule创建实例如下<br> CommObj1.create();<br><br>报错为Access violation at address 0040424f in module '中间层程序名'<br>我在一般的vcl appliction中引用这个类没有报这个错误。<br><br>class 定义如下<br>unit sOIObjectPool;<br><br>interface<br><br>Uses SysUtils , Classes, ExtCtrls, Controls , Comobj, AdoDB, Provider,<br> Dialogs, db, DataBkr, sIObjectPool;<br><br>type TSrvComObject = Class<br> Query: tadoquery;<br> Dsp: TDataSetProvider;<br> bIsUsing:Boolean;<br> Time:ttimer;<br> iRunTime:Integer;<br> private<br><br> public<br> constructor create();<br> destructor destroy();override;<br> procedure InitInstance(rdm:TRemoteDataModule);safecall;<br> procedure FinishRequest();safecall;<br> procedure BeginUeing(); safecall;<br><br> procedure TimeOnTimer(Sender:tObject);<br> procedure QueryAfterClose(DataSet: TDataSet);<br> procedure QueryAfterOpen(DataSet: TDataSet);<br><br> end;<br><br>implementation<br><br>uses sDm, sCommMethod;<br><br>procedure TSrvComObject.BeginUeing();<br>begin<br><br> bIsUsing:=True;<br> Time.Enabled:=True;<br> iRunTime:=0;<br>end;<br><br>constructor TSrvComObject.create();<br>begin<br> inherited create;<br>end;<br><br>procedure TSrvComObject.InitInstance(rdm:TRemoteDataModule);<br>begin<br> if query=nil then<br> Query:= tadoquery.Create(rdm);<br> Query.Connection:=fDm.ADOConn;<br> Query.Name:=GetNewCName();<br> if Dsp=nil then<br> begin<br> Dsp:= TDataSetProvider.Create(rdm);<br> Dsp.Name:=GetNewCName;<br> Dsp.DataSet:=Query;<br> rdm.RegisterProvider(Dsp);<br> end;<br> bIsUsing:=False;<br> Time:=ttimer.Create(nil);<br> Time.Enabled:=False;<br> Time.Interval:=1000;<br> iRunTime:=0;<br> Time.OnTimer:=TimeOnTimer;<br> query.AfterOpen:=QueryAfterOpen;<br> query.AfterClose:=QueryAfterClose;<br>end;<br><br>destructor TSrvComObject.destroy;<br>begin<br> inherited;<br> Query:=nil;<br> Dsp:=nil;<br> Time:=nil; <br> Query.Free;<br> Dsp.Free;<br> Time.Free;<br>end;<br><br>procedure TSrvComObject.FinishRequest;<br>begin<br> Query.Close;<br> Time.Enabled:=False;<br> iRunTime:=0;<br> bIsUsing:=False;<br>end;<br><br>procedure TSrvComObject.QueryAfterClose(DataSet: TDataSet);<br>begin<br> FinishRequest;<br>end;<br><br>procedure TSrvComObject.QueryAfterOpen(DataSet: TDataSet);<br>begin<br> BeginUeing();<br>end;<br><br>procedure TSrvComObject.TimeOnTimer(Sender: tObject);<br>begin<br> inc(iRunTime);<br> if iRunTime=1800 then<br> FinishRequest();<br>end;<br><br>end.