{"id":247,"date":"2019-08-21T13:11:49","date_gmt":"2019-08-21T19:11:49","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=247"},"modified":"2019-08-17T15:42:19","modified_gmt":"2019-08-17T21:42:19","slug":"embeddedwindowcontrol","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2019\/08\/21\/embeddedwindowcontrol\/","title":{"rendered":"EmbeddedWindowControl"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you&#8217;ve ever used a container control on a layout and then tried to manipulate the controls at runtime with code like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nFor i As Integer = 0 To Self.ControlCount - 1\n  Dim ctrl As Control = Self.Control(i)  \n  \/\/ now manipulate this control or call its methods\nNext<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">you&#8217;ve probably run into the EmbeddedWindowControl<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its what you get when you use a Container Control on a layout either by placing one at design time or dynamically adding one at runtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that you get an EmbeddedWindowControl &#8211; not an instance of the Container you placed there. So any code you use that tests if a control ISA specific instance will fail for your containers. You don&#8217;t get a reference to the instance you get this EmbeddedWindowControl instead. So you cant call any methods you have added to the container control or reference any properties of it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its been most annoying. There have been several requests for something to be done so the container the EmbeddedWindowControl was created from can be accessed. Like <a href=\"http:\/\/feedback.xojo.com\/case\/23030\">this one<\/a> and <a href=\"feedback:\/\/showreport?report_id=4491\">this one<\/a> and <a href=\"http:\/\/feedback.xojo.com\/case\/2722\">this one<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And today, for a project I was working on, I needed this and decided to figure out how to make this possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The result is <a href=\"http:\/\/great-white-software.com\/miscellaneous\/EmbeddedWindowControlExtensionSample.xojo_binary_project\">this little sample program<\/a> with one module that extends EmbeddedWindowControl in a way you can get the container control that the embedded window control was created from.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To make use of this simply copy the EmbeddedWindowControlExtensions module into your project. Then when you iterate a set of controls on a layout you can do<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>For i As Integer = 0 To Self.ControlCount - 1\n  \n  Dim ctrl As Control = Self.Control(i)\n  \n  If ctrl IsA EmbeddedWindowControl Then\n    \n    Dim cc As ContainerControl = EmbeddedWindowControl(ctrl).Container \n    \n    If cc &lt;> Nil Then\n      \/\/ you now have an actual reference to the container control\n      \/\/ so you can use its methods, properties, etc\n      \/\/ but you will need to cast it first\n    End If\n    \n  End If\n  \nNext<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enjoy !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever used a container control on a layout and then tried to manipulate the controls at runtime with code like you&#8217;ve probably run into the EmbeddedWindowControl Its what you get when you use a Container Control on a layout either by placing one at design time or dynamically adding one at runtime. Note &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/08\/21\/embeddedwindowcontrol\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;EmbeddedWindowControl&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"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_post_was_ever_published":false},"categories":[1],"tags":[27,6,3],"class_list":["post-247","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-advanced-techniques","tag-tips","tag-xojo"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=247"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}