EInvalidOperation with SubChart and MarksTipTool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
WilliEbert
Newbie
Newbie
Posts: 26
Joined: Wed Aug 25, 2010 12:00 am

EInvalidOperation with SubChart and MarksTipTool

Post by WilliEbert » Wed Apr 13, 2011 2:42 pm

Hello
I've get always a EInvalidOperation (with message 'SubChart' has no parent window) if the SubChart has a MarksTipTool assigned to a series as Tool and the cursor hovers over the series in the SubChart. The error occurs in line 574 of TSubChartTool

if (not AllowDrag) then
-> TChartAccess(FChart).MouseMove(Shift,X,Y);


Can you help me?

Your sincerely

Willi Ebert

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

Re: EInvalidOperation with SubChart and MarksTipTool

Post by Yeray » Wed Apr 13, 2011 4:33 pm

Hello Willi,

I've been able to reproduce the problem so I've added it to the defect list to be fixed in future releases (TV52015496).

In the meanwhile, you could work with OnMouseMove event as in the example below:

Code: Select all

procedure Chart2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
//...
uses Chart, TeeSubChart, Series, TeeTools;

var Chart1, Chart2: TChart;
    SubChart1: TSubChartTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(self);
  Chart1.Parent:=Self;
  Chart1.Align:=alClient;
  Chart1.Legend.Visible:=false;
  Chart1.View3D:=false;

  Chart1.AddSeries(TPointSeries).FillSampleValues();

  SubChart1:=(Chart1.Tools.Add(TSubChartTool) as TSubChartTool);
  Chart2:=SubChart1.Charts.AddChart('');
  Chart2.View3D:=false;

  Chart2.AddSeries(TPointSeries).FillSampleValues();
  Chart2[0].Color:=OperaPalette[1];

  Chart2.Tools.Add(TAnnotationTool).Active:=false;
  Chart2.OnMouseMove:=Chart2MouseMove;
end;

procedure TForm1.Chart2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var ValueIndex: Integer;
    Annot: TAnnotationTool;
begin
  Annot:=Chart2.Tools[0] as TAnnotationTool;

  ValueIndex:=Chart2[0].Clicked(X, Y);
  if ValueIndex>-1 then
  begin
    Annot.Active:=true;
    Annot.Text:=FormatFloat('##0,##', Chart2[0].YValue[ValueIndex]);
    Annot.Left:=X-SubChart1.Charts[0].Left;
    Annot.Top:=Y-SubChart1.Charts[0].Top-Annot.Height;
  end
  else
    Annot.Active:=false;
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

WilliEbert
Newbie
Newbie
Posts: 26
Joined: Wed Aug 25, 2010 12:00 am

Re: EInvalidOperation with SubChart and MarksTipTool

Post by WilliEbert » Wed Apr 13, 2011 5:08 pm

Hello Yeray,
thank you very much for your quick answer. But i do not fully understand your code. Lets say Chart1 is my main Chart, SubChart1 is the SubChart of Chart1. But why you use Chart2?

Your sincerely

Willi Ebert

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

Re: EInvalidOperation with SubChart and MarksTipTool

Post by Yeray » Thu Apr 14, 2011 10:59 am

Hello Willi,

As you can see in the line:

Code: Select all

Chart2:=SubChart1.Charts.AddChart('');
Chart2 is the first chart in the SubChart Tool.

In other words:
SubChart1 is the same than (Chart1.Tools[0] as TSubChartTool)
Chart2 is the same than (SubChart1.Charts[0] as TChart) and the same than ((Chart1.Tools[0] as TSubChartTool).Charts[0] as TChart)
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