[Solved] OnActiveControlChange in two forms lazarus / 31-LCL ---------------------------------------------------------------------- petevick · 2022-03-25 17:27 In my current project I have two forms, I originally had the Screen.OnActiveControlChange in the main form, but then I needed to add Screen.OnActiveControlChange in the second form as well. But that stops the main form Screen.OnActiveControlChange from working for some reason. Is there some way to have Screen.OnActiveControlChange working in both forms ?? ---------------------------------------------------------------------- Remy Lebeau · 2022-03-25 23:54 You can't have multiple handlers assigned to an event.  But what you can do is design a separate class to act as the main event handler, and then have your Forms register themselves with that class.  That way, when the class gets notified of the event, it can then loop through its registered Forms notifying each one as needed (via a window message, a callback function, whatever you want). ---------------------------------------------------------------------- Sieben · 2022-03-26 00:11 TScreen also provides you with: 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 AddHandlerActiveControlChanged(                                  OnActiveControlChanged: TScreenControlEvent;                                  AsFirst: Boolean=false);    procedure RemoveHandlerActiveControlChanged(                                   OnActiveControlChanged: TScreenControlEvent); This way you can hook sort of an event chain to the OnActiveControlChanged event. Be careful to remove the handler when it's no longer needed or accessible due to destroying the form for instance. ---------------------------------------------------------------------- Remy Lebeau · 2022-03-26 00:23 Quote from: Sieben on March 26, 2022, 01:11:11 amTScreen also provides you with ... Even better.  I wasn't aware those methods exist. Thanks. ---------------------------------------------------------------------- dsiders · 2022-03-26 00:57 Quote from: petevick on March 25, 2022, 06:27:47 pmIn my current project I have two forms, I originally had the Screen.OnActiveControlChange in the main form, but then I needed to add Screen.OnActiveControlChange in the second form as well. But that stops the main form Screen.OnActiveControlChange from working for some reason. Is there some way to have Screen.OnActiveControlChange working in both forms ?? Each form needs to add a handler for its active control change: 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 TScreen.Add HandlerActiveControlChangedTScreen.RemoveHandlerActiveControlChanged  You implement the 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 TScreenControlEvent object procedure passed as the handler routine. There are good examples of its usage in ide/main.pp and components/IdeInspector/maininspector.pas. ---------------------------------------------------------------------- petevick · 2022-03-26 06:27 Thanks for the replies, all very helpful, particularly from dsiders giving the examples which are always really helpful ---------------------------------------------------------------------- petevick · 2022-03-26 16:52 Well that was way easier to implement than I thought it was going to be, but could not have done it without those examples that dsiders pointed to. Many thanks again to all who replied.  Marked as solved.