问题描述
在Delphi 2009中,我有一个带有过程MyProcedure的表单,该过程写入表单上的标签.表单使用带有ClientDataSet的DataModule.当触发ClientDataSet的AfterScroll事件时,应执行MyProcedure.为了避免循环引用,更重要的是,因为我希望DataModule可重用,DataModule不应引用此特定的Form.
In Delphi 2009 I have a Form with a procedure MyProcedure that writes to a label on the Form. The form uses a DataModule with a ClientDataSet. When the AfterScroll event of the ClientDataSet is fired MyProcedure should be executed.To avoid circular references and more important, as I want the DataModule to be reusable,the DataModule should not reference to this specific Form.
简而言之,希望我可以从Form中访问AfterScroll事件.我可以在窗体上连接DataModule上的Afterscroll事件吗?我以为应该有可能,但是我不记得该怎么做.预先感谢.
In short, I hope that I can access the AfterScroll event from my Form. Can I hook up the Afterscroll event on the DataModule from my Form? I thought it should be possible, but I cannot remember how to do it. Thanks in advance.
推荐答案
您将事件属性放入DataModule:
You put an event property in your DataModule:
private
FOnAfterScroll : TNotifyEvent;
public
property OnAfterScroll : TNotifyEvent read FOnAfterScroll write FOnAfterScroll;
然后在DataModule的AfterScroll过程中调用该事件:
You then call that event in the AfterScroll procedure in the DataModule:
If Assigned(FOnAfterScroll) then FOnAfterScroll(Self);
形式:声明事件处理程序
In Form:declare event handler
procedure HandleAfterScroll(Sender : TObject);
然后您将一个过程分配给DataModule的OnAfterScroll
Then you assign a procedure to DataModule's OnAfterScroll
另一种方法是从DataModule发送自定义的Windows消息,然后在表单中响应该消息.
Another way would be to send a custom windows message from DataModule and to respond to that message in the Form.
这篇关于从另一个窗体访问DataModule上的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!