{"id":750,"date":"2011-09-06T09:51:53","date_gmt":"2011-09-05T21:51:53","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=750"},"modified":"2011-09-06T09:57:02","modified_gmt":"2011-09-05T21:57:02","slug":"xe2-firemonkey-designer-clipboard-niggles","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/750\/","title":{"rendered":"XE2 FireMonkey Designer &#8211; Clipboard Gotcha"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\"> 4<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span><p>We are still waiting for our XE2 licenses to be organised but in the meantime I have started playing around with the <a href=\"https:\/\/downloads.embarcadero.com\/free\/delphi\">Free Trial Edition<\/a>.  I haven&#8217;t had much time to form much of an opinion as yet, but have already identified some oddities in the FireMonkey Form Designer, specifically in the area of clipboard support.<br \/>\n<!--more--><br \/>\nAt first I thought the clipboard was completely broken in the FireMonkey designer.<\/p>\n<p>If I created a new FireMonkey application and dropped a few controls on a form and then tried to copy\/paste those controls I simply couldn&#8217;t.  The Cut\/Copy options on the Edit menu were disabled and the keyboard shortcuts didn&#8217;t work.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.24.22-AM.png?resize=398%2C256&#038;ssl=1\" alt=\"Cut\/Copy Disabled\" title=\"Cut\/Copy Disabled\" width=\"398\" height=\"256\" class=\"aligncenter size-full wp-image-752\" srcset=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.24.22-AM.png?w=398&amp;ssl=1 398w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.24.22-AM.png?resize=300%2C192&amp;ssl=1 300w\" sizes=\"auto, (max-width: 398px) 100vw, 398px\" \/><\/p>\n<p>I immediately tried the same thing in the VCL form designer and found that everything was working as expected.  What was going on?<\/p>\n<p>Responses to a Google+ post on the issue varied from those who saw the same thing and those who had no problems, all using the same XE2 build but with a variety of VM solutions.  Eventually these responses pointed me in the direction of the Structure View&#8230; sure enough, I could Cut\/Copy if I first selected the item I wished to Cut\/Copy in the Structure View directly.  Having done that, the Form Designer itself then also became &#8220;enabled&#8221; for Cut\/Copy operations.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.45.58-AM.png?resize=345%2C240&#038;ssl=1\" alt=\"Cut\/Copy Enabled - Structure View\" title=\"Cut\/Copy Enabled - Structure View\" width=\"345\" height=\"240\" class=\"aligncenter size-full wp-image-753\" srcset=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.45.58-AM.png?w=345&amp;ssl=1 345w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.45.58-AM.png?resize=300%2C208&amp;ssl=1 300w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/p>\n<p>This then raised a quirk in behaviour in the FireMonkey designer &#8220;Paste&#8221; operation which probably should be resolved.  To understand this quirk though, let us quickly remind ourselves how the VCL designer has always worked:<\/p>\n<p>In the VCL designer if you copy a control and then paste it back into the form, the new instance becomes selected by default.  This is <strong>A Good Thing<\/strong> &#8211; you almost certainly want to change some properties on the new, pasted instance.  If you then paste more instances, the freshly pasted control is the &#8220;paste context&#8221;.  More often than not this isn&#8217;t important &#8211; most VCL controls cannot act as containers for other controls, so if you paste a <strong>TButton<\/strong> and then paste another <strong>TButton<\/strong>, the designer cannot paste it into the selected <strong>TButton<\/strong> and so the new instance is pasted into the selected button&#8217;s container.<\/p>\n<p>This can be easily seen in action:<\/p>\n<ul>\n<li>Place a <strong>TPanel<\/strong> on a VCL form<\/li>\n<li>Place a <strong>TButton<\/strong> in that panel<\/li>\n<li>Select and copy the button<\/li>\n<li>Paste the button<\/li>\n<\/ul>\n<p>The new button instance is selected by default<\/p>\n<ul>\n<li>Paste again<\/li>\n<\/ul>\n<p>Another new button is pasted with the <strong>TPanel<\/strong> as it&#8217;s parent.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.49.09-AM.png?resize=525%2C385&#038;ssl=1\" alt=\"Pasting Buttons in the VCL Designer\" title=\"Pasting Buttons in the VCL Designer\" width=\"525\" height=\"385\" class=\"aligncenter size-full wp-image-754\" srcset=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.49.09-AM.png?w=525&amp;ssl=1 525w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.49.09-AM.png?resize=300%2C220&amp;ssl=1 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/p>\n<p>When you try to paste into a control that cannot act as a container, the VCL designer try to find the nearest parent that can act as a container and pastes into that.<\/p>\n<p>Now repeat the same steps in the FireMonkey designer:<\/p>\n<ul>\n<li>Place a TPanel on a FireMonkey form<\/li>\n<li>Place a TButton in that panel<\/li>\n<li>Select and copy the button<\/li>\n<li>Paste the button<\/li>\n<\/ul>\n<p>(NOTE: In my case, in order to be able to &#8220;Paste&#8221; I had to first click away from the button, de-selecting it, then click it again in the Structure View to select it once more)<\/p>\n<p>The new button instance is selected by default &#8211; exactly the same as the VCL designer but the parent of the new button is the original button, NOT the panel!<\/p>\n<ul>\n<li>Paste again<\/li>\n<\/ul>\n<p>Another new button is pasted but this time the previously pasted button is the parent.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.48.39-AM.png?resize=489%2C373&#038;ssl=1\" alt=\"Pasting Buttons - FireMonkey\" title=\"Pasting Buttons - FireMonkey\" width=\"489\" height=\"373\" class=\"aligncenter size-full wp-image-755\" srcset=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.48.39-AM.png?w=489&amp;ssl=1 489w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2011-09-06-at-9.48.39-AM.png?resize=300%2C228&amp;ssl=1 300w\" sizes=\"auto, (max-width: 489px) 100vw, 489px\" \/><\/p>\n<p>Crucially this isn&#8217;t immediately apparent because the nature of &#8220;parenting&#8221; in FireMonkey is quite different from that in the VCL &#8211; a parent control does not &#8220;clip&#8221; it&#8217;s children (in the examples I have found so far &#8211; there may be exceptions).  So visually there is nothing to tell you that the pasted buttons are parented by anything other than the panel &#8211; unless and until you move the &#8220;root&#8221; button, at which point the other &#8220;child&#8221; buttons will move also as their positions are relative to their parent, obviously.<\/p>\n<p>This at first appears to be a bug, but I think it&#8217;s more accurate to say it&#8217;s an oversight.  The behaviour (apart from the initial clipboard bug) is essentially the same as that of the VCL designer.  The difference is that any FireMonkey control can be the parent of any other FireMonkey control, so the consequences of assuming the selected control as the &#8220;paste context&#8221; and default selection of any newly pasted control combine to create the potential for unintentional nesting.<\/p>\n<h2>Suggested Fix\/Change in Behaviour<\/h2>\n<p>Given that the &#8220;Parent\/Child&#8221; relationship in FireMonkey is so different, I think the &#8220;Parent&#8221; property of any pasted control should respect and reflect the Parent property on the original Copy (or Cut) control.  That is, if you paste a Control whose parent is &#8220;A&#8221; then it should be pasted with a parent of &#8220;A&#8221;.  A &#8220;Shift&#8221; key modifier could be used to instruct the form designer to ignore the Parent property on the clipboard and instead paste into the currently selected control.<\/p>\n<p>But in the meantime, this is something to be aware of when copy\/pasting in the FireMonkey form designer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\"> 4<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span>We are still waiting for our XE2 licenses to be organised but in the meantime I have started playing around with the Free Trial Edition. I haven&#8217;t had much time to form much of an opinion as yet, but have already identified some oddities in the FireMonkey Form Designer, specifically in the area of clipboard [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4],"tags":[140],"class_list":["post-750","post","type-post","status-publish","format-standard","hentry","category-delphi","tag-xe2-firemonkey"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-c6","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=750"}],"version-history":[{"count":5,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/750\/revisions"}],"predecessor-version":[{"id":758,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/750\/revisions\/758"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}