We have some problem with TeeChart when trying to create and save it to bitmap from the separate thread in gui application.
Some result images(bmp) are corrupted. I.e. some files are ok, but another images empty or not fully painted(for example only legend is painted and nothing more). Sometimes "Out of resources" exception is raised inside the TeeChart.
The problem exists in TeeChart 5(Delphi 5)/6(Delphi 7) and in versions that included in Delphi 2006 and Delphi 2007
We have find out that there is no this problem in console application, only in gui application. Also, somehow this issue is depends on window messages of main form - for example when mouse is over the main form or timer works. In this case we have more "corrupted" bmps
We have a test project to show this problem. (can't find how to attach a file?)
http://forum.ixbt.com/post.cgi?id=attach:26:38134:0:1
Test project creates and saves chart to chartX.bmp file in separate thread in loop and compare this resulted file with "base" file chart.bmp. If ok - it generates this file again and check again.. When files are different - message will be shown
This is short description of how we use TeeChart in this project:
Code: Select all
TTester = class(TThread)
procedure Execute(); override;
end;
procedure CreateChartFile(ATitle: String; const AFileName: WideString);
var
Chart: TChart;
Series : TBarSeries;
i: Integer;
Rows: Integer;
ChartWidth, ChartHeight: Integer;
begin
Rows := 20;
ChartWidth := 800;
ChartHeight := 400;
Chart := TChart.Create(nil);
try
Series := TBarSeries.Create(nil);
TBarSeries(Series).BarStyle := bsRectangle;
Chart.LeftAxis.Title.Caption := 'Left Axis';
Chart.AddSeries(Series);
Chart.Legend.TextStyle := ltsPlain;
Chart.Legend.Alignment := laRight;
Chart.Height := ChartHeight;
Chart.Width := ChartWidth;
Chart.Color := clWhite;
Chart.BevelInner := bvNone;
Chart.BevelOuter := bvNone;
Chart.BottomWall.Color := clWhite;
Chart.LeftWall.Color := clWhite;
Chart.Title.Text.Text := ATitle;
with Chart.Title.Font do
begin
Name := 'Arial';
Size := 12;
Style := [fsBold];
end;
// series
Series.Marks.Visible := False;
for i := 0 to Rows - 1 do
Series.Add(i, 'label'+IntToStr(i));
Series.SeriesColor := clBlack;
Series.ColorEachPoint := true;
// here we were trying a couple of another methods to save to bitmap with same result
Chart.SaveToBitmapFile(AFileName);
finally
Chart.Free;
end;
end;
procedure TTester.Execute();
var error: boolean;
begin
// base chart
DeleteFile(AppRoot+'chart.bmp');
CreateChartFile('Test chart', AppRoot+'chart.bmp');
n := 0;
error := false;
try
while (not terminated) do
begin
// delete previous
if (FileExists(AppRoot+'chartX.bmp'))
then ASSERT(DeleteFile(AppRoot+'chartX.bmp'));
// create next
CreateChartFile('Test chart', AppRoot+'chartX.bmp');
// compare
if (not equalfiles(AppRoot+'chart.bmp', AppRoot+'chartX.bmp'))
then
begin
Synchronize(Form1.TesterFailed);
error := true;
break;
end;
inc(n);
end;
finally
if (not error)
then Synchronize(Form1.TesterFinished);
end;
end;