2

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:

Working chart

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: Access violation 1

CPU

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?

Rodolfo Donã Hosp
  • 1,037
  • 1
  • 11
  • 23
  • I don't know that, since I haven't been using Delphi 5 in 18 years. Two side nodes, though: since it's so old, you might want to consider upgrading, possibly to FreePascal/Lazarus, which are highly compatible and already way more feature rich, and are free to use). Also, did you know that you can just hit Ctrl+C in a message box like that to copy it's text? Can be handy if you want to google for specific error messages. – GolezTrol Sep 12 '18 at 17:31
  • I actually know about the Ctrl + C on message boxes, but for some reason it didn't work out for me on Delphi, so i had to manually write it, and i tried googling a lot about these kind of error, but as access violations are too generic, i can't seem to find anything on what's probably going on – Rodolfo Donã Hosp Sep 12 '18 at 17:33
  • gj on the question though, there is almost enough to try and replicate it. I have Delphi 10, and try to replicate it. Can you give an example of a value that caused the error? – GolezTrol Sep 12 '18 at 17:36
  • Thank you! Not a specific number, but i tried with 5000, and basically everything above this behaves the exact same – Rodolfo Donã Hosp Sep 12 '18 at 17:39
  • I got it compiling, tried with 2000, 5000, 999999999, and a bunch of values in between. Can't reproduce it. The values seem to be added nicely. At least I don't get an error... Just for the record, I'm on Delphi 10, Seattle Update 1, and I *think* I'm just using the TeeChart that comes with it (didn't install the extended version). – GolezTrol Sep 12 '18 at 17:43
  • But I did notice that the bitmap remains empty. This is probably caused because the bitmap doesn't have width and height (they are 0). I can't see how this would cause your error, but maybe it does in Delphi 5. I added `vBmp.Width := c.Width; vBmp.Height := c.Height;` just before calling PaintTo. Maybe you can try that? – GolezTrol Sep 12 '18 at 17:44
  • I also tried replicating it in Delphi XE7, and the values were added correctly. The problem is that i can't simply migrate since our software is gigantic and with a lot of dependencies. Thank for the bitmap sidenote, worked with normal values, but with higher values the same thing occurs – Rodolfo Donã Hosp Sep 12 '18 at 17:53
  • That sucks. If you can't upgrade, there is probably little you can do apart from debugging your version of TeeChart if you have the source, or do some ugly work-around (like adding a 0 first, if you get an error on the first value). Upgrading is better. Our application (reaching a million lines), has been migrated from D3 to D5, D7, D2007, XE2, XE5 and is now on 10. It's a big step, especially if you have a lot of 3rd party libraries, but it may be worth it, because eventually you'll get stuck if you don't (if only because support is gone). Whatever you do, good luck solving this issue! – GolezTrol Sep 12 '18 at 18:06
  • I tried to reproduce this with Delphi 7 and TeeChart v4.04 and it seems to work fine (after adding the bitmap size as +GolezTrol indicated [above](https://stackoverflow.com/questions/52300563/access-violation-adding-a-value-in-tchart-delphi-component#comment91549320_52300563)) – Yeray Sep 13 '18 at 10:24

0 Answers0