Page 1 of 1

TCursorTool trap events

Posted: Wed May 26, 2010 12:11 pm
by 10055200
Hi,

Currently I am using TCursorTool.OnChange to detect change and do some operations. I have problems that OnChange event is called too fast or to many times. I would actually need one event which is fired when move of cursor is done. As I see OnChange is fired everytime the mouse moves which is problem for my application. I need to filter that somehow that OnChange would be fired only when change was made and mouse button is not down anymore. This mean that change would appear only when I stop to move cursor and unpress mouse button.

Now it is like:

1. Mouse button pressed to grab cursor
2. Mouse is moving (and cursor) so fire event OnChange

but I would need this way:

1. Mouse button pressed to grab cursor
2. Mouse is moving (and cursor)
3. Mouse button is up so stop moving cursor
4. If cursor new position differe from prevous position fire event OnChange


Does cursor tool offer any solutions to that (I cannot use snap while I have many points)? What do you suggest? Is possible somehow to trap that mouse events?

Thanks.
Br,
PoLabs

Re: TCursorTool trap events

Posted: Thu May 27, 2010 7:47 am
by yeray
Hi Br,

Yes, you can use the mouse events OnMouseDown, OnMouseMove and OnMouseUp to do this, or you can use the CursorTool OnChange evend with OnMouseUp as follows:

Code: Select all

var CursorChanged: Boolean;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CursorChanged:=false;
end;

procedure TForm1.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
  const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
  CursorChanged:=true;
end;

procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if CursorChanged then
  begin
    CursorChanged:=false;

    ShowMessage('Do the CursorChanged job');
  end;
end;

Re: TCursorTool trap events

Posted: Thu May 27, 2010 1:05 pm
by 10055200
Yep, that was very good solution. Thanks. ;)

BR,
PoLabs