On Thursday 11 February 2016 16:13:22 Graeme Geldenhuys wrote: > 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? > If one wants to transfer property values from "source" to "dest" one calls "dest.assign(source)". If "dest" does not know how to handle "source" it calls "source.assignto(self)".
> 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. > It depends on what knows to handle what. Sometimes both have to be overridden. Martin _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal