Fudley 3 Posted October 4 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
Olli73 5 Posted October 4 var ItemClickEvent: TCustomListBox.TItemClickEvent; Share this post Link to post
Fudley 3 Posted October 4 (edited) Thanks. But still undeclared identifier TCustomListBox.TItemClickEvent Edited October 4 by Fudley Share this post Link to post
Lajos Juhász 295 Posted October 4 That is only possible if you have not included FMX.ListBox into the uses clause. Share this post Link to post
Fudley 3 Posted October 4 In this case, FMX.Listbox is definately in the uses clause Share this post Link to post
Dave Nottage 563 Posted October 4 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
Remy Lebeau 1436 Posted October 4 (edited) 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 October 4 by Remy Lebeau Share this post Link to post
Fudley 3 Posted October 4 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
Lajos Juhász 295 Posted October 4 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