{"id":619,"date":"2020-02-19T20:35:00","date_gmt":"2020-02-20T03:35:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=619"},"modified":"2020-07-07T11:08:46","modified_gmt":"2020-07-07T17:08:46","slug":"iseventimplemented","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2020\/02\/19\/iseventimplemented\/","title":{"rendered":"IsEventImplemented"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In 2019r3 Xojo added something that a lot of people have been asking for for a very long time. A way for a class that exposes events to know IF an instance implements the event. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its literally called IsEventImplemented (see <a href=\"http:\/\/feedback.xojo.com\/case\/58342\">http:\/\/feedback.xojo.com\/case\/58342<\/a>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But it <a href=\"http:\/\/feedback.xojo.com\/case\/58868\">remains undocumented<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Previously if you wrote a class that could have some default behaviour IF an instance did not implemnent the event to alter the behaviour you had no way to know if you should operate in whatever way was the default or not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You could never have your superclass do something like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>If IsEventImplemented(\"Action\") then\n   \/\/ call the instance' code\n   raiseEvent Action\nelse\n   \/\/ do nothing\nend if<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this case its not so bad and you could probably just use RaiseEvent without any impact. But if you wanted to do something more, like know if you should use a default color or not you had a much more difficult task<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ if we had an event ChooseColor that instances could implement or not\n\ndefaultBackGroundColor = raiseEvent ChooseColor\n\n\/\/ if setColor IS implemented we'd get a color \n\/\/ if setColor is NOT implemented we still get a color - its just all 0's\n\/\/ and we have no way to know which is the case \n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But now with IsEventImplemented we could know<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ if we had an event ChooseColor that instances could implement or not\n\nif IsEventImplemented(\"ChooseColor\") then\n   defaultBackGroundColor = raiseEvent ChooseColor\nelse\n   defaultBackgroundColor = &amp;cFF00FF \/\/ or whatever\nend if\n\n\/\/ now we can use defaultBackgroundColor knowing whether \n\/\/ it did or did not come from the instance<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, Xojo has chosen to not document this  (see <a href=\"http:\/\/feedback.xojo.com\/case\/58868\">http:\/\/feedback.xojo.com\/case\/58868<\/a>) <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The comment almost makes it seem as if this method might disappear despite its usefulness whether API 2.0 event have or have not been reverted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use it carefully !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In 2019r3 Xojo added something that a lot of people have been asking for for a very long time. A way for a class that exposes events to know IF an instance implements the event. Its literally called IsEventImplemented (see http:\/\/feedback.xojo.com\/case\/58342) But it remains undocumented Previously if you wrote a class that could have some &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2020\/02\/19\/iseventimplemented\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;IsEventImplemented&#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":[],"class_list":["post-619","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/619","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=619"}],"version-history":[{"count":2,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/619\/revisions"}],"predecessor-version":[{"id":796,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/619\/revisions\/796"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}