Recent

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

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
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.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • 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: 2223
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.

balazsszekely

  • Guest
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

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Cannot Focus a Disabled or Invisible Window
« Reply #4 on: March 04, 2021, 07:31:35 am »
Thanks :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

 

TinyPortal © 2005-2018