Clone Series from a TmpChart ?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Thu May 14, 2009 11:37 am

I hope the demo has 5 series included (on the left chart).

I have the following series included (in the SourceChart):
- Fast Line
- Area
- Volume
- Error Bar
- Bar 3D

And the Area Series holds some sample values after the application starts.

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

Post by Yeray » Thu May 14, 2009 11:53 am

Hi Dominik,

I've tested with it here again, now in two different computers and I can't get the error. So, please, verify that you have TeeChart 8.04 installed and check that all the search and library paths don't reference old TeeChart installations.

On the other hand, going back to the tmpChart option, I've found how you could free the tmpChart safety (it remained only a tmpChart := nil):

Code: Select all

var Stream: TMemoryStream;
    tmpChart: TChart;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TLineSeries.Create(self));
  Chart1[0].FillSampleValues(25);

  Stream := TMemoryStream.Create;
  SaveChartToStream(TCustomChart(Chart1), Stream, true, false);
end;


procedure TForm1.Button1Click(Sender: TObject);
var SeriesCopy: TChartSeries;
begin
  tmpChart := TChart.Create(self);

  try
    Stream.Position := 0;
    LoadChartFromStream(TCustomChart(tmpChart), Stream);

    SeriesCopy := tmpChart[0];
    SeriesCopy.ParentChart := Chart2;
  finally
    Stream.Free;
    tmpChart := nil;
    tmpChart.free;
  end;
end;
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Thu May 14, 2009 12:02 pm

Hi Yeray,

did you enable the RangeCheck in the Compiler Options?
If I deselect the rangecheck all works fine. With RangeCheck I got the error.

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

Post by Yeray » Thu May 14, 2009 1:04 pm

Hi Dominik,

With your project's default values (Project/Options/Debug Configuration/Runtime errors/Range checking: checked) it seems to work fine.

And unchecking it, or setting Release Configuration, everything still works fine...
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Thu May 14, 2009 1:48 pm

Hi Yeray,

really strange. I got an error as soon as I enable RangeCheck.

I tried your solution with setting the TmpChart to NIL. It works, but the color changes after setting the ParentChart to TargetChart.

Is there any automatically mechanism to change the color if a new series is added? Can I switch off this behaviour during my move operation?

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Fri May 15, 2009 7:38 am

Hi Yeray,

today I did some new tests. I always get the error if ...
- Rangecheck is enabled
- use Project -> Create Project to compile the whole application complete (in german it´s called xxxx erzeugen - Shortcut is SHIFT + F9)
- Start the project and press the Copy Button -> Error.

My Chart has on the left side a horizontal line with 300 points added.

Find the new Upload here:
Received Object RTTI.zip Content Type application/x-zip-compressed Length 143791

Notes:
There is a small mistake of mine ... CopyEg.dpr contains a line " ExceptionLog,". Please remove this before. Sorry about that.

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

Post by Yeray » Fri May 15, 2009 8:16 am

Hi Dominik,

The problem here is that by default there is no color property saved to the series serialization because the chart palette is going to be used. Then, while the series color is the default in the palette, the stream won't save it and it won't be exported so the default in the target chart palette will be used.

I think that you should save the original color series and then force the destination series to take this color (after setting it to clNone to force the change to be applied):

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var SeriesCopy: TChartSeries;
    SeriesColor: TColor;
begin
  tmpChart := TChart.Create(self);

  try
    Stream.Position := 0;
    LoadChartFromStream(TCustomChart(tmpChart), Stream);

    SeriesCopy := tmpChart[1];

    SeriesColor := tmpChart[1].Color;
    SeriesCopy.Color := clNone;
    SeriesCopy.Color := SeriesColor;

    SeriesCopy.ParentChart := Chart2;
  finally
    Stream.Free;
    tmpChart := nil;
    tmpChart.free;
  end;
end;
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Fri May 15, 2009 8:52 am

Hi Yeray,

Code: Select all

    SeriesColor := tmpChart[1].Color; 
    SeriesCopy.Color := clNone; 
    SeriesCopy.Color := SeriesColor;
Well this will work for some series types but not with all. If you use TFastLine you need this code:

Code: Select all

         SeriesColor     := (tmpChart[Serie] as TFastLineSeries).LinePen.color;
         (SerieCopy as TFastLineSeries).LinePen.Color := clNone;
         (SerieCopy as TFastLineSeries).LinePen.Color := SeriesColor;
So could you think about an generic solution which will work with all series types?

And did you try my last demo app (see posting 15 May 2009 07:38)?

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

Post by Yeray » Fri May 15, 2009 10:13 am

moelski wrote:And did you try my last demo app (see posting 15 May 2009 07:38 )?
Ups, excuse me. I think I didn't refresh the page before answering... my fault.
Now I've tested it (and also Narcis) and we don't see any error. Yes, really strange.
moelski wrote:So could you think about an generic solution which will work with all series types?
I'm afraid that there is no generic solution for this. You could test if a series is one type or another and use a casting to copy the particular series properties too:

Code: Select all

if tmpChart[1].ClassType = TFastLineSeries then
  SeriesCopy := tmpChart[1] as TFastLineSeries
else if tmpChart[1].ClassType = TLineSeries then
  SeriesCopy := tmpChart[1] as TLineSeries;

SeriesColor := SeriesCopy.Color;
SeriesCopy.Color := clNone;
SeriesCopy.Color := SeriesColor;

SeriesCopy.ParentChart := Chart2;
I hope this works!
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Fri May 15, 2009 10:16 am

Hi Yeray,

I found this generic solution:

Code: Select all

        SerieCopy := tmpChart[Serie];

        // Farbe merken
        SeriesColor := tmpChart[Serie].Color;

        if IsPublishedProp(TCustomLineSeries(tmpChart[Serie]).LinePen, 'Color') then begin
          SeriesLineColor := GetOrdProp(TCustomLineSeries(tmpChart[Serie]).LinePen, 'Color') ;
        end;

        SerieCopy.ParentChart := TargetChart;

        SerieCopy.Color := clNone;
        SerieCopy.Color := SeriesColor;
        if IsPublishedProp(TCustomLineSeries(SerieCopy).LinePen, 'Color') then begin
          TCustomLineSeries(SerieCopy).LinePen.Color := clNone;
          TCustomLineSeries(SerieCopy).LinePen.Color := SeriesLineColor;
        end;
This works good. I think I still have to make some enhancements, but in general this works good. What do you think about that?

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

Post by Yeray » Fri May 15, 2009 10:22 am

Hi Dominik,

Yes, you solution seems more generic that mine. I'm pleased to see that you made it work.
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Fri May 15, 2009 11:14 am

Hi Yeray,

now I reinstalled TChart completely.
All works fine now. No more Range errors.

Anyway. Thx for your excelent help :)

Post Reply