Hi Yeray,
well I could solve one issue
I can copy the settings using RTTI. This code works well:
Code: Select all
procedure CopyObject(ObjFrom, ObjTo: TObject);
var
PropInfos: PPropList;
PropInfo: PPropInfo;
Count, Loop: Integer;
OrdVal: Longint;
StrVal: String;
FloatVal: Extended;
MethodVal: TMethod;
begin
{ Iterate thru all published fields and properties of source }
{ copying them to target }
{ Find out how many properties we'll be considering }
Count := GetPropList(ObjFrom.ClassInfo, tkAny, nil);
{ Allocate memory to hold their RTTI data }
GetMem(PropInfos, Count * SizeOf(PPropInfo));
try
{ Get hold of the property list in our new buffer }
GetPropList(ObjFrom.ClassInfo, tkAny, PropInfos);
{ Loop through all the selected properties }
for Loop := 0 to Count - 1 do
begin
PropInfo := GetPropInfo(ObjTo.ClassInfo, PropInfos^[Loop]^.Name);
{ Check the general type of the property }
{ and read/write it in an appropriate way }
case PropInfos^[Loop]^.PropType^.Kind of
tkInteger, tkChar, tkEnumeration,
tkSet, tkClass{$ifdef Win32}, tkWChar{$endif}:
begin
if UpperCase(PropInfos^[Loop]^.Name) <> 'PARENTCHART' then begin
OrdVal := GetOrdProp(ObjFrom, PropInfos^[Loop]);
if Assigned(PropInfo) then
SetOrdProp(ObjTo, PropInfo, OrdVal);
end;
end;
tkFloat:
begin
FloatVal := GetFloatProp(ObjFrom, PropInfos^[Loop]);
if Assigned(PropInfo) then
SetFloatProp(ObjTo, PropInfo, FloatVal);
end;
{$ifndef DelphiLessThan3}
tkWString,
{$endif}
{$ifdef Win32}
tkLString,
{$endif}
tkString:
begin
{ Avoid copying 'Name' - components must have unique names }
if UpperCase(PropInfos^[Loop]^.Name) = 'NAME' then
Continue;
StrVal := GetStrProp(ObjFrom, PropInfos^[Loop]);
if Assigned(PropInfo) then
SetStrProp(ObjTo, PropInfo, StrVal);
end;
tkMethod:
begin
MethodVal := GetMethodProp(ObjFrom, PropInfos^[Loop]);
if Assigned(PropInfo) then
SetMethodProp(ObjTo, PropInfo, MethodVal);
end
end
end
finally
FreeMem(PropInfos, Count * SizeOf(PPropInfo));
end;
end;
But now there are two problems left and I hope you can help me with that.
1) How can I get the Class of a series?
Example ... Lets say we have a chart with one TFastLineSeries. Now I have to create the series in the target chart first. This can be done with this code:
Code: Select all
var series1: TFastLineSeries;
begin
series1 := TFastLineSeries.Create(nil);
Chart2.AddSeries(series1);
But the is fixed to TFastLine. I need a general procedure for creating the series in the TargetChart. Something like this:
Code: Select all
var series1: TChartSeries;
begin
series1 := TXXXXXXXXXXXSeries.Create(nil);
Chart2.AddSeries(series1);
TXXXXXXXXXXXSeries is the class I need to know.
Could you give me a piece of code which detects the class in the SourceChart and create the same kind of Series in the TargetChart?
2) What´s the best way to copy the data from Sourceseries to the Targetseries? Changing the DataSource isn´t a good solution.
Again I need a general solution to copy the data from series to series - no matter what kind of series I use.
It would be great if you could help me with this two questions.