Page 1 of 1

EInvalidOperation with SubChart and MarksTipTool

Posted: Wed Apr 13, 2011 2:42 pm
by 16556791
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

Re: EInvalidOperation with SubChart and MarksTipTool

Posted: Wed Apr 13, 2011 4:33 pm
by yeray
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;

Re: EInvalidOperation with SubChart and MarksTipTool

Posted: Wed Apr 13, 2011 5:08 pm
by 16556791
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

Re: EInvalidOperation with SubChart and MarksTipTool

Posted: Thu Apr 14, 2011 10:59 am
by yeray
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)