2) use of ClassType function for cloning objects
I added two things:

- 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
. I mentioned the special rules when calling the "inherited" from
Assign overrides, and AssignTo, and the fact that TPersistent makes
the default visibility "published".

- And the ClassType, with the example of Clone method using it, is
added at the desciption of "class references" on
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_class_references

Just read your example

|function TMyClass.Clone(AOwner: TComponent): TMyClass; begin // This would always create an instance of exactly TMyClass: //Result := TMyClass.Create(AOwner); // This can potentially create an instance of TMyClass descendant: Result := TMyClassRef(ClassType).Create(AOwner); Result.Assign(Self); end |

|I remember someone once asked whether we should override the method Assign or AssignTo.| |I am worried, choosing the wrong method to override will produce unexpected result.|
||
|Dennis|

||
|
|

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to