Unexplained exception "Cannot focus a disabled or invisible window" lazarus / 31-LCL ---------------------------------------------------------------------- vsajip · 2025-06-30 04:08 The attached application has a simple UI with a couple of tabs. It opens on Tab 2: If I click on Tab1, then Tab 2, then Tab 1, then Tab2, I repeatably get the above exception raised in customform.inc at line 1880. It seems to be related to the TFileNameEdit controls, as the call stack suggests it (via TCustomAbstractGroupedEdit): #0 FPC_RAISEEXCEPTION at :0 #1 TCUSTOMFORM.SETACTIVECONTROL(TCUSTOMFORM($00007FE81B676BD0), nil) at customform.inc:1880 #2 TCUSTOMFORM.FOCUSCONTROL(TCUSTOMFORM($00007FE81B676BD0), TWINCONTROL($00007FE81B67D190)) at customform.inc:159 #3 TWINCONTROL.SETFOCUS(TWINCONTROL($00007FE81B67D190)) at wincontrol.inc:5727 #4 TCUSTOMABSTRACTGROUPEDEDIT.DOENTER(TCUSTOMABSTRACTGROUPEDEDIT($0000 7FE81B6A9390)) at groupededit.pp:944 #5 TWINCONTROL.CMENTER(TWINCONTROL($00007FE81B6A9390), TLMESSAGE (45082; 354241624; 0; 0; 0)) at wincontrol.inc:8424 #6 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal+170 at :0 #7 TCONTROL.WNDPROC(TCONTROL($00007FE81B6A9390), TLMESSAGE (45082; 354241624; 0; 0; 0)) at control.inc:2304 #8 TWINCONTROL.WNDPROC(TWINCONTROL($00007FE81B6A9390), TLMESSAGE (45082; 354241624; 0; 0; 0)) at wincontrol.inc:5474 #9 TCONTROL.PERFORM(TCONTROL($00007FE81B6A9390), 45082, 0, 0) at control.inc:1625 This happens with Lazarus 4.0 on Linux Mint 64-bit using GTK2 widgets. Can anyone else reproduce this in a similar environment? It seems like a bug, as the attached reproducer has no code that I've written other than just putting the LCL controls together. ---------------------------------------------------------------------- EganSolo · 2025-06-30 07:27 I don't know if that's related, but when I opened your project, Laz complained that it couldn't load rdclazcomp package. Your code doesn't seem to use it, so I removed the dependency. When I ran your code, I didn't see any exception while switching between Tab1 and Tab2. I don't know if that's related to the missing package or something else. Which OS are your running under? I'm on Windows 11 ... ---------------------------------------------------------------------- vsajip · 2025-06-30 07:50 QuoteLaz complained that it couldn't load rdclazcomp package That package is used by the real application where the problem occurred, but not in the minimal reproducer. So it's fine to remove the dependency. QuoteWhich OS are your running under? As I mentioned, Linux Mint 64-bit using GTK2 widgets. QuoteI don't know if that's related to the missing package or something else. My guess is that's it's widget implementation related, so one wouldn't necessarily expect the same behaviour on Windows. But thanks for looking into it! ---------------------------------------------------------------------- bytebites · 2025-06-30 10:19 I tested with Lazarus trunk-version and it has same bug. ---------------------------------------------------------------------- n7800 · 2025-06-30 14:33 Checked trunk on Ubuntu gtk2 - error, in qt5 everything is fine. Out of curiosity, I checked older versions, up to Lazarus 2.2.0 - the error is still there. Looks like a long-standing problem. I tried to shorten the author's project example, and in the end there was only TPageControl with TFileNameEdit and TEdit. Apparently, the problem is really in the TCustomAbstractGroupedEdit class. For example, instead of TFileNameEdit there can be TListFilterEdit and any other of its descendants. When I searched on the bug tracker, I found an existing issue #31142 from 2016 year. It describes the same minimal example. ---------------------------------------------------------------------- etrusco · 2025-06-30 23:31 A related symptom is that every time the tab is switched, the focus is shifted to the next TGroupBox. Maybe it`s indeed related to TGroupedEdit, but TPageControl also seems to have its fair share of bugs in GTK2. ---------------------------------------------------------------------- vsajip · 2025-07-02 20:08 QuoteMaybe it`s indeed related to TGroupedEdit, but TPageControl also seems to have its fair share of bugs in GTK2. No doubt, but I was able to get rid of the problem in my application by replacing TFileNameEdit with a much simpler component based on a TPanel wrapping a TEdit and a TButton. It's good enough for my use case.