1

Delphi 10.1 Pro, VCL with embedded Teechart controls. CalcClickedPart shows cpSeriesMarks after a Marks set to be hidden at the place it was previously shown.

I may not deleting Marks correctly, only hiding it, or there is a bug in CalcClickedPart. Please advice.

I added a tLabel on the top-left which show the CalcClickedPart Part result. Also a button to toggle the Marks visibility.

The series & Marks creation:

procedure TForm2.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;
  with Chart1.AddSeries(TLineSeries) as TLineSeries do
    begin
      for i := 0 to 9 do
        begin
          AddXY(i, 10);
          Marks.Item[i].Visible := false; // Hide all Marks
        end;

      Marks.Show; // A global Marks enabled.
      Marks.Item[5].Visible := true;
    end;
end;

CalcClickedPart test:

procedure TForm2.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
Var
  ClickedPart: tChartClickedPart;
  sCursorText: string;
begin
  sCursorText := '';

  Chart1.CalcClickedPart(Point(X, Y), ClickedPart); // Return information about the TeeChart component below the Mouse pointer at an X,Y location.
  Case ClickedPart.Part of
    cpNone          : sCursorText := 'cpNone';
    cpLegend        : sCursorText := 'cpLegend';
    cpAxis          : sCursorText := 'cpAxis';
    cpSeries        : sCursorText := 'cpSeries';
    cpTitle         : sCursorText := 'cpTitle';
    cpFoot          : sCursorText := 'cpFoot';
    cpChartRect     : sCursorText := 'cpChartRect';
    cpSeriesMarks   : sCursorText := 'cpSeriesMarks';
    cpSeriesPointer : sCursorText := 'cpSeriesPointer ';
    cpSubTitle      : sCursorText := 'cpSubTitle';
    cpSubFoot       : sCursorText := 'cpSubFoot';
    cpAxisTitle     : sCursorText := 'cpAxisTitle';
  end;

  Label1.Caption := sCursorText;
end;

The Marks visibility toggling:

procedure TForm2.btnMarksToggleClick(Sender: TObject);
begin
  with (Chart1[0] as tLineSeries).Marks.Item[5] do
    Visible := not Visible;
end;

Marks is visible. A correct cpSeriesMarks (cursor in Red arrow):

Press the button to hide the Marks. Will get the following wrong CalcClickedPart. Marks is NOT visible. An incorrect cpSeriesMarks (cursor in Red arrow):

Do you have any idea for work around?

p.s I previously found a bug with CalcClickedPart when CalcVisiblePoints := false. This is another issue, not related to CalcVisiblePoints at all.

Thanks Reron

2
  • I don't see that as a bug at all. Setting Visible := false doesn't remove the mark, it just doesn't draw it. The mark is still in its location. Commented Sep 23, 2018 at 7:13
  • Tom, it is a point of view. Do you know how to delete/remove a single Mark completely? or hide it from CalcClickedPart when it is not visible?
    – Reron
    Commented Sep 23, 2018 at 9:57

1 Answer 1

2

I've been able to reproduce the problem here so I've added it to the public tracker (#2092).

Note the problem is at TSeriesMarks.Clicked function.
I've already fixed it for the next versions.

As a workaround, you could set Positions.Item[5]:=nil:

procedure TForm2.btnMarksToggleClick(Sender: TObject);
const aMarksIndex = 5;
begin
  with (Chart1[0] as tLineSeries).Marks do
  begin
    with Item[aMarksIndex] do
      Visible := not Visible;

    if not Item[aMarksIndex].Visible then
       Positions.Items[aMarksIndex]:=nil;
  end;
end;
5
  • Thanks Yeray. Can I assume there is a class or an object created for each Mark? It is created on the 1st time a Marks is shown. If the assumption is correct, can it be free/disposed somehow by code? Something like "Marks.Items[aMarksIndex].CleanupInstance;" which doesn't help. I also tried to set "Marks.Items[aMarksIndex]" AutoSize:=false, Width=Height=0 and RePaint, It was also was not a solution.
    – Reron
    Commented Sep 24, 2018 at 16:05
  • The TSeriesMarks.Clicked function loops the Marks.Positions array. So, you could set the Marks.Positions.Count:=0 to force resetting the positions.
    – Yeray
    Commented Sep 26, 2018 at 7:20
  • I think this workaround is better than the one I initially proposed, so I'll move the first thought to the end of the answer
    – Yeray
    Commented Sep 26, 2018 at 7:27
  • Yeray, thank you - it is working for me. Based on yours direction, may I offer Marks.Positions.Items[aMarksIndex] := nil. It is dedicated to a single Mark.
    – Reron
    Commented Sep 27, 2018 at 11:14
  • Thanks for pointing it. I think I tested Marks.Positions[5]:=nil; which gives an Access Violation. I'll edit the answer with that code.
    – Yeray
    Commented Sep 28, 2018 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.