[Solved] Crosshair error when changing series lazarus / 55-TAChart ---------------------------------------------------------------------- Marq01 · 2024-12-10 19:02 I have this problem with the crosshair that is bugging me. I know what is happening but not how to solve it. Tried many things but even AI did not give the answer i needed. Example: in a chart are 6 lines and with the [Ctrl]+mousemove the crosshair wil give the datapoint below the crosshair. This works as expected and when the crosshair is not close enough tot he lines it disappears: as expected. Then new lines are loaded in the same chart after deleting the previous with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if (aChart.SeriesCount > 0) then    for i := aChart.SeriesCount - 1 downto 0 do       if (aChart.Series[i] is TChartSeries) then         TChartSeries(aChart.Series[i]).Free;  Which works perfectly well. UNLESS: the crosshair was visible when deleting and loading new lines. Then it trows an listindex error in the function   Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TListChartSource.GetItem(AIndex: Integer): PChartDataItem;begin  Result := PChartDataItem(FData.Items[AIndex]);end;    of the TASources unit. I can understand why it does this: the previous chart series are gone and new are in place. But how teach the crosshair not to display and reset itself? As said I tried a lot (Enable/disable/hide). Please find my program in the attachment. It it only the essentials but still big. Start program – goto tab ‘injections’ – press [ctrl]+mousemove and set crosshair. – goto to tab ‘alingment’ and witness the problem. Please what should i do to solve the crosshair? ---------------------------------------------------------------------- wp · 2024-12-11 10:41 I don't fully understand the issue because your description of the issue seems to be different from the behaviour of the program. I need SHFT+mousemove to display the crosshair. When I select the Alignment page with visible crosshair I do see the crash that you mention. I'd propse to hide the crosshair in the OnChange handler of the pagecontrol; you already have this in your code, commented out with message "ERROR // hide because sometimes it stays". Uncommenting this line does result in an error indeed. Debugging into this error leads to TBasicChartTool.Deactivate in which properties of the internal FChart variable are accessed although FChart is nil. I could not find out why FChart became nil here, but I think it should not be harmful to perform a check for nil here: Open unit TAGraph, find the implementation of TBasicChartTool.Deactivate, put all the code into an "if Assigned(FChart) then" condition. Probably it is helpful to do the same with TBasicChartTool.Activate: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TBasicChartTool.Activate;begin  if Assigned(FChart) then  begin    FChart.FActiveToolIndex := Index;    FChart.MouseCapture := true;    FChart.FDisablePopupMenu := false;    FStartMousePos := Mouse.CursorPos;  end;end; procedure TBasicChartTool.Deactivate;begin  if Assigned(FChart) then  begin    FChart.MouseCapture := false;    FChart.FActiveToolIndex := -1;    if PopupMenuConflict then      FChart.FDisablePopupMenu := true;  end;end; This (together with the crosshairtool.Hide in the pagecontrol's OnChange handler) fixes the issue. I noticed that the crosshair cursor does not disappear when the SHIFT key is released. Well, it should... This probably is because the chart does not have the focus at this moment and thus does not get the key events. You can avoid this by setting the chart's AutoFocus property to true - now the chart is focused whenever the mouse is moved inside the chart. But be aware that this is a two-sided sword: When you are typing something into an edit somewhere and incidentally move the mouse into the chart, the edit will lose focus, and when you continue typing the edit will not receive the key strokes any more because they are sent to the chart now. ---------------------------------------------------------------------- Marq01 · 2024-12-11 18:47 Sorry for the error in Ctrl vs Shift key. I had to add one more change in my original program to the TATools unit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TDataPointDrawTool.DoHide;begin  if Assigned(FChart) then  begin    case EffectiveDrawingMode of      tdmXor: begin        FChart.Drawer.SetXor(true);        DoDraw;        FChart.Drawer.SetXor(false);      end;      tdmNormal:        FChart.StyleChanged(Self);    end;  end;end; And Yes the AutoFocus did add some more problems than it solved. For now the hide is the best option I think. Thanks for pointing in the right way. ---------------------------------------------------------------------- wp · 2024-12-11 21:39 Quote from: Marq01 on December 11, 2024, 07:47:59 pmI had to add one more change in my original program to the TATools unit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TDataPointDrawTool.DoHide;begin  if Assigned(FChart) then  begin    case EffectiveDrawingMode of      tdmXor: begin        FChart.Drawer.SetXor(true);        DoDraw;        FChart.Drawer.SetXor(false);      end;      tdmNormal:        FChart.StyleChanged(Self);    end;  end;end;What is the scenario why you want to change this? The original code in TAChart looks quite reasonable (except maybe for the unchecked call to FChart.StyleChanged). ---------------------------------------------------------------------- Marq01 · 2024-12-12 19:09 For some reason an error pops up at the line 1936 in TATools Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FChart.Drawer.SetXor(true); and close inspection shows that FChart=nil so I reasond that an extra check would be necessary in TDataPointDrawTool.Dohide For completeness i use Lazarus version #2.0.12; FPC 3.2.0; SVN revision: 64642 win64 Not sure which version of TAChart I use (how to find out?). ---------------------------------------------------------------------- wp · 2024-12-12 21:45 Ah, now I understand why I had not seen this crash here. Laz 2.0.12 is pretty old, and in Laz 2.2.0 a modification of DoHide had come in: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TDataPointDrawTool.DoHide(ADrawer: IChartDrawer);begin  if ADrawer = nil then exit;  case EffectiveDrawingMode of    tdmXor: begin      ADrawer.SetXor(true);      DoDraw(ADrawer);      ADrawer.SetXor(false);    end;    tdmNormal:      if Assigned(FChart) then FChart.StyleChanged(Self);   // "if Assigned(FChart) then" added today.  end;end; ---------------------------------------------------------------------- Marq01 · 2024-12-13 20:55 Good point. I really need to update to keep up with all the stuff. Thanks wp.