unit ViewTemplate;
interface
uses
Winapi.Windows,
System.Classes,
Vcl.Forms,
Vcl.Controls;
type
TfrmTemplate =
class( TForm )
private
FCurrentControl : TWinControl;
FLastActiveControl : TWinControl;
FOnFocusChanged : TNotifyEvent;
protected
procedure CMFocusChanged(
var Message : TCMFocusChanged );
message CM_FOCUSCHANGED;
public
function BackToLastActiveControl : Boolean;
published
property LastActiveControl : TWinControl
read FLastActiveControl;
property OnFocusChanged : TNotifyEvent
read FOnFocusChanged
write FOnFocusChanged;
end;
var
frmTemplate : TfrmTemplate;
implementation
{$R *.dfm}
{ TfrmTemplate }
function TfrmTemplate.BackToLastActiveControl : Boolean;
begin
Result := False;
if Assigned( LastActiveControl )
and LastActiveControl.CanFocus
then
begin
LastActiveControl.SetFocus;
Result := True;
end;
end;
procedure TfrmTemplate.CMFocusChanged(
var Message : TCMFocusChanged );
begin
FLastActiveControl := FCurrentControl;
FCurrentControl := ActiveControl;
if Assigned( OnFocusChanged )
then
OnFocusChanged( Self );
end;
end.