View Issue Details

IDProjectCategoryView StatusLast Update
0032365PackagesTAChartpublic2017-09-11 13:52
Reportermig-31 Assigned Towp  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
PlatformAllOSAll 
Product Version1.8RC4 
Target Version1.8 
Summary0032365: Propose to expand TChart.Clone to set a new Parent and Owner
DescriptionExits function TChart.Clone create a copy of existing TChart on the Parent with same Owner as original TChart.

Propose:
I propose to add a procedure TChart.Clone(AOwner,AParent : TComponent);

NewParent enables to show a copy of TChart on other TComponent.
NewOwner enables to copy TChart on Form1 to Form2.

Steps To Reproduceprocedure TChart.Clone(AOwner,AParent : TComponent);
var
  ms: TMemoryStream;
  cloned: TComponent = nil;
begin
  ms := TMemoryStream.Create;
  try
    WriteComponentToStream(ms, Self);
    ms.Seek(0, soBeginning);

    ReadComponentFromBinaryStream(
      ms, cloned, @FindComponentClass, AOwner, AParent, Owner);
  finally
    ms.Free;
  end;
end;

TagsNo tags attached.
Fixed in Revision55780
LazTarget1.8
Widgetset
Attached Files

Activities

wp

2017-09-01 11:15

developer   ~0102552

Could you attach a little demo to verify that your patch is working?

mig-31

2017-09-01 14:07

reporter  

TChartCloneDemo1.zip (4,169 bytes)

mig-31

2017-09-01 14:11

reporter   ~0102563

I added a little demo and tested it under Lazarus 1.6.4 Win 32-bit(Windows 7) and Linux 64-bit(CentOS7) Qt4 Widget.

Modification of unit TAGraph

procedure Clone(AOwner, AParent : TComponent); overload;

procedure TChart.Clone(AOwner,AParent : TComponent);
var
  ms: TMemoryStream;
  cloned: TComponent = nil;
begin
  ms := TMemoryStream.Create;
  try
    WriteComponentToStream(ms, Self);
    ms.Seek(0, soBeginning);

    ReadComponentFromBinaryStream(
      ms, cloned, @FindComponentClass, AOwner, AParent, Owner);
  finally
    ms.Free;
  end;
end;

wp

2017-09-01 16:04

developer   ~0102566

Thanks.

I extended the demo a bit to show that ChartTools and ChartStyles are working in the clone like in the original chart. I also added a series at runtime, and this is what makes me think a bit: If the series gets its data from a ChartSource the series in the cloned chart works fine. But if its data are added at runtime to the internal ListSource of the series, then the cloned series has no data. I also have to think about whether the series really is a clone because my code creates the series as being owned by Form1.

There's another possible problem which probably is not seen in your example in which the original chart is owned by the main form. Suppose the original chart is owned and parented by Form2, and depends on ChartTools, -Styles and/or -Transformations sitting on Form2 as well. Now, when the chart is cloned into another form, Form3, everything should work fine because the links to these subsidiary components are copied correctly - we see this in the present demo. But what happens with the cloned chart if Form2 is destroyed. I don't think that the program will crash, but the chart will not function like its origin any more because these linked components are gone.

I could imagine that this could cause some confusion - it is an extreme example, though.

wp

2017-09-03 13:38

developer   ~0102610

OK, I applied the patch (slightly modified). Please test and close if ok.

mig-31

2017-09-11 12:09

reporter   ~0102775

Patch is ok.

Our patch enables to show cloned TChart on new Parent and change it owner.

But it's not a "full copy" of TChart. As you mention above the owner of Series, Series.ListSource, Series.Styles is owned still by Form1.

Should I close this issue and open a new one to implement a "full copy" of TChart?

wp

2017-09-11 12:34

developer   ~0102776

If you already have a solution just repopen this report and attach the new patch.

mig-31

2017-09-11 13:52

reporter   ~0102777

Now I don't have. I close it for now.

Issue History

Date Modified Username Field Change
2017-09-01 10:32 mig-31 New Issue
2017-09-01 10:32 mig-31 Status new => assigned
2017-09-01 10:32 mig-31 Assigned To => Alexander S. Klenin
2017-09-01 11:15 wp Note Added: 0102552
2017-09-01 11:15 wp Assigned To Alexander S. Klenin => wp
2017-09-01 14:07 mig-31 File Added: TChartCloneDemo1.zip
2017-09-01 14:11 mig-31 Note Added: 0102563
2017-09-01 16:04 wp Note Added: 0102566
2017-09-03 13:38 wp Fixed in Revision => 55780
2017-09-03 13:38 wp LazTarget => 1.8
2017-09-03 13:38 wp Note Added: 0102610
2017-09-03 13:38 wp Status assigned => resolved
2017-09-03 13:38 wp Resolution open => fixed
2017-09-03 13:38 wp Target Version => 1.8
2017-09-11 12:09 mig-31 Note Added: 0102775
2017-09-11 12:34 wp Note Added: 0102776
2017-09-11 13:52 mig-31 Note Added: 0102777
2017-09-11 13:52 mig-31 Status resolved => closed