Access DataModule's event from another Form (delphi design-time)

こ雲淡風輕ζ 提交于 2019-12-13 09:11:50

问题


I would like to know if there's any way to link a component's event (As TButton.OnClick) to a procedure defined in a datamodule (At design-time). At the moment, I'm doing this at runtime:

MyButton.OnClick := MyDataModule.MyOnClickEvent;

The goal would be that to get MyDataModule.MyOnClickEvent proposed in the dropdown lists in the Object Inspector Window. Thanks in advance to all who will share their knowledge :D

Note1: Here's a similar question, but there are no informations about how to accomplishing the same task at design-time: Access an event on a DataModule from another Form

Note2: The only way I found consists in define all events on a parent-form, but I was hoping there was a cleaner solution


回答1:


As far as I know something like this is not possible.

Perhaps with some addons but I doubt it. Why?

Imagine all the cluter that would be returned when you try using something like this on a project with hudreds of forms and thousands of events.

Also how would you deal when you would have multiple events on different forms with same name?




回答2:


Define a published method in the DataModule to act as the event handler. Its signature must match TNotifyEvent.

Make sure the DataModule's unit is in the interface uses clause of the component's parent Form unit.

Make sure the DataModule is created before the parent Form is created.



来源:https://stackoverflow.com/questions/29446578/access-datamodules-event-from-another-form-delphi-design-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!