Teechart SelectorTool Error

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
restech
Newbie
Newbie
Posts: 7
Joined: Mon Mar 27, 2017 12:00 am

Teechart SelectorTool Error

Post by restech » Fri Feb 16, 2018 8:16 am

Hi!

I work with RadStudio 10.1 Berlin in c++ and teechart Pro 2017.21

I found next error in teechart. After adding on chart RectangleTool and AnnotationTool, then i dragged annotation in RectangleTool area, i can't drag annotation with SelectorTool, only Rectangle.
Error occurs because of tools order in Selector. Then i click on chart, SelectorTool stops on Rectangle(Rectangle inherited from Annotation). Error can't be fixing by override SelectorTool class(function of search tools is not virtual)

The only way to fix error is change source code and recompile teechart.
To fix error in source code i can change FOR operator in file TeeSelectorTool.pas on string 353 by this:

Code: Select all

for t:=Tools.Count-1 downto 0 do
In attachment you can find Tee file from Teechart Office, there i just reproduce this error.
Also there is screenshot of tools order in archive
Attachments
Attachments.7z
(7.89 KiB) Downloaded 776 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Teechart SelectorTool Error

Post by Yeray » Mon Feb 19, 2018 9:28 am

Hello,

After loading the tee file, I can see a TRectangleTool and a TAnnotationTool, but no TSelectorTool in the chart.
Anyway, I think I understand the problem. When two TAnnotationTools (or descendants like TRectangleTool) are superposed, the TSelectorTool checks the tools in the order of addition, and that may or may not be the desired behaviour.
One thing you could do is to move the last used TAnnotationTool to the first position in the list of tools. This could be done with the TSelectorTool events. Ie:

Code: Select all

var selected: Integer;

procedure TForm1.SelectorSelected(Sender: TObject);
var i: Integer;
begin
  for i:=0 to Chart1.Tools.Count-1 do
    if Chart1.Tools[i] is TAnnotationTool then
      if (Chart1.Tools[i] as TAnnotationTool).Clicked(Chart1.GetCursorPos.X, Chart1.GetCursorPos.Y) then
      begin
        selected:=i;
        break;
      end;
end;

//Same for OnResized
procedure TForm1.SelectorDragged(Sender: TObject);
var i, first: Integer;
begin
  for i:=0 to Chart1.Tools.Count-1 do
    if Chart1.Tools[i] is TAnnotationTool then
    begin
      first:=i;
      break;
    end;

  if (Chart1.Tools[first] <> Chart1.Tools[selected]) and
     (Chart1.Tools[first] is TAnnotationTool) and
     (Chart1.Tools[selected] is TAnnotationTool) then
     Chart1.Tools.Exchange(first, selected);
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

restech
Newbie
Newbie
Posts: 7
Joined: Mon Mar 27, 2017 12:00 am

Re: Teechart SelectorTool Error

Post by restech » Mon Feb 19, 2018 3:17 pm

Yeray wrote:Hello,

After loading the tee file, I can see a TRectangleTool and a TAnnotationTool, but no TSelectorTool in the chart.
Anyway, I think I understand the problem. When two TAnnotationTools (or descendants like TRectangleTool) are superposed, the TSelectorTool checks the tools in the order of addition, and that may or may not be the desired behaviour.
One thing you could do is to move the last used TAnnotationTool to the first position in the list of tools. This could be done with the TSelectorTool events. Ie:

Code: Select all

var selected: Integer;

procedure TForm1.SelectorSelected(Sender: TObject);
var i: Integer;
begin
  for i:=0 to Chart1.Tools.Count-1 do
    if Chart1.Tools[i] is TAnnotationTool then
      if (Chart1.Tools[i] as TAnnotationTool).Clicked(Chart1.GetCursorPos.X, Chart1.GetCursorPos.Y) then
      begin
        selected:=i;
        break;
      end;
end;

//Same for OnResized
procedure TForm1.SelectorDragged(Sender: TObject);
var i, first: Integer;
begin
  for i:=0 to Chart1.Tools.Count-1 do
    if Chart1.Tools[i] is TAnnotationTool then
    begin
      first:=i;
      break;
    end;

  if (Chart1.Tools[first] <> Chart1.Tools[selected]) and
     (Chart1.Tools[first] is TAnnotationTool) and
     (Chart1.Tools[selected] is TAnnotationTool) then
     Chart1.Tools.Exchange(first, selected);
end;

Thanks for your reply, but you can see in new tee file in attachments, that there is no way to drag annotation, exept changing tool order in for operator. If rectangle is not transparrent, you can't see annotation behind it. So i just can't use your code for my task.
Is it error in logic of teechart?
Attachments
Attachments.7z
(1.42 KiB) Downloaded 758 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Teechart SelectorTool Error

Post by Yeray » Mon Feb 26, 2018 9:16 am

Hello,

It seems I wasn't fully understanding it when I thought I was. :oops:
If the drawing order of the tools follows the same direction than the order of detection of the tools in the mouse event, it results on the undesirable effect you describe.
I've added it to the public tracker and fixed it for the next maintenance release.
http://bugs.teechart.net/show_bug.cgi?id=2002

Note the TSelectorTool also events need to be fired also before the TRectangleTool's events are fired, so you need to move it to the top of the list of tools.
I've also modified the code to exchange the TAnnotationTools to do it simply at the OnSelected event:

Code: Select all

uses Series, TeeTools, TeeSelectorTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues;

  with Chart1.Tools.Add(TSelectorTool) as TSelectorTool do
  begin
    OnSelected:=SelectorSelected;
  end;

  with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
  begin
    Text:='Rectangle';
    Shape.Transparency:=50;
    Shape.Color:=clYellow;
    Top:=100;
    Left:=100;
    Width:=200;
    Height:=100;
  end;

  with Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool do
  begin
    Text:='Annotation';
    Shape.Transparency:=50;
    Shape.Color:=clRed;
    Shape.Shadow.Hide;
    Top:=120;
    Left:=130;
    Width:=100;
    Height:=50;
  end;
end;

procedure TForm1.SelectorSelected(Sender: TObject);
var i, last, selected: Integer;
begin
  selected:=-1;
  last:=-1;

  for i:=Chart1.Tools.Count-1 downto 0 do
    if Chart1.Tools[i] is TAnnotationTool then
    begin
      if last=-1 then
         last:=i;

      if (selected=-1) and (Chart1.Tools[i] as TAnnotationTool).Clicked(Chart1.GetCursorPos.X, Chart1.GetCursorPos.Y) then
      begin
        selected:=i;
        break;
      end;
    end;

  if (last>-1) and (selected>-1) and
     (Chart1.Tools[last] <> Chart1.Tools[selected]) then
  begin
    Chart1.Tools.Exchange(last, selected);
    Chart1.Draw;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply