Solved

Last Position of Focus

Posted on 1998-12-13
6
217 Views
Last Modified: 2010-04-04
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
Comment
Question by:omsec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Author Comment

by:omsec
ID: 1350834
ops, some typos
tab-mode = tab-move
now = known
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1350835
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1350836
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
Industry Leaders: 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!

 
LVL 4

Expert Comment

by:jeurk
ID: 1350837
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
 
LVL 3

Accepted Solution

by:
rickpet earned 20 total points
ID: 1350838
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
 
LVL 4

Expert Comment

by:jeurk
ID: 1350839
this is how I'm doing it too.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 3 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question