Recent

Author Topic: [solved]SetFocus Error: SetKeyboardFocus failed  (Read 2922 times)

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
[solved]SetFocus Error: SetKeyboardFocus failed
« on: October 10, 2017, 01:07:38 pm »
I have made a small cross platform app that starts a TrayIcon and then, when the user so clicks, pops up a window or two. In one case the Window is the main unit (that I hide when I start the TrayIcon) and in others, its a Form I create new instances of.

On the Mac, I find that while it works fine from within lazarus (including Run without Debugging) if I launch it outside of Lazarus, the windows that appear do not get focus, I can see them, sometimes behind an existing window but they are inactive and anything I type is directed to the terminal I started from.

I see messages like this at the terminal -
Code: Pascal  [Select][+][-]
  1. TCarbonRadioButton.SetFocus Error: SetKeyboardFocus  failed with result -30585
  2. TCarbonRadioButton.SetFocus Error: SetKeyboardFocus  failed with result -30585
  3. TCarbonBitBtn.SetFocus Error: SetKeyboardFocus  failed with result -30585
Both Linux and Windows work fine.
The forms I create instances of are started like this -
Code: Pascal  [Select][+][-]
  1. EBox := TEditBoxForm.Create(Application);
  2. EBox.Show;
I have added the following to try fix this but no good -
Code: Pascal  [Select][+][-]
  1. EBox.KMemo1.SetFocus;

Do you have any suggestions ?  Its well worth noting I am a real mac newbe ! Don't be afraid to suggest something obvious.

David
« Last Edit: October 10, 2017, 01:25:22 pm by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: SetFocus Error: SetKeyboardFocus failed
« Reply #1 on: October 10, 2017, 01:24:10 pm »
OK, same thing happens with the very minimal button on a blank form app. Clearly I don't know enough about Macs..... So, look a bit closer.

I have made an application bundle, it contains, down a couple if directories, a link back to my binary. So, I find, if I start from the link, it works, if I start directly from the binary, it fails. Hmm.

Anyway, my problem solved....

Macs are a funny beast, they really are !

David
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: [solved]SetFocus Error: SetKeyboardFocus failed
« Reply #2 on: October 20, 2017, 12:21:47 pm »
hi,
i just learned that on Carbon the way applications are run is from the Bundle (app created structure).
so the proper way to run, the one in which you are not getting the error is:

cd myproject
open project1.app

more information in http://forum.lazarus.freepascal.org/index.php/topic,19834.msg113456.html#msg113456
Lazarus 2.0.2 64b on Debian LXDE 10

 

TinyPortal © 2005-2018