Solved

Last Position of Focus

Posted on 1998-12-13
6
205 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
Comment Utility
ops, some typos
tab-mode = tab-move
now = known
0
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Expert Comment

by:jeurk
Comment Utility
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
Comment Utility
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
Comment Utility
this is how I'm doing it too.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now