Page 1 of 1

Control 'chartTest' has no parent window

Posted: Tue Dec 27, 2016 3:17 pm
by 16577368
I just upgraded to 2016.19.161025 and I get an exception (Control 'chartTest' has no parent window) for a chart I create fully in code. It occurs when I call the .Draw method. I will post an example here soon but I sure would like to have a fix to this ASAP.

Ed Dressel

Re: Control 'chartTest' has no parent window

Posted: Tue Dec 27, 2016 3:25 pm
by 16577368
Attached is a demo that creates the problem. (I just tested 2016.18 and it worked fine. It only seems to occur in .19).

Re: Control 'chartTest' has no parent window

Posted: Wed Dec 28, 2016 12:23 pm
by 10050769
Hello Test Always,

The problem you're experiencing appears for me using TeeChart Pro VCL/FMX v2016.18, too. But in any case, to fix the problem you should only assign to result.Parent property the parent window it needs. You can modify the code in same way I have done below:

Code: Select all

function TFOrm1.CreateChart: TChart;
begin
  result := TChart.Create(nil);
  result.Parent := Self;

  //result.Canvas := TTeeCanvas3D.Create;  doesn't allow transparent series for batch gap chart

  result.Color := clWhite;
  result.BevelOuter := bvNone;
  result.LeftAxis.Grid.Color := clSilver;

//  result.LeftAxis.LabelsFont.Name := 'Arial Narrow'; {added from Gap Chart}
  result.LeftAxis.AutomaticMinimum := False; {added from Gap Chart}
  result.LeftAxis.Minimum := 0; {added from Gap Chart}
  result.LeftAxis.MinorTicks.Visible := False; {added from Gap Chart}
  result.LeftAxis.TicksInner.Visible := False; {added from Gap Chart}
  result.LeftAxis.Ticks.Style := psDot;
  result.LeftAxis.TickLength := 2; {added from Gap Chart}
  result.LeftAxis.Axis.Width := 1;
  result.LeftAxis.Title.Font.Name := 'Arial Narrow';

  result.BottomAxis.Axis.Color := clSilver;
  result.BottomAxis.MinorTicks.Visible := false; {added from Gap Chart}
  result.BottomAxis.Ticks.Visible := false;
//  result.BottomAxis.LabelsFont.Name := 'Arial Narrow';
  result.BottomAxis.Grid.Visible := False;
  result.BottomAxis.Axis.Width := 1;

  result.Legend.Frame.Visible := False;
  result.Legend.Title.Font.Name := 'Arial Narrow';
  result.Legend.Title.Font.Style := [];
  result.Legend.Shadow.VertSize := 0;
  result.Legend.LegendStyle := lsSeries;
  result.Legend.Shadow.HorizSize := 0;
  result.Legend.Alignment := laRight;
  result.Legend.Transparent := True;

  result.LeftAxis.Axis.Color := clSilver;
  result.LeftAxis.AxisValuesFormat := '$,0';

  result.Walls.Visible := False;

  result.BackWall.Pen.Color := clSilver;
//  result.OnGetAxisLabel := ChartAxisLabel;

  result.View3D := False;
end;


procedure TForm1.CreateChartImage;
var
  lChart: TChart;

  function CreateChartSeries: TAreaSeries;
  begin
    result := TAreaSeries.Create(self);
    result.ParentChart := lChart;
    result.AreaLinesPen.Visible := false;
    result.Pen.Visible := false;
  end;

var
  lRect: TRect;
begin
  lChart := CreateChart;
  try
    lChart.LeftAxis.Title.Font.Size := 10;
    lChart.BottomAxis.Title.Caption := 'Years in Retirement';
    lChart.BottomAxis.Title.Font.Size := 10;
    lChart.Legend.CustomPosition := True;

    lRect := Rect(1, 1, Image1.Width, Image1.Height);

    lChart.SetBounds(0, 0, lRect.Width, lRect.Height);

    lChart.Draw;
    lChart.Draw;

  finally // wrap up
   // lChart.FreeAllSeries;
  // lChart.Free;
  end;    // try/finally
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  CreateChartImage;
end;
Hoping this helps.

Thanks in advance,

Re: Control 'chartTest' has no parent window

Posted: Wed Dec 28, 2016 7:12 pm
by 16577368
This was only a demo. The actual chart is created in a data module (so "self" does not work) and I also use this in a online service and would prefer not have to create a TForm.

This wasn't this way in 2015.x.

