16693

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

Question:

I would like to know if there's any way to link a component's event (As .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

<strong>Note1:</strong> Here's a similar question, but there are no informations about how to accomplishing the same task at design-time: <a href="https://stackoverflow.com/questions/906853/access-an-event-on-a-datamodule-from-another-form" rel="nofollow">Access an event on a DataModule from another Form</a>

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

Answer1:

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?

Answer2:

Define a <strong>published</strong> 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.

Recommend

  • Using Google Api: Speech To Text on PC Version
  • Reading contents of a managed bean with reflection in a JSF application
  • Tracking screen recorder in windows app
  • How can i use Django smart select to filter ManyToManyField?
  • Storing data from SQL in array
  • How to load Q library with Require.js?
  • Get the last date of each month in a list of dates in Python
  • Rails 5 - Google Maps - Javascript error - initMap is not a function - fixing one js issue creates a
  • Client side validation mvc dropdown
  • Main Thread Checker: UI API called on a background thread iOS 11 Xcode 9 GM Seed
  • PHP multiple file uploads
  • Javascript/Jquery runs fast in desktop browsers, but slow in mobile/smartphone browsers…should I spl
  • Activation Function choice for Neural network
  • Retrieving specified columns from a list of csv files to create a data data frame in R
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • How to override value that appears in a dropdown in the rails_admin gem
  • How can I replace the server in Web Component Tester
  • Creating a DropDownList
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • converting text file into xml using php?
  • ListItem.Attributes.Add not working
  • Unable to get column index with table.getColumn method using custom table Model
  • custom UITableViewCell with image for highlighting
  • Alert pop up with LWUIT
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • How would I use PHP exceptions to define a redirect?
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • Comma separated Values
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • SQL merge duplicate rows and join values that are different
  • AngularJs get employee from factory
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • How do I configure my settings file to work with unit tests?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How does Linux kernel interrupt the application?
  • Is it possible to post an object from jquery to bottle.py?
  • Net Present Value in Excel for Grouped Recurring CF