Recent

Author Topic: TChartGrid  (Read 16711 times)

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TChartGrid
« Reply #15 on: December 13, 2011, 09:21:54 am »
All your components using TIndexedComponent/TIndexedComponentList override the method GetChildren, e.g. in TATools:

Code: [Select]
procedure TChartToolset.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
  t: TChartTool;
begin
  for t in Tools do
    if t.Owner = Root then
      Proc(t);
end;

Who is Root, and where in TATools is it assigned? I think that when Root is not set properly the streaming mechanism for the children will fail.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TChartGrid
« Reply #16 on: December 13, 2011, 01:05:40 pm »
Root is the second argument of this method, so it is assigned by the caller.
(This is why I always start argument names with "A").

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TChartGrid
« Reply #17 on: December 13, 2011, 01:40:46 pm »
Sure - that's clear. But who is Root at the time when the method is called by the streaming mechanism? Is it the ChartToolset itself? Or the form?

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TChartGrid
« Reply #18 on: December 13, 2011, 04:14:56 pm »
Sorry, the entire thread must be very confusing...

I wrote a stripped-down version of the demo program which contains only the relevant streaming code. (Just run the project, no installations needed).

TBasicSeriesLink inherits from TIndexedComponent and is stored in a TSeriesLinkList which, in turn, inherits from TIndexedComponentList. TChartLink is the main component which administrates the series links.

When a chart is assigned to the ChartLink, a BasicSerieslink is created for each series and stored in the link list. This is done during FormCreate of the demo project.

Clicking on the button "write lfm" initiates writing of the form to a stream which is displayed immediately in a memo. At the end of the memo you will see ChartLink. However, the SeriesLinks are not shown. I would expect them to appear as children of the ChartLink.

Without the SeriesLinks, the columns of the ChartGrid in the full version are not persistent.

You are applying TIndexedComponent and TIndexedComponentList throughout the TAChart library in several places, and I duplicated all the virtual procedures. But something must be missing...

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TChartGrid
« Reply #19 on: December 13, 2011, 10:56:41 pm »
Oh - adding the SeriesLink to the list was missing in this stripped-down demo:

Code: [Select]
procedure TChartLink.SetChart(AValue: TChart);
var
  i: Integer;
  link: TBasicSeriesLink;
begin
  if AValue = FChart then exit;
  FChart := AValue;
  SeriesLinks.Clear;
  if FChart = nil then exit;
  for i:=0 to FChart.SeriesCount-1 do begin
    link := TBasicSeriesLink.Create(self);
    link.ChartLink := self;  // <-- this was missing
    link.Series := TCustomChartSeries(FChart.Series[i]);
  end;
end; 

But nevertheless, still no SeriesLinks as children of the ChartLink in the memo... How can I achieve that ChartLink streams the FLinkList?

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TChartGrid
« Reply #20 on: December 16, 2011, 01:49:23 pm »
I found a way that ChartLink streams the SeriesLinks: In the method GetChildrenProc, the parameter Root seems to point to the form, not the ChartLink itself. The following code writes the ChartLinks to the lfm file correctly:

Code: [Select]
procedure TChartLink.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
  link: TBasicSeriesLink;
  i: Integer;
begin
  for i:=0 to SeriesLinks.Count-1 do begin
    link := SeriesLinks[i];
//    if link.Owner = Root then   --> not working
    if link.Owner = self then
      Proc(link);
  end;
end; 

Now I can continue with the ChartGrid.

 

TinyPortal © 2005-2018