How can I create a generic KeyEvent handler?
Posted on 2005-04-23
I have an event handler that I use in the OnKeyDown event of a TwwDBDateTimePicker to modify the way date changes are handled when the + or - key is pressed in various combinations. Because I have a large number of these components in my application I want to put the code in a shared unit with other common functions and procedures so that it can be assigned to all datetimepickers.
I understand that you cannot assign a regular procedure to an event, as it generates and error. In the past I have used a dummy class to get around this problem, but it does not work in this case. Here is what I have tried so far:
Uses .... wwdbdatetimepicker, DateUtils;
type TDatePickHandler = Class // Dummy Class
procedure UpdateDateTimePicker(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure TTradePartnerForm.FormCreate(Sender: TObject);
ContactBirthdaywwDBDateTimePicker.OnKeyDown := TDatePickHandler.UpdateDateTimePicker; // Compile Error
This produces the error 'incompatible types tkeyevent and procedure' - how can I get around this problem?