I was wondering, is there anything in the RTTI of Delphi that will do the same as MemberwiseClone does in C# for the simple implementation of the prototype pattern. I saw so
There's nothing built in that will perform a deep-clone for you. I'm sure you could write a deep-clone based on the new RTTI, but I'd expect it to be a non-trivial amount of work.
If you were dealing with simple enough types it would work fine, but you could easily run into serious challenges. For example, off the top of my head:
You could implement your prototype pattern by defining a basic Clone()
method which uses RTTI for simple types and then you have to override it for anything more complex. Personally though, I'd inherit from TPersistent
and make my Clone()
method based on Assign
.