Issue with Tools

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
spietrek
Newbie
Newbie
Posts: 10
Joined: Wed Sep 22, 2004 4:00 am

Issue with Tools

Post by spietrek » Thu Oct 21, 2004 3:42 pm

I am using TeeChart 7. I would like to copy tools from one chart to another. I believe the code is correct but what happens if the first chart contains 2 tools and the second 0, after adding each tool from the first to the second, the second chart contains 2 tools and the first one contains *none*.

{ Copy over tools }
FGraphParentForm.Chart.Tools.Clear;
for i:= 0 to FGraphParentForm.ChartCubeFacts.Tools.Count-1 do
FGraphParentForm.Chart.Tools.Add(FGraphParentForm.ChartCubeFacts.Tools);

I tried Assign and received AV's the second time through.

Am I doing something wrong? I hope this is possible.

Thanks.

SMP

Pep
Site Admin
Site Admin
Posts: 3273
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Oct 22, 2004 5:19 pm

Hi,
Am I doing something wrong? I hope this is possible.
This is possible, but not using the Assign method. In your code the problem is that you are assign the chart Tools from the Chart1 to Chart2, to have the same Tools in both Chart you will have to create the same Chart tools of the Chart1 for the Chart2 and then add them.

spietrek
Newbie
Newbie
Posts: 10
Joined: Wed Sep 22, 2004 4:00 am

Post by spietrek » Fri Oct 22, 2004 6:08 pm

Pep,

Thanks for the response. However, I'm not sure that will work. I have two charts. One chart contains a list of series matching the numerics my users can select from. For example, Amount, Cost, and Margin. The user can modify the first chart using the chart editor. When the user wants to create a graph, I then take each selected series in the first chart (for example Amount) and create a seperate series for each numeric/customer combination. Therefore, the second chart may contain 30 series if there are 30 customers and the user selected one numeric, 60 series if there are 30 customers and the user selected two numerics, etc.

I do this because users want to be able to save graph settings. I can't have them save numeric/customer series because there are too many plus depending on the data, some customers may be there one time but not other times.

Therefore, I save the first chart. When the user wants to run a graph, I open the first chart, create the series in the second chart based on the numeric series in the first chart, assign chart values (i.e. legend, title, etc.) options.

Since the first chart is the edited one and will contain the tools (either by the using adding/deleting/changing tools from the editor) or from opening a graph, I need to get the tools from chart1 over to chart2.

I was hoping adding them from chart1 to chart2 would work but it just moves them. I am looking for a way to *copy* the tools from one to another.

Maybe I will look into seeing if there is a way to *copy* an entire chart to a new chart. Then I could delete all the series and add them back.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Mon Oct 25, 2004 11:54 am

Hi.
looking for a way to *copy* the tools from one to another
The following code might help you clone only chart tools. But you might have to add additional safeguards if for example a tool is connected to specific series and the destination chart doesn't have this series type.

Code: Select all

Function CloneChartTool(ATool:TTeeCustomTool; AOwner: TComponent):TTeeCustomTool;
begin
  result:=TTeeCustomToolClass(ATool.ClassType).Create(AOwner);
  result.Assign(ATool);
end;

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
  Chart2.Tools.Clear;
  Chart2.Assign(Chart1);
  for i:=0 to Chart1.Tools.Count-1 do
    CloneChartTool(Chart1.Tools[i],Chart2).ParentChart:=Chart2;
  EditChart(Self,Chart2);
end;
Marjan Slatinek,
http://www.steema.com

spietrek
Newbie
Newbie
Posts: 10
Joined: Wed Sep 22, 2004 4:00 am

Post by spietrek » Tue Oct 26, 2004 2:03 pm

Thanks, it worked great.

SMP

Post Reply