Cannot focus a disabled or invisible window


(Rohit Bajaj) #1

Received this error while creating WPF plugin. Traced the error into hydra library source file : UHYVCLCrossPlatformVisualPluginWrapper.pas

Modified the code with additional guard code

procedure THYVCLCrossPlatformVisualPluginWrapper.ShowParented(aParent: TWinControl);

if Ctrl <> nil then begin
if Form.CanFocus then
SetFocus(Form.Handle);

**if Form.Focused then**
  Form.ActiveControl := Ctrl;

end;
end;


(RemObjects) #2

Thanks, logged as bugs://78586


(RemObjects) #3

bugs://78586 got closed with status fixed.


(Rohit Bajaj) #4

This bug still remains as your modification assumes that, if
you call SetFocus(Form.Handle) that the form has focus on it!

You have to check to see if the Form is Focused First (using if Form.Focused) before setting the ActiveControl!

This is the modification I made which gets rid of the error

if Ctrl <> nil then
begin
if Form.CanFocus then
begin
SetFocus(Form.Handle);

  if Form.Focused then
      Form.ActiveControl := Ctrl;
end;

end;


(EvgenyK) #5

what version of Hydra you are using? the latest RTM ?


(Rohit Bajaj) #6

I believe the source we have is for 5.0.91.1169.


(EvgenyK) #7

fixed. next beta will contain if Form.Focused then line