Lazarus

Programming => LCL => Topic started by: Weitentaaal on March 03, 2021, 05:24:38 pm

Title: Cannot Focus a Disabled or Invisible Window
Post by: Weitentaaal 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 )
Title: Re: Cannot Focus a Disabled or Invisible Window
Post by: Handoko 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.
Title: Re: Cannot Focus a Disabled or Invisible Window
Post by: ASerge 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.
Title: Re: Cannot Focus a Disabled or Invisible Window
Post by: GetMem 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;
Title: Re: Cannot Focus a Disabled or Invisible Window
Post by: Weitentaaal on March 04, 2021, 07:31:35 am
Thanks :)
TinyPortal © 2005-2018