Can this be fixed?

Ed Dressel

Re: Control 'chartTest' has no parent window

Posted: Thu Dec 29, 2016 9:46 am
by 10050769
Hello Ed Dessel,

The problem appears for me, too using Teechart Pro V2015.16 version. Could you tell us in which exactly TeeChart Pro 2015 version, the problem doesn't appear for you?
Also, I'm sorry the code we offers you doesn't help but it fix the demo example you send us. Is possible you attached the project you're using because we can try to find a solution for the problem you're experiencing? If it is large you can upload it in the link below:

http://www.steema.net/upload/


Thanks in advance

Re: Control 'chartTest' has no parent window

Posted: Fri Dec 30, 2016 6:02 pm
by 16577368
I hope you have (or had as your probably wont' get to this in 2016) an wonderful New Years and that 2017 is a great year for your.

I appreciate your attention to this issue.

After reviewing my code I didn't t understand what is happening--you are correct (as you know) that the demo does not work in .18 either.

My demo was a very simplified version of what we are doing in code, and I removed quite a bit. But after reviewing more, I did find the issue.

In the (updated) attached demo the way the image gets generated is a little different and optionally uses the TTeeCanvas3D class.

This demo now works in 2016.18 but raises an exception in 2016.19.

Please advise.

Ed Dressel

Re: Control 'chartTest' has no parent window

Posted: Mon Jan 02, 2017 3:49 pm
by 10050769
Hello Ed Dressel,

Many thanks for the clarification.
I have added the problem in the TeeChart VCL Bugzilla tracker to review it to upcoming releases. Here's the link: http://bugs.teechart.net/show_bug.cgi?id=1738
Also, I would like suggest you, comment the Draw method so the application works fine without that.

Hoping this helps you

Thanks in advance

Re: Control 'chartTest' has no parent window

Posted: Wed Jan 04, 2017 4:31 pm
by 16577368
Sigh. If I remove the .Draw command the custom positioned legend does not work. (This was told to do this by Steema's support).

Please let me know how to move forward.

Ed Dressel

Re: Control 'chartTest' has no parent window

Posted: Thu Jan 05, 2017 9:19 am
by yeray
Hello,
Test Always wrote:Sigh. If I remove the .Draw command the custom positioned legend does not work. (This was told to do this by Steema's support).
I see the legend is drawn on top of the chart if you don't force a chart repaint. I'm not sure if this was the exact cause of that suggestion.
In that case, an alternative would be to add some margin at the top instead of forcing a chart repaint:

Code: Select all

function TdmCreateChart.CreateImage(aRect: TRect): TGraphic;
//...
    lChart.Legend.CustomPosition := True;

    lSrs := CreateChartSeries;
    lSrs.FillSampleValues(100);

    lChart.SetBounds(aRect.Left, aRect.Top, aRect.Right, aRect.Bottom);
    lChart.MarginTop:=10;  //Add some margin at the top

    {lChart.Draw;
    lChart.Draw;}
//...

Re: Control 'chartTest' has no parent window

Posted: Thu Jan 05, 2017 6:06 pm
by 16577368
Like I said this is a simple demo of a much more complex situation. I really don't want to chase down every little item to show you that I really need to call the .draw command. I do--because the positioning of the legend needs more than just a margin begin set.

To set the position of the legend, I use the following code:

Code: Select all

    ...
    lChart.OnAfterDraw := GapChartAfterDraw;
    ...

procedure TMyUnit.GapChartAfterDraw(Sender: TObject);
begin
  Assert(sender is TChart);
  AdjustGapChartLegend(Sender as TChart);
end;

procedure TMyUnit.AdjustGapChartLegend(aChart: TChart);
var
  lLeft: Integer;
begin
  if (aChart.SeriesCount > 0) and (aChart.Series[0].Count > 0) then
  begin
    lLeft := aChart.Series[0].CalcXPos(1);
    aChart.Legend.Left := lLeft;
  end;
end;
Adding a margin doesn't get me this. 2016.19 does not work for my team (we have 4 licenses)--what worked before, and how Steema support told me to implement it (calling the .draw command 2x), is broken in 2016.19.

Ed Dressel

Re: Control 'chartTest' has no parent window

Posted: Mon Jan 09, 2017 11:41 am
by yeray
Hello Ed,

There was a change in v2016.19 forcing the chart to have a parent when you call Draw method.
An alternative would be to call TeeCreateBitmap.