Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/AddOn/TChart    [ Add a report in this area ]  
Report #:  122729   Status: Closed
[TDBChart] Access Violation when open TeeChart with TClientDataSet at the second time
Project:  Delphi Build #:  19.0.14356.6604
Version:    19.2 Submitted By:   Andy Hui
Report Type:  Crash / Data loss / Total failure Date Reported:  2/24/2014 3:29:53 PM
Severity:    Critical / Show Stopper Last Updated: 4/15/2014 6:31:42 PM
Platform:    All versions Internal Tracking #:   47964
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 10
Description
We're migrating our XE projects to XE5, however, we encountered the access violation exception about teechart during the test. Can someone please look at it urgently?

I've created a test application to recreate the issue. With the test app, it works fine when open the first teechart form but will get the access violation exception when open it second time or open a new form.

Steps to Reproduce:
Steps to recreate the exception om TDBChart.

1. build and run the test app
2. click Open Chart 1
3. click Open Chart 2

------------
...
...
uses Unit2, OutcomeGraph;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowChart((Sender as TButton).Tag);
end;

procedure TForm1.ShowChart(const ATag: integer);
begin
  case ComboBox1.ItemIndex of
    0:
    begin
      OutcomesGraphFm := TOutcomesGraphFm.Create(Self);
      OutcomesGraphFm.Caption := 'ABC : Test result ';
      OutcomesGraphFm.Tag := ATag;
      OutcomesGraphFm.ShowModal; // <<---- Access Violation
      OutcomesGraphFm.Free;
    end;
    1:
    begin
      Form2 := TForm2.Create(self);
      try
        Form2.DatasetTag := ATag;
        Form2.ShowModal;
      finally
        FreeAndNil(Form2);
      end;
    end;
  end;
end;
------------
Workarounds
None
Attachment
DBChart.zip
Comments

Andy Hui at 2/24/2014 3:36:55 PM -
BTW, have installed the update of "TeeChart Lite for RAD Studio, Delphi, C++Builder XE5 Update 2".

http://cc.embarcadero.com/item/29708

David Berneda at 2/25/2014 12:45:44 AM -
I've converted the project (missing units, etc) and could finally reproduce the error in XE5 Update 2.
Its related to using an internal TObjectList generic collection inside DBChart.
The code has been improved so the error is fixed now (a new code takes care of destroying the ObjectList items correctly).

As a workaround, you can add this code at your form's OnClose event:

type
  TChartAccess=class(TDBChart);

procedure TOutcomesGraphFm.bbtnCloseClick(Sender: TObject);
begin
  TChartAccess(dbcBar).RemovedDataSource(bsTestScores,bsTestScores.DataSource);

  Close;
end;

Tomohiro Takahashi at 2/24/2014 5:37:24 PM -
Does your issue occur when closing Clientdataset connected to a TOutcomesGraphFm(including a TeeChart ) instance?
---------
procedure TForm2.OpenDataset(const ATag: integer);
var
  i: integer;
begin
  DataModule3.ClientDataSet1.Close; // <<---- Access Violation
  ...
  ...
---------

Michael Chen at 2/24/2014 5:48:45 PM -
Yes. I tried to debug it with DCUs. The exception happened when notifying TDBChart's OnStateChange event.

procedure TDataSet.DataEvent(Event: TDataEvent; Info: NativeInt);
begin
  ...
  if NotifyDataSources then
  begin
    for I := 0 to FDataSources.Count - 1 do
      FDataSources[I].DataEvent(Event, Info);  // <<---- Access Violation
    if FDesigner <> nil then FDesigner.DataEvent(Event, Info);
  end;
end;

Tomohiro Takahashi at 2/24/2014 6:08:59 PM -
ok, is this a regression in Delphi XE5(w/ the latest TeeChart Lite)? What about previous versions of Delphi?

Andy Hui at 2/24/2014 6:26:55 PM -
Yes. It's a regression in XE5 with latest TeeChart lite. We use Delphi XE previously.

Andy Hui at 2/25/2014 7:08:14 PM -
David Berneda (Steema) provided the workaround:

Its related to using an internal TObjectList generic collection inside
DBChart.
The code has been improved so the error is fixed now (a new code takes care
of destroying the ObjectList items correctly).

As a workaround, you can add this code at your form's OnClose event:

type
TChartAccess=class(TDBChart);

procedure TOutcomesGraphFm.bbtnCloseClick(Sender: TObject);
begin
TChartAccess(dbcBar).RemovedDataSource(bsTestScores,bsTestScores.DataSource);

Close;
end;

Server Response from: ETNACODE01