Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何防止/取消TListBox中的项目更改?_Delphi_Listbox_Delphi Xe2_Onchange_Firemonkey - Fatal编程技术网

Delphi 如何防止/取消TListBox中的项目更改?

Delphi 如何防止/取消TListBox中的项目更改?,delphi,listbox,delphi-xe2,onchange,firemonkey,Delphi,Listbox,Delphi Xe2,Onchange,Firemonkey,使用FireMonkey和一个 我希望能够允许/取消项目更改 就像我们可以通过TListView的事件来实现一样: 在更改之前会触发mousedown和OnKeyDown事件(项目值仍然适用于当前/旧所选项目,而不是新所选项目) 所以我可以存储当前的列表框ItemIndex。。。在改变之后,回到过去。。但这太糟糕了,太脏了 不管怎样,还是要做得很好?您最好创建一个自定义组件,通过覆盖SetItemIndex方法来添加功能: type TCustomListBox = class(TListBox

使用FireMonkey和一个

我希望能够允许/取消项目更改

就像我们可以通过TListView的事件来实现一样:

在更改之前会触发mousedown和OnKeyDown事件(项目值仍然适用于当前/旧所选项目,而不是所选项目)

所以我可以存储当前的列表框ItemIndex。。。在改变之后,回到过去。。但这太糟糕了,太脏了


不管怎样,还是要做得很好?

您最好创建一个自定义组件,通过覆盖SetItemIndex方法来添加功能:

type TCustomListBox = class(TListBox)
  protected
    procedure SetItemIndex(Value: Integer);override;
  end;

procedure Register;

程序寄存器;
开始
注册表控件('Custom',[TCustomListBox]);
结束;
过程TCustomListBox.SetItemIndex(值:整数);
开始
若然
继承
结束;
初始化
RegisterFMXClasses([TCustomListBox]);
结束;
当然,您可以为条件类型添加事件

procedure Register;
begin
  RegisterControls('Custom', [TCustomListBox]);
end;

procedure TCustomListBox.SetItemIndex(Value: Integer); 
begin
  if <condition> then
inherited
end;

initialization
  RegisterFMXClasses([TCustomListBox]);
end;