Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an event handler for a non published but public event in delphi?

In RAD Studio 10.1 Berlin quite a few things has changed from previous version. In FMX there are a few previously published events that has now been changed to only be public.

I have a Multi Platform Project that uses a TStringGrid component and the OnDblClick event. When opening this project in Studio 10.1 I get warned that the Property OnDblClick does not exist.

The question is now how I can use the no longer published event?

(I must say that It's hard to understand why they haven't set mouse events to Published anymore. As far as I know most regular PCs and OSX machines doesn't have touch. A true Multi Target Project should be able to target these systems without hassle as they did in Studio 10 Seattle)

like image 857
TheAviator Avatar asked Mar 12 '23 18:03

TheAviator


2 Answers

In case the event handlers already exist (which I imply by the error message), you can assign these handlers to their events in FormCreate.

procedure TForm1.FormCreate;
begin
  StringGrid1.OnDblClick := StringGrid1DblClick;
end;
like image 112
Uwe Raabe Avatar answered Apr 21 '23 05:04

Uwe Raabe


One solution is to make your own component where you extend the FMX.TStringGrid to have published event handlers again.

See here how to create a new FMX component: creating a firemonkey component

Here's the code to re-publish the mouse events.

unit MyStringGrid;

interface

uses FMX.Grids;

type
  TMyStringGrid = class(TStringGrid)
  published
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove; 
    property OnMouseUp;
    property OnMouseWheel;
    property OnMouseEnter;
    property OnMouseLeave;
  end;

procedure Register;

implementation

uses FMX.Types;

procedure Register;
begin
  RegisterComponents('NewPage', [TMyStringGrid]);
end;

initialization
  RegisterFmxClasses([TMyStringGrid]);
end.
like image 34
Johan Avatar answered Apr 21 '23 04:04

Johan