Lazarus

Programming => General => Topic started by: Tirans on April 13, 2021, 12:11:45 pm

Title: Wrong Focus on Form
Post by: Tirans 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.
Title: Re: Wrong Focus on Form
Post by: lucamar 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.
Title: Re: Wrong Focus on Form
Post by: Tirans 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.
Title: Re: Wrong Focus on Form
Post by: Gustavo 'Gus' Carreno 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
Title: Re: Wrong Focus on Form
Post by: lucamar 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 (https://wiki.freepascal.org/TAction).

A handy explanation, though for Delphi:  Dr.Bob on Delphi Actions and Action Lists (http://www.drbob42.com/delphi4/actions.htm). Google "Delphi TAction" for more.
Title: Re: Wrong Focus on Form
Post by: Tirans on April 13, 2021, 06:19:10 pm
Thanks guys, I will definetly look into this one.
TinyPortal © 2005-2018