EInvalidOperation with TMarksTipTool and TSubChartTool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Eic
Newbie
Newbie
Posts: 18
Joined: Mon Apr 18, 2016 12:00 am

EInvalidOperation with TMarksTipTool and TSubChartTool

Post by Eic » Tue Oct 25, 2016 1:50 pm

Hi,

I made this simple code to reproduce a bug :

Code: Select all

void __fastcall TscrTestGraphe::Button2Click(TObject *Sender)
{
	TChart * Chart1 = new TChart(this);
	Chart1->Parent = this;
	Chart1->Align = alClient;

	TSubChartTool *SubChart1 = new TSubChartTool(NULL);
	Chart1->AddSeries(new TPointSeries(Chart1))->FillSampleValues();

	Chart1->Tools->Add(SubChart1);

	TChart * Chart2 = SubChart1->Charts->AddChart("MySubChart");
        // Chart2->Parent = _subChartTool->ParentChart;
	Chart2->AddSeries(new TPointSeries(Chart1))->FillSampleValues();

	TMarksTipTool *marksTipTool = new TMarksTipTool(Chart2);
	marksTipTool->OnGetText = OnGetMarksTipGetText;

	Chart2->Tools->Add(marksTipTool);
}

void __fastcall TscrTestGraphe::OnGetMarksTipGetText(TMarksTipTool* Sender, System::UnicodeString &Text)
{
	TChartSeries *serie = Sender->ParentChart->Series[0];
	int iValueIndex = serie->GetCursorValueIndex();  // <= Launch the exception
}
The objective is to use a TMarksTipTool on a SubChart.

At run time, calling the GetCursorValueIndex function generates the exception "Le projet TEST.exe a déclenché la classe d'exception EInvalidOperation avec le message 'Le contrôle 'MySubChart' n'a pas de fenêtre parente'."

If I enable the line :

Code: Select all

Chart2->Parent = _subChartTool->ParentChart;

I have no exception but the tip is not displayed.

How to view a Tip on a sub chart ?

Thanks.

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

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Post by Yeray » Fri Oct 28, 2016 9:51 am

Hello,

I could reproduce the problem so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=1668
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

Eic
Newbie
Newbie
Posts: 18
Joined: Mon Apr 18, 2016 12:00 am

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Post by Eic » Fri Oct 28, 2016 12:35 pm

Hello,

Thank you for your reply.

Pending publication of the correction, what alternative do you propose to know the current index overflight in the event "OnGetText" ?

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

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Post by Yeray » Mon Oct 31, 2016 1:39 pm

Hello,

You could use the clicked function of the series and get the mouse position of the chart the subchart belongs to. Ie:

Code: Select all

procedure TForm1.OnGetMarksTipGetText(Sender: TMarksTipTool; var Text: string);
var serie: TChartSeries;
    iValueIndex: Integer;
    i, j: Integer;
begin
  serie := Sender.ParentChart.Series[0];
  //iValueIndex := serie.GetCursorValueIndex();  // <= Launch the exception

  for i:=0 to Chart1.Tools.Count-1 do
    if Chart1.Tools[i] is TSubChartTool then
       for j:=0 to (Chart1.Tools[i] as TSubChartTool).Charts.Count-1 do
          if (Chart1.Tools[i] as TSubChartTool).Charts[j].Chart = Sender.ParentChart then
          begin
            iValueIndex := serie.Clicked(Chart1.GetCursorPos); // <= Works fine
            //Caption:=IntToStr(iValueIndex);
            exit;
          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

Eic
Newbie
Newbie
Posts: 18
Joined: Mon Apr 18, 2016 12:00 am

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Post by Eic » Thu Nov 03, 2016 2:54 pm

Hello,

It Works.

Thanks

Post Reply