forked from Sharlikran/xEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmTipForm.pas
127 lines (102 loc) · 2.61 KB
/
frmTipForm.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
unit frmTipForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, FileContainer;
type
TfrmTip = class(TForm)
Shape1: TShape;
textTip: TStaticText;
StaticText1: TStaticText;
cbShowTip: TCheckBox;
lblNextTip: TLabel;
fcEditTips: TFileContainer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lblNextTipClick(Sender: TObject);
procedure cbShowTipClick(Sender: TObject);
private
{ Private declarations }
slTips: TStringList;
public
{ Public declarations }
procedure NextTip;
end;
var
frmTip: TfrmTip;
procedure ShowTip;
procedure HideTip;
implementation
{$R *.dfm}
uses
wbInterface;
procedure ShowTip;
begin
if not Assigned(frmTip) then begin
frmTip := TfrmTip.Create(Application);
ShowWindow(frmTip.Handle, SW_SHOWNOACTIVATE);
frmTip.Visible := True;
end;
end;
procedure HideTip;
begin
if Assigned(frmTip) then begin
if frmTip.Visible then frmTip.Hide;
FreeAndNil(frmTip);
end;
end;
procedure TfrmTip.NextTip;
begin
if Assigned(slTips) and (slTips.Count <> 0) then
textTip.Caption := slTips[Random(slTips.Count)];
end;
procedure TfrmTip.lblNextTipClick(Sender: TObject);
begin
NextTip;
end;
procedure TfrmTip.cbShowTipClick(Sender: TObject);
begin
wbShowTip := Assigned(cbShowTip) and cbShowTip.Checked;
end;
procedure TfrmTip.FormCreate(Sender: TObject);
var
FileContainer : TFileContainer;
Stream : TStream;
TipsFile: string;
i: integer;
begin
slTips := TStringList.Create;
try
FileContainer := FindComponent('fc'+wbToolName+'Tips') as TFileContainer;
TipsFile := ExtractFilePath(Application.ExeName) + wbToolName + 'Tips.Override.txt';
if FileExists(TipsFile) then try
slTips.LoadFromFile(TipsFile, TEncoding.UTF8);
except end;
if (slTips.Count < 1) and Assigned(FileContainer) then try
Stream := FileContainer.CreateReadStream;
try
slTips.LoadFromStream(Stream, TEncoding.UTF8);
finally
Stream.Free
end;
except end;
if slTips.Count < 1 then try
TipsFile := ExtractFilePath(Application.ExeName) + wbToolName + 'Tips.txt';
if FileExists(TipsFile) then
slTips.LoadFromFile(TipsFile, TEncoding.UTF8);
except end;
for i := Pred(slTips.Count) downto 0 do
if Trim(slTips[i]) = '' then
slTips.Delete(i);
if slTips.Count = 0 then
Exit;
NextTip;
except end;
end;
procedure TfrmTip.FormDestroy(Sender: TObject);
begin
FreeAndNil(slTips);
end;
initialization
Randomize;
end.