{"id":888,"date":"2020-11-23T02:35:06","date_gmt":"2020-11-23T01:35:06","guid":{"rendered":"https:\/\/www.kassebaum.eu\/?p=888"},"modified":"2020-11-23T02:35:06","modified_gmt":"2020-11-23T01:35:06","slug":"did-you-know-9","status":"publish","type":"post","link":"https:\/\/www.kassebaum.eu\/blog\/2020\/11\/23\/did-you-know-9\/","title":{"rendered":"Did you know\u2026?"},"content":{"rendered":"<p>Did you know that you can get and set events with the TMethod record? Let&#8217;s assume you would like to hook an OnClose event of a form:<\/p>\n<pre class=\"lang:delphi decode:true  \" title=\"Definition of a TMethod\">type\r\n  TMyHookObject = class\r\n  strict private\r\n    FOldOnClose: TMethod;\r\n    procedure OnClose(ASender: TObject; var AAction: TCloseAction);\r\n...\r\n\r\nprocedure TMyHookObject.Init(AForm: TForm);\r\nbegin\r\n  \/\/Save the old event\r\n  FOldOnClose := TMethod(AForm.OnClose);\r\n  \/\/Set the new one\r\n  AForm.OnClose := OnClose;\r\nend;\r\n\r\nprocedure TMyHookObject.OnClose(ASender: TObject; var AAction: TCloseAction);\r\nbegin\r\n  \/\/Call the old event\r\n  if Assigned(FOldOnClose.Data) and Assigned(FOldOnClose.Code) then\r\n    TCloseEvent(FOldOnClose)(ASender, AAction);\r\n  \r\n  \/\/Run your own code\r\n  ...\r\n<\/pre>\n<p>As you can see in the example you can easily store and call events with the help of TMethod.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you know that you can get and set events with the TMethod record? Let&#8217;s assume you would like to hook an OnClose event of a form: type TMyHookObject = class strict private FOldOnClose: TMethod; procedure OnClose(ASender: TObject; var AAction: &hellip; <a href=\"https:\/\/www.kassebaum.eu\/blog\/2020\/11\/23\/did-you-know-9\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-888","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/comments?post=888"}],"version-history":[{"count":3,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/888\/revisions"}],"predecessor-version":[{"id":891,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/888\/revisions\/891"}],"wp:attachment":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/media?parent=888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/categories?post=888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/tags?post=888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}