-
Notifications
You must be signed in to change notification settings - Fork 19
/
FormRichLog.pas
106 lines (74 loc) · 2.96 KB
/
FormRichLog.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
97
98
99
100
101
102
103
UNIT FormRichLog;
{=============================================================================================================
Gabriel Moraru
2024.05
See Copyright.txt
--------------------------------------------------------------------------------------------------------------
Visual log (window).
More details in llRichLogUtils.pas
Usage:
It is CRITICAL to create the AppData object as soon as the application starts.
Prefferably in the DPR file before creating the main form!
DPR:
AppData:= TAppData.Create('MyCollApp');
OnLateInitialize:
AppData.Initilizing:= False;
AppDataEx is automatically destroyed by the Finalization section of this unit.
Tester:
c:\Myprojects\LightSaber\Demo\LightLog\
=============================================================================================================}
INTERFACE
{.$DENYPACKAGEUNIT ON} {Prevents unit from being placed in a package. https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Packages_(Delphi)#Naming_packages }
USES
Winapi.Windows, Winapi.Messages, System.Classes,
Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls,
llRichLogTrack, llRichLog;
TYPE
TfrmRichLog = class(TForm)
Log : TRichLog;
Container : TPanel; { We use a container for all controls on this form so we can reparent them easily to another form }
pnlBottom : TPanel;
btnClear : TButton;
chkAutoOpen: TCheckBox;
trkLogVerb : TRichLogTrckbr;
procedure btnClearClick(Sender: TObject);
procedure LogError (Sender: TObject);
procedure FormCreate (Sender: TObject);
procedure FormDestroy (Sender: TObject); // Would be nice to make this protected but we can't. All event handlers must be accesible/visible
public
procedure LateInitialize(VAR Msg: TMessage); message WM_APP + 4712; // Called after the main form was fully initilized
end;
IMPLEMENTATION {$R *.dfm}
USES
cvINIFile, cbAppData;
{-------------------------------------------------------------------------------------------------------------
FORM
-------------------------------------------------------------------------------------------------------------}
procedure TfrmRichLog.FormCreate(Sender: TObject);
begin
Log.Onwarn := LogError; // Auto show form if we send an error msg to the log
Log.OnError:= LogError;
PostMessage(Self.Handle, WM_APP + 4712, 0, 0);
end;
procedure TfrmRichLog.LateInitialize;
begin
LoadForm(Self);
end;
// This is called automatically by "Finalization"
procedure TfrmRichLog.FormDestroy(Sender: TObject);
begin
Assert(AppData <> NIL, 'AppData is gone already!');
Container.Parent:= Self;
if NOT cbAppData.AppData.Initializing
then SaveForm(Self); // We don't save anything if the start up was improper!
end;
procedure TfrmRichLog.btnClearClick(Sender: TObject);
begin
Log.Clear;
end;
procedure TfrmRichLog.LogError(Sender: TObject);
begin
if chkAutoOpen.Checked
then Show;
end;
end.