怎样捕获TAdoQuery被打开?(20分)

  • 主题发起人 主题发起人 bravercaohao
  • 开始时间 开始时间
B

bravercaohao

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; 我要在DataMoudle任意一个TAdoQuery打开时要执行同一个事件,<br>(不想用共同事件,用shift选定所有TAdoQuery不是好办法)<br>怎样捕捉TAdoQuery被打开?
 
动态指定吧!<br><br>&nbsp; ADOQuery1.AfterOpen := deal;<br>&nbsp; ADOQuery2.AfterOpen := deal;<br>&nbsp; ADOQuery3.AfterOpen := deal;<br>&nbsp; ADOQuery4.AfterOpen := deal;<br>&nbsp; ADOQuery5.AfterOpen := deal;<br>&nbsp; ........................
 
放在什么事件中,如有100个TADOQuery怎么写?
 
啊?<br>你是动态创建的吗?<br>那更容易了,<br>在你创建 TADOQuery 时,如下:<br>&nbsp; SetLength( ADOS,100); &nbsp;// &nbsp;假定 ADOS 是你要创建的100个ADO 连接<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;我猜想你也不会在一个Module 或者是窗体上放100 控件吧!<br>&nbsp; for i:=0 to 100 do<br>&nbsp; begin<br>&nbsp; &nbsp; ADOS := TADOQuery.Create(self);<br>&nbsp; &nbsp; ADOS.AfterOpen := deal;<br>&nbsp; &nbsp; //........加入你的初始化。 &nbsp;<br>&nbsp; end;
 
不是动态的,项目中所有的TADOQuery都在DATAMOUDLE中,怎么解决
 
给你一个思路:<br><br>&nbsp; &nbsp;在 DataModule 的Create 事件中,<br>&nbsp; <br>&nbsp; &nbsp;if Components is TADOQuery then<br>&nbsp; &nbsp; &nbsp;(Components AS TADOQuery).AfterOpen := deal;<br><br>&nbsp; &nbsp;你看行不行,如果不行,我也没有招了。
 
同意darnis的作法,一定是可行的。
 
如果有的TADOQUERy在初始化时未打后而在在程序中控制的执行共同事件会不会有问题?
 
接受答案了.
 
后退
顶部