Am 29.11.2019 um 01:01 schrieb Ryan Joseph via fpc-pascal:

function CopyList (source: TFPSList): TFPSList;
begin
   result := TFPSList(source.ClassType.Create);
   result.Assign(source);
end;
This can't work. ClassType is of type TClass and TClass.Create calls TObject.Create, *not* the constructor of your list type, cause the constructor chain is not virtual.

What you can do is this:

=== code begin ===

generic function CopyList<T: TFPSList> (source: T): T;
begin
  result := T.Create;
  result.Assign(source);
end;

var
  a, b: TNodeObjectList;
begin
  a := TNodeObjectList.Create;
  b := specialize CopyList<TNodeObjectList>(a);
end.

=== code end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to