Recent

Author Topic: Wrong Focus on Form  (Read 1233 times)

Tirans

  • New Member
  • *
  • Posts: 11
Wrong Focus on Form
« on: April 13, 2021, 12:11:45 pm »
Hello, i was making a database type project and i wanted to add a feature where you can go to next/prev object using arrowkeys, but the problem is that I have Buttons for that aswell and whenever i launch my code it sets the focus to Button1 and my procedure for FormKeyDown does not work, it just shuffles between the buttons.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Wrong Focus on Form
« Reply #1 on: April 13, 2021, 12:17:39 pm »
Have you set KeyPreview of the form to True?

Also, you may want to see how Actions work for these. Depending on your design it might be a better solution than using OnKeyDown.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Tirans

  • New Member
  • *
  • Posts: 11
Re: Wrong Focus on Form
« Reply #2 on: April 13, 2021, 12:26:37 pm »
Oh wow that was an easy Fix, thank you very much. What did you mean by "actions" i did a quick google search couldnt find much info on it.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1111
  • Professional amateur ;-P
Re: Wrong Focus on Form
« Reply #3 on: April 13, 2021, 12:35:44 pm »
Hey Tirans,

Oh wow that was an easy Fix, thank you very much. What did you mean by "actions" i did a quick google search couldnt find much info on it.

On the component palette, Tab Standard, First from the Right: TActionList.
Drop one of those on your form and right-click to access Action Editor.

There are lots of components that accept a TAction on their properties: Property Action, right at the top.
Things like Buttons, Menus, etc.

This helps you with having a single place to have code and then have a menu and a button have the same action.
And you can set: Caption, Font, Hint, ...., Short-Cut, that will then be automatically replaced on the button or menu.

That's how you do to have a menu and a button on a toolbar do the same thing and respond to the same short-cut, like say: Open (Ctrl+O)

Nice hum?

Cheers,
Gus
« Last Edit: April 13, 2021, 12:37:30 pm by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Wrong Focus on Form
« Reply #4 on: April 13, 2021, 04:28:47 pm »
What did you mean by "actions" i did a quick google search couldnt find much info on it.

Not much info but see in the wiki: TAction.

A handy explanation, though for Delphi: Dr.Bob on Delphi Actions and Action Lists. Google "Delphi TAction" for more.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Tirans

  • New Member
  • *
  • Posts: 11
Re: Wrong Focus on Form
« Reply #5 on: April 13, 2021, 06:19:10 pm »
Thanks guys, I will definetly look into this one.

 

TinyPortal © 2005-2018