Turn visible form to only focusable window lazarus / 31-LCL ---------------------------------------------------------------------- scribly · 2014-01-27 21:28 Him I have an application with multiple windows that the user can normally access randomly But, I have a situation where once an special event happens (Lua hook encounters a line with a breakpoint set), it will wait in the main thread for input before the code continues. During this time I wish to have only one window accessible to the user (other windows could trigger other breakpoints, or just mess with certain lua variables or interfere in other ways I haven't anticipated yet). Right now I have implemented it like this:  (frmLuaCodeAndDebug is the form the user is most likely in at the time) Code: [Select]function luabreakpointHit...  //called when a breakpoint has been hit in the current thread ...       //setting up the debug toolbar        ...       frmLuaCodeAndDebug .visible:=false; //hide it because showmodal complains       frmLuaCodeAndDebug .ShowModal;        //wait till the user presses the button to continue execution (which closes the form for now)       frmLuaCodeAndDebug .show; ... This works fine but causes some obvious blinking. It's not the end of the world, but I would love to be able to do this without having to hide the form to focus it and hide it again to be able to continue ---------------------------------------------------------------------- howardpc · 2014-01-27 21:38 Code: [Select] frmLuaCodeAndDebug.SetFocus; Does this not do what you want? ---------------------------------------------------------------------- scribly · 2014-01-27 21:49 Doing setFocus in a infinite loop together with application.processmessages does come close, but it still seems to allow some button presses in other forms ---------------------------------------------------------------------- howardpc · 2014-01-28 00:13 ShowModal should exclude user interaction with anything outside the modal window (SetFocus only moves the focus momentarily, it does not keep a window focused if something moves the focus elsewhere). I have never used ShowModal in a multi-threaded application, so I don't know if that could be a factor in your complex application, since the LCL is not thread safe. ---------------------------------------------------------------------- scribly · 2014-01-28 00:32 A bit more explenation: frmLuaCodeAndDebug contains an editor and execute button. When the execute button is invoked lua is called which executed the code in the form. This is all done in the main thread. When lua encounters a breakpoint, it calls a breakpoint callback which continues executing the lua code as soon as it exits. So, in order to get a state of the lua interpreter and variables, I need to collect the data in that function, show it to the user, and then wait for the user to determine when to continue and how (Add new bp, or just run til the end) But other windows can also initiate lua code(internally). Because they affect the mainthread lua vmstate they could potentially break the current lua stack by pushing/popping values. The best solution I came up with is making the frmLuaCodeAndDebug modal during debugging (modal at all times isn't really useful as the lua code manipulates existing windows, and it's easier to just switch to that window to confirm the changes, instead of having to close the editor first) But continuing, even to do a single step (bp on next line), causes a flicker in the form, as the form needs to be closed (since it's modal) before the lua code executes till next instruction sequence of clicking the "Debug luascript" button: frmLuaCodeAndDebug.buttonclick(entry)->lua executes code->breakpoint hit->frmLuaCodeAndDebug interaction:step->breakpoint continue->lua executes code->breakpoint hit->frmLuaCodeAndDebug interaction:continue->breakpoint continue->lua executes code->frmLuaCodeAndDebug.buttonclick(exit) Edit: I stumbled upon screen.DisableForms which should do what I want. But for some reason it really break the input of the form. Anyhow, I copied the implementation without the last instruction that disables WidgetSet.AppHandle, and now it works properly