Page 1 of 1

FMX TChartListBox not working

Posted: Sat Apr 30, 2022 4:16 pm
by 16591331
I attached two zip files, one for a VCL app and one for a FMX app. Both apps were set up the same way. Basically they have a TChart set up with three Line Series using random data (added with the TChart editor with no other changes). There is also a TChartListBox with the "Chart" field set to the TChart, which should allow clicking a series shown in the listbox to show/hide the individual series in the TChart. Note: I did not include the Fast4MM files in the attached zip files. Remove the line for Fast4MM from the project source if you don't have copies of those files.

If you run the VCL app, everything works as expected. Clicking a Series checkbox in the TChartlistBox shows/hides the Series in the TChart as the checkboxes are checked/unchecked. There are also no memory leaks with the VCL version.

However, if you run the FMX version, multiple things occur:
1. Changing the checkboxes in TChartListBox has no affect on the Series being displayed in the TChart. The image below shows the FMX version with all three series unchecked, but they still show in the chart. The VCL version shows Series1 unchecked and it doesn't appear in the chart.
Images.png
Images.png (80.85 KiB) Viewed 40283 times
2. There is a long gray column to the left of the checkboxes in the FMX ChartListBox. My assumption is this has to do with the Icon property of the list box not being shown correctly. See in the FMX version of the image above.

3. When you close the program down, there is a huge amount of memory that is leaked. It appears the memory leaks are from the TChartListBox not being fully destroyed, as clearing the "Chart" property of the TChartListBox before running the program does not cause memory leaks (this also keeps the Series from showing in the listbox). Also, trying to set the Chart property in code, and then setting it to nil before closing the program still causes the memory leaks.

Am I doing something incorrectly with the FMX version of the TChartListBox? Or are these bugs and the FMX version should work the same as the VCL version?

Note: I am using Delphi 11.1 with patch 1 applied and TeeChart version 2022_35, but the same FMX problems occur with using Delphi 11.1 without the patch and TeeChart version 2021_34.

Re: FMX TChartListBox not working

Posted: Mon May 02, 2022 1:56 pm
by yeray
Hello,

Thanks for the detailed report.
I get slightly different issues here (*) so I'm investigating if there's something I'm missing.

(*) I get an access violation when I connect the TChartListBox to the TChart at design-time and try to run the project. Then, when the IDE returns to the design view, I see it broken:
bds_2022-05-02_15-54-55.png
bds_2022-05-02_15-54-55.png (51.16 KiB) Viewed 40251 times

Re: FMX TChartListBox not working

Posted: Mon May 02, 2022 3:43 pm
by 16591331
Yes the problem only happens when the list box is connected to the chart. I think I was also getting access violations once I added the sample data to the series. But just simply dropping a chart and chartlistbox on the form, connecting the two together, then running the program, without any series configured, causes the memory leaks. The additional problems started appearing when I added the series.

Re: FMX TChartListBox not working

Posted: Tue May 03, 2022 5:00 am
by 16591331
After playing around with the ChartListBox code, I discovered a few things:

1. the memory leaks appear to be due to the way the style is loaded and freed. I changed the following to fix the leaks.
When loading the style, I added a variable to save the Style object returned, then use that variable to free the resource. I also had to remove setting "Chart" to nil in the destructor.

Code: Select all

var
  vResource: TFMXObject = nil;

procedure TChartListBox.FillSeries(const OldSeries: TChartSeries);
...
    if not Assigned(FMX.Types.FindStyleResource(TeeListStyleName)) then
      begin
        vResource := {$IFDEF D20}TStyleStreaming{$ELSE}TStyleManager{$ENDIF}.LoadFromResource(HInstance,TeeListStyle,RT_RCDATA);
       FMX.Types.AddResource(vResource);
       end;
...
end;

procedure FreeListResource;
begin
  if assigned(vResource) then
    vResource.Free;
end;

Destructor TChartListBox.Destroy;
begin
  //Chart:=nil;
  inherited;
end;
2. the access violations you mentioned appear to be due to the adding and removing of the "Listener". From what I can tell, commenting out those lines doesn't appear to have any adverse effect on anything, but I might be missing something.

Code: Select all

procedure TChartListBox.SetChart(const Value: TCustomChart);
begin
  if FChart<>Value then
  begin
    if Assigned(Chart) then
    begin
//      TChartAccess(Chart).RemoveListener(Self);
      Chart.RemoveFreeNotification(Self);
    end;

    FChart:=Value;

    if Assigned(Chart) then
    begin
      Chart.FreeNotification(Self);
//      TChartAccess(Chart).AddListener(Self); //.Listeners.Add(Self);
      FillSeries(nil);
    end
    else
      Clear;
  end;
end;
3. The Gray column in the ChartListBox component during runtime is from the Icon component in the ListBoxItem. Apparently the correct bitmap is not being loaded in the "CheckIcon" routine. Note: did not look father into this, as I don't need that Icon showing.

4. I did find a way to remove/show the series in the Chart when the checkbox is changed in the ChartlistBox. But it wasn't pretty as I used the checkbox tag property to save a pointer to the ListBoxItem it belongs to, which, in turn, provides access to the Series field, which is saved in the ListBoxItem.Data property. I will let you work on a better fix for that one.

