[fpc-pascal] Assign() vs AssignTo()

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Feb 11 16:13:22 CET 2016


Hi,

In TPersistent, we have two virtual methods. Assign() which calls
AssignTo().

1) Why are they both virtual? It seems like Assign() is what I call a
template method, farming its work out to other helper methods - in this
case, AssignTo(). Normally template methods are not virtual, but their
helper methods (the ones doing the actual work) are. So again, why is
Assign() virtual?

2) Now seeing that both are virtual, and that is probably not going to
change in the RTL, which method is the preferred method to override so
you have the ability to do MyObject.Assign(MySource)? I've been
overriding Assign(), but thinking that maybe I should have overridden
AssignTo() instead.


ps:
The FPC (pdf) documentation for TPersistent.Assign() has a "See Also"
reference to TPersistent.AssignTo(). But that link doesn't work, because
AssignTo is Protected, and the RTL documentation doesn't include
Protected methods.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list