Recent

Author Topic: Tchart crashes on MouseMouse event is scale/range is not set yet  (Read 312 times)

stephanweber

  • Jr. Member
  • **
  • Posts: 54
Hi,

I use the mouse moving event to update a little text label to show the coordinates. But to get the coordinates x and y the ranges need to be setup already. This is not the case on program startup, so if the mouse cursor is (e.g. by chance) over the chart I get a runtime error.
To avoid this I created a boolean variable IsRun and use it in mouse-move event and initialize it in formcreate to False.
However, I still get the same crash. What to do?

Code:

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  2.   Y: Integer);
  3. Var xx, yy : Double;
  4. begin
  5.   If IsRun then Begin
  6.   xx:=Chart1.XImageToGraph(X);
  7.   yy:=Chart1.YImageToGraph(Y);
  8.   LabelCursor.Caption:='Cursor: x=...';
  9.   end
  10. end;

If I use If False all is fine....


Bye Stephan

TRon

  • Hero Member
  • *****
  • Posts: 2856
Re: Tchart crashes on MouseMouse event is scale/range is not set yet
« Reply #1 on: June 17, 2024, 08:53:54 am »
Hard to say without being able to see all the code/components/properties but as a general note: you can assign an event at runtime so would advise to try and set the event only after you have set the ranges correctly.

stephanweber

  • Jr. Member
  • **
  • Posts: 54
Re: Tchart crashes on MouseMouse event is scale/range is not set yet
« Reply #2 on: June 17, 2024, 09:32:14 am »
Hi, it looks I found a solution:

Using

If Chart1.ScalingValid then ...

works fine!!

However, I still do not know why using the boolean variable instead does not work.

Bye Stephan

 

TinyPortal © 2005-2018