Recent

Author Topic: OnEnter of frame activates zoom selection in chart  (Read 3660 times)

kapibara

  • Hero Member
  • *****
  • Posts: 610
OnEnter of frame activates zoom selection in chart
« on: October 08, 2018, 10:35:23 pm »
There is a chart in a frame and the frame has an OnEnter event with a showmessage.

When clicking the chart OnEnter triggers ShowMessage, but on dissmissing that dialog a zoom selection in the chart starts. Am I doing something wrong?
« Last Edit: October 09, 2018, 02:12:30 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: OnEnter of frame activates zoom selection in chart
« Reply #1 on: October 09, 2018, 10:46:18 am »
The problem starts when you click into the chart to trigger the ShowMessage. But primarily, the click initiates a zooming process. I don't know exactly what happens when the message is shown, but the chart is still in zooming mode even when the message is closed - that's why that rectangle appears.

A way to avoid this is to deactivate zooming in the Object Inspector: Chart1.AllowZoom := false. If you need zooming afterwards you can switch AllowZoom back to true again. But as I found out, in Linux it is not sufficient to do this immediately after the ShowMessage call, instead it must be queued asynchronously:

Code: Pascal  [Select][+][-]
  1. procedure TfrTest.DoAllowZoom(AData: PtrInt);
  2. begin
  3.   TChart(AData).AllowZoom := true;
  4. end;
  5.  
  6. procedure TfrTest.FrameEnter(Sender: TObject);
  7. begin
  8.   ShowMessage('Enter');
  9. //  Chart1.AllowZoom := true;   // <---- this does not work
  10.   Application.QueueAsyncCall(@DoAllowZoom, PtrInt(Chart1));
  11. end;

Another, even simpler, solution is to turn on the Chart's AutoFocus. (The problem is for me that I don't know why this works.)

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: OnEnter of frame activates zoom selection in chart
« Reply #2 on: October 09, 2018, 11:12:41 pm »
Thanks, QueueAsyncCall did the trick for me under Linux!
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

 

TinyPortal © 2005-2018