Duplicating a class instance
I’ve run into a strange problem, and I wonder if there is a solution out there.
I have working code that do this
aCopy := TMyClass(Self.ClassType.Create);
The .Create will also eventually call .AfterConstruction – which poses a problem – as I do things in it which basically shouldn’t be done with the copy.
So – I add another constructor to the base class to set a flag to indicate it is a copy – but – how do I invoke the other constructor?
A cast like the one below, is not a viable solution, it seems – as I end up with a nil pointer AV.
aCopy := TMyClass(Self.ClassType).AnotherCreate;
How do I invoke the right constructor in a clean and efficient way?