Jump to content
Fudley

D12 TItemClickEvent undeclared identifier

Recommended Posts

Trying to reference the events for a TListBox in order to save and restore them. This is so I can make changes to the listbox without triggering the events, then restore the events.

 

However I'm having trouble with FMX.ListBox.TCustomListBox.OnItemClick as Delphi suggests that TItemClickEvent  is an undeclared identifier.

 

Thoughts?

 

 

 

Share this post


Link to post

Thanks. But still undeclared identifier TCustomListBox.TItemClickEvent

 

 

Edited by Fudley

Share this post


Link to post

In this case, FMX.Listbox is definately in the uses clause

Share this post


Link to post
4 hours ago, Fudley said:

In this case, FMX.Listbox is definately in the uses clause

Please post a reproducible example.

Share this post


Link to post
8 hours ago, Fudley said:

Thanks. But still undeclared identifier TCustomListBox.TItemClickEvent

It should not be undeclared. It is a public sub-type of TCustomListBox.  The following is taken from FMX.ListBox.pas:

  TCustomListBox = class(...)
  ...
  public type
    ...
    TItemClickEvent = procedure(const Sender: TCustomListBox; const Item: TListBoxItem) of object;
    ...
  strict private
    ...
    FOnItemClick: TItemClickEvent;
    ...
  public
    ...
    property OnItemClick: TItemClickEvent read FOnItemClick write FOnItemClick;
  end;

The following works fine for me in D12.2:

uses
  ..., FMX.ListBox;

procedure TForm1.Button1Click(Sender: TObject);
var
  OnClickHandler: TCustomListBox.TItemClickEvent;
begin
  OnClickHandler := ListBox1.OnItemClick;
  ListBox1.OnItemClick := nil;
  // ...
  ListBox1.OnItemClick := OnClickHandler;
end;

You could also use an inline variable and let the compiler deduce the type:

uses
  ..., FMX.ListBox;

procedure TForm1.Button1Click(Sender: TObject);
begin
  var OnClickHandler := ListBox1.OnItemClick;
  ListBox1.OnItemClick := nil;
  // ...
  ListBox1.OnItemClick := OnClickHandler;
end;

 

Edited by Remy Lebeau

Share this post


Link to post

Thanks Dave, Remy!

Here's my reproducible (at least for me) example:
 


unit testlistboxerror1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts, FMX.ListBox;
type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
     procedure Button1Tap(Sender: TObject; const Point: TPointF);
     procedure NoEventSetListBoxIndex   (aListBox : TCustomListBox;  aValue : integer);
  private
  public
  end;
var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.NoEventSetListBoxIndex   (aListBox : TCustomListBox;  aValue : integer);
var
  eItemClickEvent: TItemClickEvent ;  
  // also tried TCustomListBox.TItemClickEvent, same
  {<--[DCC Error] testlistboxerror1.pas(31): E2003
    Undeclared identifier: 'TItemClickEvent ' }          
  eGestureEvent  : TGestureEvent;
  eTapEvent      : TTapEvent;
begin
  eItemClickEvent        := aListBox.OnClick ;
  eGestureEvent        := aListBox.OnGesture;
  eTapEvent            := aListBox.OnTap;
  aListBox.OnClick        := nil;
  aListBox.OnGesture    := nil;
  aListBox.OnTap        := nil;
  aListBox.Itemindex     := aValue;
  aListBox.OnClick        := eItemClickEvent ;
  aListBox.OnGesture    := eGestureEvent;
  aListBox.OnTap        := eTapEvent;
end;    

procedure TForm1.Button1Tap(Sender: TObject; const Point: TPointF);
begin
 NoEventSetListBoxIndex(ListBox1,  5);
end;

end.

 

Share this post


Link to post

Dave - the inline method worked great thanks!

Share this post


Link to post

For me it is working:

 

var
  eItemClickEvent: TCustomListBox.TItemClickEvent;
 

and fails at:

 

eItemClickEvent        := aListBox.OnClick ;

since the OnClick and OnItemClick has different signatures.

 

For OnClick it should be:

 

var 

eOnClickEvent : TNotifyEvent;

 

eOnClickEvent:=aListBox.OnClick;

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×