我想为TFileListBox创建一个新的事件。我想知道用户何时选择不同的项目。如何实现TFileListBox的OnSelectionChanged事件?
实现它会在用户按下这样的鼠标按钮来调用该事件的最好办法:
procedure TMyFileList.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
VAR PrevItem: Integer;
begin
PrevItem:= ItemIndex; <---------- Problem here
inherited;
if (Count> 0)
AND (PrevItem<> ItemIndex)
AND Assigned(FOnSelChaged)
then FOnSelChaged(Self, PrevItem);
end;
所以,我们说的拳头项目(的ItemIndex = 0)已经被选定。 只要我按下鼠标按钮选择第二项,我就进入了MouseDown过程。但是这里的ItemIndex已经是1而不是0. 为什么?
Delphi的哪个版本? – Dampsquid 2012-02-24 21:27:32
看起来您对选择更改的位置不正确。显然,选择的变化较早。找到那个地方。我可以帮忙,但我不知道TFileList是什么,所以我无法阅读它的源代码。 – 2012-02-24 21:30:37
对不起。我的确在谈论tFileListBox。该代码在Delphi 7/XE下的行为相同。 – Ampere 2012-02-24 21:59:04