0

I am using Firemonkey and I would like to allocate the OnTap Event to an object at Runtime.

The code that i have tries is basically the same as the one i use for the OnClick event:

Header at the top :

procedure txtHostClick(Sender: TObject);

Procedure :

procedure TMyForm.txtHostClick(Sender: TObject);
begin
   //do stuff
end;

Assignment to event handler:

hotspot :=  Tmemo.Create(Highlight_Scrollbox);
hotspot.OnClick := txtHostClick;

So i try to apply the same logic to the OnTap event and it gives the following error :

[DCC Error] s3.pas(4338): E2009 Incompatible types: 'Parameter lists differ'

Below is a code sample of what I have tried:

Header at the top :

procedure txtOnTAPEvent(Sender: TObject; const [Ref] Point: TPointF);

Procedure :

procedure TMyForm.txtOnTAPEvent(Sender: TObject; const [Ref] Point: TPointF);
begin
   //do stuff
end;

Assignment to event handler:

hotspot :=  Tmemo.Create(Highlight_Scrollbox);
hotspot.OnTap := txtOnTAPEvent;

There is gap in my knowledge that needs to be filled.

1 Answers1

0

Try removing the [Ref] attribute from the Point parameter:

procedure txtOnTAPEvent(Sender: TObject; const Point: TPointF);

procedure TMyForm.txtOnTAPEvent(Sender: TObject; const Point: TPointF);
begin
    //do stuff
end;

If you double-click on any UI control's OnTap event in the Object Inspector at design-time, you will see that the IDE generates an OnTap event handler that does not include the [Ref] attribute. This is further enforced by the fact that there is no [Ref] attribute in the declaration of FMX.Types.TTapEvent to begin with:

TTapEvent = procedure(Sender: TObject; const Point: TPointF) of object;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Hi Remy, thanks for the answer. It is correct. I was also wondering if you could explain the following. When i drop an object on the form and create an OnTap event using the built in events tab on the IDE, The procedure that is created has the [Ref] field? – Andrew Maine Dec 08 '15 at 06:02
  • I tested the IDE before posting my answer. Using Seattle Update 1, when I had the IDE create the event, no `[Ref]` attribute was present. – Remy Lebeau Dec 08 '15 at 07:16
  • Thanks. I will accept this. I don't have update 1 so it might just be in the version without the update. – Andrew Maine Dec 08 '15 at 07:26