Page 1 of 1

EInvalidOperation with TMarksTipTool and TSubChartTool

Posted: Tue Oct 25, 2016 1:50 pm
by 16478065
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.

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Posted: Fri Oct 28, 2016 9:51 am
by yeray
Hello,

I could reproduce the problem so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=1668

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Posted: Fri Oct 28, 2016 12:35 pm
by 16478065
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" ?

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Posted: Mon Oct 31, 2016 1:39 pm
by yeray
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;

Re: EInvalidOperation with TMarksTipTool and TSubChartTool

Posted: Thu Nov 03, 2016 2:54 pm
by 16478065
Hello,

It Works.

Thanks