Firemonkey ListView 点击事件

Firemonkey ListView 的点击事件一直让人摸不着头绪(各平台触发规则不太相同),因为它提供了点击相关的事件就有如下:

  • OnChange:改变项目触发。
  • OnClick:点击触发。
    • Windows 平台:按下立即触发,放开后接着触发 OnItemClickEx。
    • Android 平台:按下立即触发,不用放开接着OnItemClickEx(按钮 Button 触发顺序与 Widnows 相同,要放开才会触发OnItemClickEx)。
  • 下列以这二个事件为例:
    • OnItemClickEx:项目内单项触发。
    • OnButtonClick:按钮事件。

下例将 Item.Apperance 设定为 Custom。

可获取每一个单项的事件触发:

TForm1.ListView1ItemClickEx( [Ref] LocalClickPos: TPointF; ItemObject TListItemText Label1.Text := + ItemIndex.ToString ItemObject TListItemImage Label1.Text := + ItemIndex.ToString ItemObject TListItemAccessory Label1.Text := + ItemIndex.ToString<span style="color: #0000ff;">procedure TForm1.ListView1ButtonClick(<span style="color: #0000ff;">const<span style="color: #000000;"> Sender: TObject;
<span style="color: #0000ff;">const
AItem: TListItem; <span style="color: #0000ff;">const
<span style="color: #000000;"> AObject: TListItemSimpleControl);
<span style="color: #0000ff;">begin

<span style="color: #0000ff;">if
AObject <span style="color: #0000ff;">is
TListItemGlyphButton <span style="color: #0000ff;">then
Label1.Text := <span style="color: #800000;">'
<span style="color: #800000;">OnButtonClickGlyphButton
<span style="color: #800000;">'
+ AItem.Index.ToString <span style="color: #0000ff;">else

<span style="color: #0000ff;">if
AObject <span style="color: #0000ff;">is
TListItemTextButton <span style="color: #0000ff;">then
Label1.Text := <span style="color: #800000;">'
<span style="color: #800000;">OnButtonClickTextButton
<span style="color: #800000;">'
+<span style="color: #000000;"> AItem.Index.ToString;
<span style="color: #0000ff;">end
;

有一些问题存在:

  1. 点击 Accessory 后是触发 Text 而非 Accessory,这部份我有改动到源码,使它能正常辨别是点击到那一个(改动源码并不建议,有兴趣自行研究)。

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...