Recent

Author Topic: ChartTools: ATool.Chart = nil in AfterMouseUp event  (Read 3339 times)

wp

  • Hero Member
  • *****
  • Posts: 13398
ChartTools: ATool.Chart = nil in AfterMouseUp event
« on: January 12, 2013, 11:20:24 pm »
In a larger project I noticed crashes caused in the AfterMouseUp event of a TZoomDragTool shared between two charts. In the event the chart in which the mouseup occured needs to be known in order to execute some code depending on whether the chart is zoomed or not.

Investigating into this problem I found out that the parameter ATool that is passed to the OnAfterMouseUp event does no longer know about the chart in which the event was generated (ATool.Chart = nil). See the attached demo which shows the name of the event along with the chart it belongs to.

I know the workaround now - store the chart in the OnBeforeMouseUp event and evaluate that in the AfterMouseUp.

But it is not self-evident why the ATool.Chart is different in the AfterMouseUp event. Therefore, there should be a statement on that in the documentation, or better, the AfterMouseUp event should behave like the other events regarding ATool.Chart. Or is this by design?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: ChartTools: ATool.Chart = nil in AfterMouseUp event
« Reply #1 on: January 13, 2013, 10:06:47 pm »
Quote
is this by design?
Not quite. It is rather a side-effect of a known design limitation.
Basically, there is only one instance of internal state per tool,
even if that tool is shared between several charts.
So there is a danger of mistakes due to mixups.
To reduce the probability of error, Deactivate method immediately clears FChart field (similar to using FreeAndNil instead of just Free).

You can quick-fix this by removing line 1677 of TAGraph.pas
(FChart := nil).
I have to do more thorough analysis before committing this change.

wp

  • Hero Member
  • *****
  • Posts: 13398
Re: ChartTools: ATool.Chart = nil in AfterMouseUp event
« Reply #2 on: January 13, 2013, 11:50:56 pm »
Thank you

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: ChartTools: ATool.Chart = nil in AfterMouseUp event
« Reply #3 on: January 14, 2013, 04:21:16 pm »
Committed in r39854.
Please test -- if there is no bad side effects,
I will nominate this for fixes branch.

wp

  • Hero Member
  • *****
  • Posts: 13398
Re: ChartTools: ATool.Chart = nil in AfterMouseUp event
« Reply #4 on: January 15, 2013, 02:18:50 pm »
My projects using ChartTools are running fine, thank you.

 

TinyPortal © 2005-2018