I'm trying to use TChart component to export a graph to a bitmap file, but i got to a very odd error.
Everytime i try adding a value to the chart, i call the AddY
function from the TLineSeries
component passing the value as a parameter. When i try adding small values, the graph behaves completely normal as shown:
The problem happens when i try adding some big value at it's first point, i get an access violation like this:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00450047 in module 'Project1.exe'. Write of address 022AC000'. Process stopped. Used Step or Run to continue.
And the callstack is completely empty, the only line there is the name of my project, and the highlighted line is the "end" of my dpr file.
As i keep pressing ok other erros pops up:
As i'm not skilled enough with those errors, i didn't manage to debug exactly what's going on, i presume its some sorte of corrupted heap, but i can't seem to find out where, since the code is so simple and the component has it's code hidden because it's a third party component.
The funny part is that if i just click ok until the errors are gone and add another value, it shows normally, as well as adding some small value first, and then a big value (by big i don't know exactly the number, but 2000+ starts happening this)
I isolated the TChart from my main software and build a snippet just to test things out, and here's the simple code i'm running:
procedure TdesktopForm.Button1Click(Sender: TObject);
var
vBMP: TBitmap;
begin
vBMP := TBitmap.Create();
try
config();
c.series[0].AddY(StrToFloat(edit.text));
c.PaintTo(vBMP.Canvas.Handle, 0, 0);
vBMP.SaveToFile('D:\test.bmp');
finally
vBMP.Free();
end;
end;
Where c
is my visually added TChart
component, edit
is just a visual TEdit
to manipulate what i'm adding and config
is a method to configure visual stuff on the graphic with the following code:
procedure TdesktopForm.config();
begin
c.Height:=200;
c.Width:=200;
c.LeftAxis.LabelsFont.Size:=13;
c.BottomAxis.LabelsFont.Size:=13;
c.MarginBottom:=20;
c.MarginTop:=10;
c.LeftAxis.StartPosition:=10;
c.LeftAxis.EndPosition:=90;
c.BottomAxis.LabelsAngle:=0;
c.BottomAxis.Grid.Color:=clBlack;
c.LeftAxis.Grid.Color:=clBlack;
c.BottomAxis.Ticks.Color:=clBlack;
c.LeftAxis.Ticks.Color:=clBlack;
c.LeftAxis.MinorTicks.Color:=clBlack;
c.BottomAxis.MinorTicks.Color:=clBlack;
c.BottomAxis.LabelsMultiLine:=True;
c.BottomAxis.DateTimeFormat:='DD/MM/AAAA hh:mm:ss';
c.BottomAxis.StartPosition:=10;
c.BottomAxis.EndPosition:=90;
c.View3D:=False;
c.Color:= clWhite;
c.Legend.Visible:=False;
c.Series[0].Marks.Visible:=true;
c.Series[0].Marks.Transparent:=false;
c.Series[0].Marks.Style:= smsValue;
c.Series[0].Marks.Frame.Visible:=True;
c.Series[0].Marks.Frame.Color:=clBlack;
c.Series[0].Marks.BackColor:=clWhite;
c.Series[0].Marks.Font.Size:=12;
c.Series[0].Marks.Font.Color:=clBlack;
end;
If it wasn't strangely enough, all of the tests above was using the "Line series", if i try the same thing with Bar series for example, everything works completely normal, i tried adding some absurd values like 999999999 and no errors were raised.
All of the above was using Delphi 5, as my main software is built on Delphi 5.
Does anyone have an idea of what's going on?