Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find previous active control: Delphi

Tags:

delphi

I want to get the previous active control in Delphi, i have tried to used OnActiveControlChange event, but even through that i can get the current active control not the previous one.

Thanks for the help in advance. --Vijay

like image 253
Vijay Bobba Avatar asked Dec 16 '10 04:12

Vijay Bobba


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.Name to get the name of previous control

For more information go through this link

like image 150
Bharat Avatar answered Nov 15 '22 07:11

Bharat


You could build yourself a 'history' of active controls using this event, and to find the previous you would consult your history list.

like image 32
Darian Miller Avatar answered Nov 15 '22 06:11

Darian Miller