4

Hello please is there any VirtualStringTree version that contains these 2 Mouse Events :

OnMouseEnter and OnMouseLeave ?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Sdean
  • 245
  • 2
  • 5
  • 12

1 Answers1

4

These events are easy enough to add if your string tree doesn't already support them.

  TMyImprovedVirtualStringTree = class(TSomeVirtualStringTree)
  private
    FOnMouseEnter: TNotifyEvent;
    FOnMouseLeave: TNotifyEvent;

    // Watch for MouseEnter and MouseLeave messages...
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  protected
    // Provide MouseEnter() and MouseLeave() methods
    // for descendent controls to override if needed.
    procedure MouseEnter; virtual;
    procedure MouseLeave; virtual;
  published
    // Publish the events so they show in Delphi's object inspecter.
    property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

implementation

{ TMyImprovedVirtualStringTree }

procedure TMyImprovedVirtualStringTree.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  MouseEnter;
end;

procedure TMyImprovedVirtualStringTree.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  MouseLeave;
end;

procedure TMyImprovedVirtualStringTree.MouseEnter;
begin
  if Assigned(FOnMouseEnter) then
    FOnMouseEnter(Self);
end;

procedure TMyImprovedVirtualStringTree.MouseLeave;
begin
  if Assigned(FOnMouseLeave) then
    FOnMouseLeave(Self);
end;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Shannon Matthews
  • 9,649
  • 7
  • 44
  • 75
  • I added calls to `inherited` to both of your message handlers. Without these you break the control because the underlying control already has handlers for these messages. – David Heffernan Jul 09 '13 at 09:45