Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Last Position of Focus

Is it possible in Delphi 4, to see which Element (Edit, Button, etc.) had the Focus before the user changed it, by clicking or tab-mode to another element. Once, the old Focus is now, i want to set it back (probly using .SetFocus) on the OnExit-Event of the new (current) focused element.
0
omsec
Asked:
omsec
1 Solution
 
omsecAuthor Commented:
ops, some typos
tab-mode = tab-move
now = known
0
 
dwwangCommented:
Of course you can, suppose the new(current) focued control is edit2, then in Edit2's OnExit event, you can write:
   SelectNext(Edit2,false,true);
See the help for SelectNext method and you get all.

However,this method works only for changing focus by TAB-move, not for Mouse click. If you gonna want one method for mouse click, I think you need a variable to record the old control on each focus change.
0
 
MadshiCommented:
You could hook all WM_KILLFOCUS messages by writing an Application.OnMessage handler. Please look in the documentation about Application.OnMessage. The WM_KILLFOCUS tells you the handle of the window control, that has lost the focus.

Regards, Madshi.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jeurkCommented:
Hi,
I typing this from memory so...
In the onexit event of your components get the active control and store it in a tobject,
so whenever you want you can switch back to the latest selected component.
use the form's activecontrol to get the current selected component.
If it's still necessary, i'l bring you back some code tommorow.
0
 
rickpetCommented:
The Screen object(TScreen) has a property called ActiveControl
it also has an event called OnActiveControlChange

Just create an object of type TWincontol

declared in the Form's Interface:

FLastControl : TWinControl;
procedure OnScreenControlChange(Sender: TObject);

On the forms create...add:
Screen.OnActiveControlChange := OnScreenControlChange;

procedure TForm1.OnScreenControlChange(Sender: TObject);
begin
  FLastControl := Screen.ActiveControl;
end;

on the forms destroy add:

Screen.OnActiveControlChange := nil;

Rick
0
 
jeurkCommented:
this is how I'm doing it too.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now