我有一个TreeViewItem
,它的onMouseUp
没有被解雇,我尝试缩小我的复杂类,并且能够产生一个有效的onMouseUp
实例,看来onMouseMove
覆盖导致此行为是一个谜,因为我正在使用onMouseUp
,但没有覆盖onMouseMove
!
如何解决此代码?
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
FMX.TreeView;
type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure MouseMove(Shift: TShiftState; X, Y: Single); override;
procedure onItemMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
procedure TForm2.FormCreate(Sender: TObject);
var
treeView: TTreeView;
treeViewItem: TTreeViewItem;
begin
treeView := TTreeView.Create(nil);
treeView.Position.X := 0;
treeView.Position.Y := 0;
treeView.Width := 200;
treeView.Height := 300;
treeView.Parent := form2;
treeViewItem := TTreeViewItem.Create(nil);
treeViewItem.Parent := treeView;
treeViewItem.Text := 'This is a test';
treeViewItem.OnMouseUp := onItemMouseUp;
end;
procedure TForm2.onItemMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Single; Y: Single);
begin
ShowMessage('onItemMouseUp');
end;
procedure TForm2.MouseMove(Shift: TShiftState; X: Single; Y: Single);
begin
end;
end.
答案 0 :(得分:1)
MouseMove(...) override;
会覆盖其他所有onMouseMove
,这通常用于如果您需要确保在MouseMove
上执行而不管您关注的对象是什么,因为您要覆盖{{1 }},您必须在正文中使用关键字MoveMove
,这样才能确保所有其他继承的Inherited
也能正常工作。
因此,您只需要将MouseMove更改为此:
onMouseMove