Correct way to change BackImage

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
AndyBell
Newbie
Newbie
Posts: 16
Joined: Wed Nov 02, 2022 12:00 am

Correct way to change BackImage

Post by AndyBell » Thu May 18, 2023 9:08 am

Hi

I'm working with some legacy code that was created with TeeChart VCL and C++ Builder V6.

We've upgraded to C++ Builder 11.3 and TeeChart Pro V2022.36.220929...

One of our charts creates a BackImage and sometimes needs to change it and the code that achieves that does the following:

if (Chart->BackImage != NULL)
Chart->BackImage = NULL;

and then creates and assigns a new BackImage.

Most of the time this works, but sometimes it an causes access violation, always with this stack trace:

00e2d029 +00d Operations2022.exe System 19926 +1 TMonitor.Destroy
00e2d014 +014 Operations2022.exe System 19920 +9 TMonitor.Destroy
00e2c809 +029 Operations2022.exe System 18614 +23 TObject.CleanupInstance
00e2c631 +005 Operations2022.exe System 18314 +1 TObject.FreeInstance
01b94f65 +019 Operations2022.exe Madexcept _17445
00f94183 +033 Operations2022.exe Vcl.Graphics 8150 +5 TBitmap.Destroy
00e2c730 +008 Operations2022.exe System 18378 +1 TObject.Free
00f90a6a +00e Operations2022.exe Vcl.Graphics 5951 +1 TPicture.Destroy
013aea89 +021 Operations2022.exe Vcltee Tecanvas.TTeePicture.Destroy
00e2c730 +008 Operations2022.exe System 18378 +1 TObject.Free
00e58780 +008 Operations2022.exe System.SysUtils 27992 +2 FreeAndNil
013ca1e5 +021 Operations2022.exe Vcltee Teeprocs.TCustomTeePanelExtended.SetBackImage

To my mind, the line Chart->BackImage = NULL; looks suspicious but I can't find in the documentation if there is a correct way to remove an existing BackImage and then recreate it...

Any advice would be appreciated.

Andy

Yeray
Site Admin
Site Admin
Posts: 9622
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Correct way to change BackImage

Post by Yeray » Fri May 19, 2023 7:13 am

Hello Andy,

I've just given it a try with the same version, just in a new application with a TChart two buttons and the code below, and it seems to work pefectly:
Project1_2023-05-19_09-15-22.gif
Project1_2023-05-19_09-15-22.gif (61.85 KiB) Viewed 17251 times
Unit1.h:

Code: Select all

#include <VCLTee.TeePNG.hpp>
#include <VCLTee.TeeConst.hpp>
Unit1.cpp:

Code: Select all

#pragma link "VCLTee.TeePNG"
//...
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  this->Caption=TeeMsg_Version;

  Chart1->Walls->Hide();
  Chart1->Axes->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Chart1->BackImage->LoadFromFile("E:\\tmp\\steema.png");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Chart1->BackImage=NULL;
}
If you still find problems with it, could you please try in a new simple example?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

AndyBell
Newbie
Newbie
Posts: 16
Joined: Wed Nov 02, 2022 12:00 am

Re: Correct way to change BackImage

Post by AndyBell » Mon May 22, 2023 8:47 am

Thanks Yeray

I still get the problem occasionally in our legacy app - I'll have to dig into the code more. It doesn't occur in simple demos, unfortunately.

My main question is - is this line Chart1->BackImage=NULL; the 'correct' way to clear the background image? I can't find anything in the documentation...

Andy

AndyBell
Newbie
Newbie
Posts: 16
Joined: Wed Nov 02, 2022 12:00 am

Re: Correct way to change BackImage

Post by AndyBell » Tue May 23, 2023 12:52 pm

Yeray

After a lot of debugging and logging, it seems memory 'near' the object containing the TeeChart had been corrupted, occasionally causing the issue...

Andy

Yeray
Site Admin
Site Admin
Posts: 9622
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Correct way to change BackImage

Post by Yeray » Tue May 23, 2023 12:55 pm

Hello Andy,

Yes, that's the correct way.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply