Solved

Last Position of Focus

Posted on 1998-12-13
6
216 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 92
Delphi 2 91
DBCtrlGrid, Delphi, Scroll 8 86
Using MMsystem To change audio input 1 39
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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