[fpc-pascal] Generic a "Clone" method
JoshyFun
joshyfun at gmail.com
Tue Jun 16 16:49:02 CEST 2009
Hello FPC-Pascal,
Tuesday, June 16, 2009, 2:27:07 PM, you wrote:
TBC> Martin Friebe wrote:
>> There is Object.InstanceSize, which sounds as if it may be what you
>> are looking for.
>> But you have a bigger problem than that.
TBC> Thanks - i'll try that.
From my point of view a generic clone method can not and must not be
written, but for your purposes, this means your own classes, you can
derive a "TClonableObject" from "TObject" and use it for the new
classes, this function must be virtual, so you can specialize the
default clone method in each class when ref counted variables are
present or custom records, arrays, etc and of course alloc'ed
pointers. Something like:
function TClonedClonedObject.Clone(): TClonableObject;
begin
Result:=Inherited Clone();
//Now fixup the ref.counted strings in example, but
//you must use pointers to avoid automatic string dispose.
end;
For sure it is not a generic function ;)
--
Best regards,
JoshyFun
More information about the fpc-pascal
mailing list