Here's how to find out what control was the last one with the input focus...
Delphi's TScreen object has an event called OnActiveControlChange, which fires immediately after input focus changes to a new windowed control.
//Add a new public procedure, ActiveControlChanged,
//to the TForm1 class declaration,
//and two private TWinControl type variables
wcActive, wcPrevious : TWinControl;
procedure ActiveControlChanged(Sender: TObject) ;
procedure TForm1.FormCreate(Sender: TObject) ;
Screen.OnActiveControlChange := ActiveControlChanged;
procedure TForm1.ActiveControlChanged(Sender: TObject) ;
wcPrevious := wcActive;
wcActive := Form1.ActiveControl;
procedure TForm1.FormDestroy(Sender: TObject) ;
Screen.OnActiveControlChange := nil;
procedure TForm1.Button1Click(Sender: TObject) ;
if TEdit(wcPrevious) = Edit1 then
ShowMessage('Edit1 had focus')
else if TEdit(wcPrevious) = Edit2 then
ShowMessage('Edit2 had focus')
ShowMessage('Some other control had a focus!') ;
Delphi tips navigator:
» How to determine the output of a console application
« What is being typed into the DBGrid?