ali ahmadi
ali ahmadi

Reputation: 189

onMouseMove override keeps onMouseUp from working

I have a TreeViewItem which its onMouseUp is not fired, I tried shrinking my complicated class and I was able to produce a working example of a onMouseUp not working, it seems the onMouseMove override is causing this behavior which is a mystery because I am using onMouseUp and I'm not overriding the onMouseMove!
How can I fix this code?

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.

Upvotes: 1

Views: 419

Answers (1)

ali ahmadi
ali ahmadi

Reputation: 189

MouseMove(...) override; overrides every other onMouseMove, this is usually used if you need to ensure execution on MouseMove no matter what kind of object you are focusing, since you are overriding MoveMove you have to use the keyword Inherited inside the body which will ensure all the other onMouseMoves that are inherited work as well.
So you simply need to change your MouseMove to this:

procedure TForm2.MouseMove(Shift: TShiftState; X: Single; Y: Single);
begin
  Inherited;
end;  

Upvotes: 1

Related Questions