FMX TChartListBox not working

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

FMX TChartListBox not working

Post by Rick » Sat Apr 30, 2022 4:16 pm

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 40546 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.
Attachments
VCL.zip
(1.63 KiB) Downloaded 1822 times
FMX.zip
(1.57 KiB) Downloaded 1811 times

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

Re: FMX TChartListBox not working

Post by Yeray » Mon May 02, 2022 1:56 pm

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 40514 times
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

Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

Re: FMX TChartListBox not working

Post by Rick » Mon May 02, 2022 3:43 pm

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.

Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

Re: FMX TChartListBox not working

Post by Rick » Tue May 03, 2022 5:00 am

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.

Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

Re: FMX TChartListBox not working

Post by Rick » Tue May 03, 2022 4:32 pm

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.

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

Re: FMX TChartListBox not working

Post by Yeray » Fri May 13, 2022 2:00 pm

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.
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

Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

Re: FMX TChartListBox not working

Post by Rick » Fri May 13, 2022 9:31 pm

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.

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

Re: FMX TChartListBox not working

Post by Yeray » Tue May 24, 2022 4:41 am

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.
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

Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

Re: FMX TChartListBox not working

Post by Rick » Wed May 25, 2022 8:41 pm

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 40121 times
FMX_MacMini.png
FMX_MacMini.png (135.31 KiB) Viewed 40121 times

Rick
Newbie
Newbie
Posts: 7
Joined: Fri Jun 04, 2021 12:00 am

Re: FMX TChartListBox not working

Post by Rick » Wed May 25, 2022 9:22 pm

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.

Post Reply