Lazarus

Programming => Graphics and Multimedia => TAChart => Topic started by: kapibara on October 08, 2018, 10:35:23 pm

Title: OnEnter of frame activates zoom selection in chart
Post by: kapibara 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?
Title: Re: OnEnter of frame activates zoom selection in chart
Post by: wp 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.)
Title: Re: OnEnter of frame activates zoom selection in chart
Post by: kapibara on October 09, 2018, 11:12:41 pm
Thanks, QueueAsyncCall did the trick for me under Linux!
TinyPortal © 2005-2018