Author: Vsevolod L1433
I’ve got a task of cloning FireMonkey objects. Let it be “chess”. An object is created as an aggregate in design-time. Look at the picture in the Structure pane. I have made the composite pawn model and start thinking of make 15 more.
If you’re thinking of a similar method, please, try Clone method. It will help you clone any FireMonkey object, not necessarily pawns, 3D primitives, but also controls. The only hint you need to know is that the only property “Parent” is not cloned, not to trigger rebuilding of the scene. Very often cloning should be done “purely-in-memory” with no consequences to the visual interface and corresponding times to draw.
The code shows how to do clones:
1 2 3 4 5 6 7 8 9 |
<span style="font-weight:bold;color:#000000;">var</span><br> tmp <span style="color:#000066;">:</span> TDummy<span style="color:#000066;">;</span><br> <span style="font-weight:bold;color:#000000;">begin</span><br> <span style="font-style:italic;color:#808080;">// cloning without visual effects</span><br> tmp <span style="color:#000066;">:</span><span style="color:#000066;">=</span> TDummy<span style="color:#000066;">(</span>duPawn<span style="color:#000066;">.</span><span style="color:#006600;">Clone</span><span style="color:#000066;">(</span><span style="font-weight:bold;color:#000000;">self</span><span style="color:#000066;">)</span><span style="color:#000066;">)</span><span style="color:#000066;">;</span><br> <span style="font-style:italic;color:#808080;">// setting Parent property to see the clone</span><br> tmp<span style="color:#000066;">.</span><span style="color:#006600;">Parent</span> <span style="color:#000066;">:</span><span style="color:#000066;">=</span> <span style="font-weight:bold;color:#000000;">self</span><span style="color:#000066;">;</span> <span style="font-style:italic;color:#808080;">// Dummy1 or any typically parental object</span><br> <span style="font-style:italic;color:#808080;">// don't foreget to change Position (x, y and z)</span><br> <span style="font-weight:bold;color:#000000;">end</span><span style="color:#000066;">;</span> |
Once again, Clone is implemented in TFmxObject (FMX.Types).
Thanks to Eugene Kryukov, FireMonkey architect and my good adviser.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition