TAChart: deriving from TListChartSource may lead to infinite loop
Original Reporter info from Mantis: Marcin Wiazowski
-
Reporter name:
Original Reporter info from Mantis: Marcin Wiazowski
- Reporter name:
Description:
I introduced some problem, when adding XCountMin / YCountMin functionality to TListChartSource, in #35089 (closed) - so I'm attaching a Reproduce demo application, and a patch to fix the problem.
Currently, TListChartSource has two constructors:
constructor TListChartSource.Create(AOwner: TComponent);
begin
...
end;
constructor TListChartSource.Create(AOwner: TComponent; AXCountMin, AYCountMin: Cardinal);
begin
Create(AOwner); <==== PROBLEM IS HERE
FXCountMin := AXCountMin;
FYCountMin := AYCountMin;
if FXCount < FXCountMin then
FXCount := FXCountMin;
if FYCount < FYCountMin then
FYCount := FYCountMin;
end;
The attached demo application implements TListChartSource's descendant, in the following way:
type
TTestSource = class(TListChartSource)
public
constructor Create(AOwner: TComponent); override;
end;
constructor TTestSource.Create(AOwner: TComponent);
begin
inherited Create(AOwner, 2, 2);
end;
Currently, creating a TTestSource instance causes an infinite recursion, which finally leads to stack overflow:
- TTestSource.Create() calls the second variant of TListChartSource.Create()
- second variant of TListChartSource.Create() calls Create() - since Create() is a virtual method, this leads us back to TTestSource.Create()
- TTestSource.Create() calls the second variant of TListChartSource.Create()
- second variant of TListChartSource.Create() calls Create() - since Create() is a virtual method, this leads us back to TTestSource.Create()
- ...
- ...
The attached patch solves the problem.
Mantis conversion info:
- Mantis ID: 35665
- Build: 61310
- Version: 2.1 (SVN)
- Fixed in revision: 61320 (#cdd32d1c)
- Target version: 2.2