Re: FMX TChartListBox not working

Posted: Tue May 03, 2022 4:32 pm
by 16591331
I will have to wait for your fixes to the ChartListBox, as I am still finding problems with the fixes/workarounds I mentioned earlier.

1. if I attach the ChartListBox.Chart property to the TChart during design time, I get errors about duplicate "SeriesItem" names. This appears to be due to the Chart being read in first during loading which calls FillSeries which creates the ListBoxItems in the ChartListBox. Then the ChartListBox component is read in from the form resource, which also has saved the ListBoxItems for the series causing duplicate name errors.

2. I can attach the chart to ChartListBox in FormShow and have everything work great for the Windows 32-bit platform, but the ChartListBox stays blank in the MacOS 64-bit, IOS 64-bit and Android 32-bit platforms. It does appear the ListBoxItems are created for the ChartListBox, but apparently the "chartlistbox" style doesn't get loaded for those 3 platforms so the ListBox items are empty.

3. And as mentioned before, un-commenting the lines that add listeners to the chart, causes too many errors to figure out if that will eliminate some of the problems I see.

Re: FMX TChartListBox not working

Posted: Fri May 13, 2022 2:00 pm
by yeray
Hello Rick,

Excuse us for the delay here.
We've done various changes fixing some of the memory leaks you reported, and adding responsiveness to the TChartListBox.
I'll send you the changes so you can take a look at them. We still find a memory leak but it looks smaller than before.
I'm also sending the style and the resources just in case they got somehow broken.

Re: FMX TChartListBox not working

Posted: Fri May 13, 2022 9:31 pm
by 16591331
The changes your sent me fixed the TChartListBox checkboxes for the Windows 32-bit platform, but there are still other problems. FYI: The Style files you sent match the ones I have, so any problems I report is not due to broken styles.

1. As you mention, there is still a memory leak when using the TChartListBox. As mentioned previously, this memory leak is due to how the "chartlistbox" Style is loaded and freed. I sent you my file that shows how i eliminated the memory leak, but its probably not the correct way to do it.

2. The TChartListbox does not work on Android, Mac and IOS devices. If I attach the TChartListBox "Chart" field to the TChart in code, the Series show up and works in the Listbox on Windows, but the Listbox is blank on the Android, Mac and IOS devices. If I attached the TChartListBox "Chart" field during design time then run the program, Windows works fully, Android will open the graph with a blank Listbox, and the Mac and IOS devices report access violations. I did not try to debug this problem yet.

4. Creating a form with a TChart and a TChartListBox pointing to the chart, but with no series configured, then inheriting that form and adding Series to it, causes problems when trying to open the inherited form during runtime. During design time, the TChartListBox displays the Series correctly in the inherited form, as well as adds the TChartListbox.SeriesItems to the form. But when you try to open the form during runtime, you get a error saying "A component named "SeriesItem1" already exists." and the form is not opened. My guess is there is a conflict between the SeriesItems being loaded from the FMX file during runtime and the logic trying to recreate the SeriesItems when connecting the TChartListbox to the TChart during loading. The fix may be to not store the TChartListBox.SeriesItems in the FMX and just create them as needed but have not tried that.

Re: FMX TChartListBox not working

Posted: Tue May 24, 2022 4:41 am
by yeray
Hello,

It seems like the "normal" way of finding loaded resources (to free them) causes memory leaks. This is probably a bug in RAD Studio so we implemented your workaround of using a variable.

We also fixed the problem with the SeriesItems being loaded at design-time.

I'll send you the latest modifications.

Re: FMX TChartListBox not working

Posted: Wed May 25, 2022 8:41 pm
by 16591331
The changes you sent me appear to fix all the problems but one.

The ChartListBox is still blank on Mac, Android and IOS. The first image below shows the program running on a Windows 10 machine. The second one shows the same program running on my Mac Mini. In both programs, I have selected Series 2 to hide that series in the chart. As you can see, ChartListBox on the Mac appears to contain the three Series ListBoxItems, with the Series2 ListBoxItem selected. And I can show and hide Series2 in the chart by pressing that line repeatedly on the Mac. However, the ListBoxItems on the Mac are blank.

My assumption is this same problem occurs on the Android and IOS devices, but the ListBoxItem lines do not get highlighted on those devices, so I am not sure.

FYI: I used the original source files from the 35 zip file I got from your site, replaced the FMXTee.Chart.ListBox.pas file with the latest one you sent me and then used TeeRecompile.exe to rebuild the source files, so everything should be up to date on my system where Teecharts is concerned.

FMX_Win.png
FMX_Win.png (53.71 KiB) Viewed 39858 times
FMX_MacMini.png
FMX_MacMini.png (135.31 KiB) Viewed 39858 times

Re: FMX TChartListBox not working

Posted: Wed May 25, 2022 9:22 pm
by 16591331
I want to correct one item in my previous post. On the Mac Mini, I am NOT able to show and hide the Series 2 line by clicking on the ListBoxItem line in the ChartListBox. I had additional code added to my test program that was attached to the ListBoxItemClick Event. I was this event that was hiding and showing the Series line, the the checking and checking of the hidden checkbox.