Recent

Author Topic: Cannot Focus a Disabled or Invisible Window  (Read 555 times)

Weitentaaal

  • Full Member
  • ***
  • Posts: 185
Cannot Focus a Disabled or Invisible Window
« on: March 03, 2021, 05:24:38 pm »
Hello Guys :)

i get this Error when i try to SetFocus in OnShow Procedure of My Form.

Should i move this Part out or is there something else i can work with ?

LG loch )
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

Handoko

  • Hero Member
  • *****
  • Posts: 4286
  • My goal: build my own game engine using Lazarus
Re: Cannot Focus a Disabled or Invisible Window
« Reply #1 on: March 03, 2021, 05:40:55 pm »
You can try:
Code: Pascal  [Select][+][-]
  1.   if TheControl.Visible then TheControl.SetFocus;

You didn't show us the code. I had to use my tele-vision eye but the image was blurry due to the weather.

ASerge

  • Hero Member
  • *****
  • Posts: 1796
Re: Cannot Focus a Disabled or Invisible Window
« Reply #2 on: March 03, 2021, 05:42:26 pm »
i get this Error when i try to SetFocus in OnShow Procedure of My Form.
Use ActiveControl := ... instead.

GetMem

  • Hero Member
  • *****
  • Posts: 3355
Re: Cannot Focus a Disabled or Invisible Window
« Reply #3 on: March 03, 2021, 06:01:43 pm »
Form.ActiveControl is the easiest solution, as @ASerge already mentioned. If you have to use SetFocus, always check if the control can receive focus:
Code: Pascal  [Select][+][-]
  1. if Control.CanFocus then
  2.   Control.SetFocus;

Weitentaaal

  • Full Member
  • ***
  • Posts: 185
Re: Cannot Focus a Disabled or Invisible Window
« Reply #4 on: March 04, 2021, 07:31:35 am »
Thanks :)
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

 

TinyPortal © 2005-2018