Solved

Last Position of Focus

Posted on 1998-12-13
6
212 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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