Recent

Author Topic: TChartImageList clears non-series images  (Read 3466 times)

wp

  • Hero Member
  • *****
  • Posts: 11853
TChartImageList clears non-series images
« on: February 05, 2013, 01:18:09 am »
You recently added a method ReadData to TChartImageList which clears the list. The ImageList had been designed to be able to contain also other images in front of the series icons. With this new method these icons are lost. You mention a memory leak in the svn comments. Is it really necessary to clear the entire list in ReadData in order to avoid this memory leak? Maybe it is sufficient to call ClearAllSeries (instead of Clear) to remove only series icons?

If it is unavoidable to remove icons already existing in the image list the property FirstSeriesIndex should be removed, it would be useless.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TChartImageList clears non-series images
« Reply #1 on: February 05, 2013, 10:49:09 pm »
The attached project demonstrates the issue discussed in the previous topic. ChartImageList1 contains two "stationary" icons (a chart icon to be used for the root of the treeview next to the chart; and two dummy icons), as well as two "dynamic" icons created from the two series of the chart. Because the imagelist is cleared upon reading from the stream in the present implementation the chart icon is not shown.

The two attached patches fix the problem. At first, the SaveData method of the initial submission of TChartImageList is restored; it unlinks the chart from the Imagelist and by this way removes the dynamic icons from the imagelist before writing the stream. Since no series images are stored in the lfm the ReadData method resets the internal series counter after reading the stationary icons.

However, this is not enough -- the program can crash after this modification. The reason is a bug in TCustomImageList which allows to access the zero'th element of an array dimensioned to zero length. This is fixed in the second patch which I just reported to the BugTracker (http://mantis.freepascal.org/view.php?id=23834).

With both patches applied the demo runs fine. Also, there is no memory leak.

Please don't apply the ChartImageList patch before the other patch has been applied by the bug tracker team. I can drop a message here when this has been done.
« Last Edit: February 05, 2013, 10:51:05 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TChartImageList clears non-series images
« Reply #2 on: February 05, 2013, 11:49:43 pm »
Wow that was fast -- the imglist patch has already been applied.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TChartImageList clears non-series images
« Reply #3 on: February 18, 2013, 12:44:07 am »
Sorry, I don't want to be impatient, but is there a problem with the TAChart part of the patch?

 

TinyPortal © 2005-2018