How to find the previous active control: Delphi

I want to get the previous active control in Delphi, I tried to use the OnActiveControlChange event, but even through this I can get the current active control, not the previous one.

Thanks for the help in advance. --Vijay

+5
source share
2 answers

Try this code

  TForm1 = class(TForm)
  ---
  --- 
  private
    { Private declarations }
    wcActive, wcPrevious : TWinControl;
  public
    { Public declarations }
    procedure ActiveControlChanged(Sender: TObject) ;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ActiveControlChanged(Sender: TObject);
begin
  wcPrevious := wcActive;
  wcActive := Form1.ActiveControl;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.OnActiveControlChange := ActiveControlChanged;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Screen.OnActiveControlChange := nil;
end;

Use wcControl.Nameto get the name of the previous control

For more information, go to this link.

+8
source

You can create a “history” of active controls using this event, and to find the previous one, you will refer to your history list.

+4

All Articles