Mirror

How to check which control previously had focus (Views: 709)


Problem/Question/Abstract:

Is there any way to tell within the OnEnter handler of Control2, which other control just passed the focus to Control2?

Answer:

type
  TForm1 = class(TForm)
    { ... }
  public
    LastControl: TComponent;
  end;

procedure TForm1.Edit1OnEnter(Sender: TObject);
begin
  if Assigned(LastControl) then
    { do whatever you want with the previous control }
    LastControl := Sender as TComponent;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  LastControl := nil;
end;

<< Back to main page