In our previous episode, Michalis Kamburelis said: > > - A section about TPersistent.Assign. This is the "basic approach to > cloning" that should probably be shown first. See it here: > http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_cloning_tpersistent_assign
See also http://stackoverflow.com/questions/4041760/correct-way-to-duplicate-delphi-object/4041906#4041906 That is for an own root class and pre class helpers, but you could do it also in or TPersistent helper: type tpersisthelp = class helper for TPersistent function Clone(t: TPersistentClass = nil): TPersistent; end; function tpersisthelp.Clone(t: TPersistentClass = nil): TPersistent; begin if Assigned(t) then Result := t.Create else Result := TPersistentClass(Self.ClassType).Create; Result.Assign(Self); end; Since TComponent declares a virtual destructor that might even be better. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal