-
Notifications
You must be signed in to change notification settings - Fork 0
/
UPrincipal.pas
96 lines (81 loc) · 2.21 KB
/
UPrincipal.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit UPrincipal;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.AppEvnts, Vcl.StdCtrls;
type
TFPrincipal = class(TForm)
ApplicationEvents1: TApplicationEvents;
TimerLogoff: TTimer;
EdtTimeOutLogoff: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure TimerLogoffTimer(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
function login: boolean;
public
{ Public declarations }
end;
var
FPrincipal: TFPrincipal;
implementation
{$R *.dfm}
uses ULogin;
function ExisteForm(pForm: TForm): Boolean;
var
I:Integer;
begin
ExisteForm := False;
For I:= 0 to Screen.FormCount - 1 do
if (Screen.Forms[I] = pForm) then
begin
ExisteForm := True;
Break;
end;
end;
procedure TFPrincipal.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
begin
if (EdtTimeOutLogoff.Text <> '0')and(not ExisteForm(FLogin)) then
TimerLogoff.Enabled:=True;
end;
procedure TFPrincipal.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if (Msg.message = WM_KEYDOWN) or
(Msg.message = WM_LBUTTONDOWN) or
(Msg.message = WM_RBUTTONDOWN) or
(Msg.message = WM_MOUSEMOVE) or
(Msg.message = WM_SYSKEYDOWN) then
TimerLogoff.Enabled:= False;
end;
procedure TFPrincipal.FormShow(Sender: TObject);
begin
TimerLogoff.Interval := StrToInt(EdtTimeOutLogoff.Text) * 1000
end;
function TFPrincipal.login: boolean;
begin
TimerLogoff.Enabled:=False; //desativa o timer
FLogin := TFLogin.Create(Self);
try
FLogin.ShowModal;
Result := FLogin.ModalResult = MrOk;
finally
FLogin.Free;
end;
end;
procedure TFPrincipal.TimerLogoffTimer(Sender: TObject);
begin
if Application.FindComponent('FLogin') = nil then
begin
if Login then
Label2.Caption := 'Logado'
else
Application.terminate;
end;
end;
end.