procedure of object of object? lazarus / 62-General ---------------------------------------------------------------------- Edson · 2017-02-23 17:11 I would like yo use a event handler declared nested in a procedure: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Foo;   procedure Bar;  begin  end; begin  ...   SomeObject.OnEvent := @Bar;  //????  ...end; Is it possible? This doesn't work: TMyEvent = procedure of object of object; ---------------------------------------------------------------------- marcov · 2017-02-23 17:13 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  {$modeswitch nestedprocvars}type teventtype = procedure is nested; ---------------------------------------------------------------------- Edson · 2017-02-23 17:35 Quote from: marcov on February 23, 2017, 06:13:35 pm Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  {$modeswitch nestedprocvars}type teventtype = procedure is nested; Thanks. Sometimes FPC surprises me. ---------------------------------------------------------------------- Jonas Maebe · 2017-02-23 18:36 Note that this is very dangerous. As soon as the outer procedure is exited, the procedural variable (which is the generic term for what you call an event handler) will become invalid. The reason is a nested procedure has access to the context of the outer procedure, and when the outer procedure exits this context gets destroyed (and hence becomes invalid). ---------------------------------------------------------------------- Edson · 2017-02-23 20:44 OK. I see it's dangerous. Maybe only useful for events of local objects.