Page 1 of 1

Exception on opening form with component using TChart

Posted: Fri Jul 25, 2014 6:50 am
by 16567585
TeeChart 2014: If I write a component which is a descendant of TPanel and which creates a TChart in the constructor with owner being Self, then any form on which my component was/is put cannot be opened in the Delphi IDE (design time), since an exception (translated from German):
access violation at address 504F0554 in module vcl200.bpl. reading address 00000000
is thrown. The exception is not thrown at run-time.

If I pass nil or the panel's owner as owner to TChart.Create everything is fine.
Here's an outline of the component:

Code: Select all

interface

type
  TCollChartPanel = class(TPanel)
  private
    FChart           : TChart;
...
  public
    constructor Create(Owner : TComponent); override;
...
end;
...
procedure Register;

implementation
...
constructor TCollChartPanel.Create(Owner : TComponent);
begin
  inherited;

  Self.Parent      := Owner as TWinControl;
  Self.BevelOuter  := bvNone;
  Self.BevelInner  := bvNone;
  Self.BorderStyle := bsNone;

  FChart        := TChart.Create(Self); // nil or Owner works fine
  FChart.Parent := Self;
  FChart.Align  := alClient;
end;
...

procedure Register;
begin
  RegisterComponents('Collinor', [TCollChartPanel]);
end;

Re: Exception on opening form with component using TChart

Posted: Tue Jul 29, 2014 9:51 am
by 10050769
Hello Collinor,

Thanks for your information. Could you please arrange for us a simple applications with your own component, because we can check if the exception occurs here and we try to find a solution for it?

Thanks in advance,

Re: Exception on opening form with component using TChart

Posted: Sun Aug 17, 2014 12:04 pm
by 16567585
With Delphi's menu entry Component/New Component... create a new component TCollChartPanel in unit CollChartPanel with the following code and put it in a new package with name Coll:

Code: Select all

unit CollChartPanel;

interface

uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.ExtCtrls, VCLTee.Chart;

type
  TCollChartPanel = class(TPanel)
  private
    { Private-Deklarationen }
    FChart           : TChart;
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(Owner : TComponent); override;
  published
    { Published-Deklarationen }
  end;

procedure Register;

implementation

uses
  Forms; // bsNone

procedure Register;
begin
  RegisterComponents('Samples', [TCollChartPanel]);
end;

constructor TCollChartPanel.Create(Owner : TComponent);
begin
  inherited;

  Self.Parent      := Owner as TWinControl;
  Self.BevelOuter  := bvNone;
  Self.BevelInner  := bvNone;
  Self.BorderStyle := bsNone;

  FChart        := TChart.Create(Self); // nil or Owner works fine
  FChart.Parent := Self;
  FChart.Align  := alClient;
end;

end.
Compile the Coll package and install it.
Then, create a new VCL application, put the CollChartPanel component (found in the Samples tool palette) on the main form and save and close the project.
Now reopen the project and you'll see that an exception is raised and the main form won't open.
Next, open the Coll package again, and change the line

Code: Select all

  FChart        := TChart.Create(Self); // nil or Owner works fine
into

Code: Select all

  FChart        := TChart.Create(Owner); // nil or Owner works fine
recompile the package and close the project.
Finally, reopen the VCL application with the TCollChartPanel component on the main form and you'll see that the main form will open without error.

Re: Exception on opening form with component using TChart

Posted: Tue Aug 19, 2014 2:57 pm
by yeray
Hello,

This worked fine for me in Delphi 7.
testComponent.zip
(6.44 KiB) Downloaded 921 times
I'll try it with XE6 and let you know asap.

Re: Exception on opening form with component using TChart

Posted: Tue Aug 19, 2014 3:08 pm
by yeray
Hello again,

It worked without problems for me also in XE6:
testComponentXE6.zip
(6.48 KiB) Downloaded 955 times
testColl.zip
(4.09 KiB) Downloaded 893 times
I'm using TeeChart v2014.11, and you?

Re: Exception on opening form with component using TChart

Posted: Tue Aug 19, 2014 3:11 pm
by yeray
Hello,

Sorry, I missed the last part:
Collinor wrote:Now reopen the project and you'll see that an exception is raised and the main form won't open.
I've reproduced the problem now.
We'll investigate it and let you know asap.

Re: Exception on opening form with component using TChart

Posted: Wed Aug 20, 2014 8:53 am
by yeray
Hello,

I've created a ticket in the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=893
Feel free to add your mail to the CC list to be automatically notified when an update arrives.