This repository was archived by the owner on Dec 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathYourAppUnit.pas
More file actions
172 lines (155 loc) · 4.44 KB
/
YourAppUnit.pas
File metadata and controls
172 lines (155 loc) · 4.44 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
unit YourAppUnit;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.onguard,
VCL.ogutil;
type
TForm1 = class(TForm)
OgRegistrationCode1: TOgRegistrationCode;
btnReg: TButton;
StatusLbl: TLabel;
CodeLbl: TLabel;
btnRemoveReg: TButton;
procedure OgRegistrationCode1GetKey(Sender: TObject; var Key: TKey);
procedure OgRegistrationCode1GetCode(Sender: TObject; var Code: TCode);
procedure OgRegistrationCode1Checked(Sender: TObject; Status: TCodeStatus);
procedure btnRegClick(Sender: TObject);
procedure OgRegistrationCode1GetRegString(Sender: TObject;
var Value: string);
procedure btnRemoveRegClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
RegStr: string;
end;
var
Form1: TForm1;
implementation
uses
Registry;
{$R *.dfm}
//==============================================================================
// OnGuard
//==============================================================================
procedure TForm1.OgRegistrationCode1GetKey(Sender: TObject; var Key: TKey);
const
CKey: TKey = ($E5, $8F, $84, $D6, $92, $C9, $A4, $D8, $1A, $FA, $6F, $8D, $AB, $FC, $DF, $B4);
begin
Key := CKey;
end;
procedure TForm1.OgRegistrationCode1Checked(Sender: TObject;
Status: TCodeStatus);
var
S: string;
begin
case Status of
ogValidCode: S := 'Valid Registration: ' + RegStr;
ogInvalidCode: S := 'Invalid release code';
ogPastEndDate: S := 'Date has expired';
ogDayCountUsed: S := 'Zero days of use remaining';
ogRunCountUsed: S := 'Usage count has expired';
ogNetCountUsed: S := 'Net usage count exceeded';
ogCodeExpired: S := 'Code has expired';
else
S := 'Unknown error';
end;
StatusLbl.Caption := S;
end;
procedure TForm1.OgRegistrationCode1GetCode(Sender: TObject; var Code: TCode);
var
Reg: TRegistry;
S: string;
begin
Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\YourAppReg', true);
try
S := '';
if Reg.ValueExists('RegistrationCode') then
S := Reg.ReadString('RegistrationCode');
{convert to proper form}
HexToBuffer(S, Code, SizeOf(Code));
{set code label caption}
CodeLbl.Caption := S;
finally
Reg.Free;
end;
end;
procedure TForm1.OgRegistrationCode1GetRegString(Sender: TObject;
var Value: string);
var
Reg: TRegistry;
S: string;
begin
Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\YourAppReg', true);
try
S := '';
RegStr := '';
if Reg.ValueExists('RegistrationStr') then
RegStr := Reg.ReadString('RegistrationStr');
Value := RegStr;
finally
Reg.Free;
end;
end;
//==============================================================================
// Remove Registration
//==============================================================================
procedure TForm1.btnRegClick(Sender: TObject);
var
Reg: TRegistry;
Work: TCode;
S: string;
begin
S := '';
{ask for string and code}
if InputQuery('Registration String Entry', 'Enter the registration string', RegStr) then begin
if InputQuery('Registration Code Entry', 'Enter the code', S) then begin
Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\YourAppReg', true);
try
{store the code in the Reg file if it looks OK}
if HexToBuffer(S, Work, SizeOf(Work)) then begin
{save the value}
Reg.WriteString('RegistrationCode', S);
Reg.WriteString('RegistrationStr', RegStr);
CodeLbl.Caption := S;
{tell the code component to test the new code, reporting the results}
OgRegistrationCode1.CheckCode(True);
end;
finally
Reg.Free;
end;
end;
end;
end;
//==============================================================================
// Remove Registration
//==============================================================================
procedure TForm1.btnRemoveRegClick(Sender: TObject);
begin
var Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\YourAppReg', true);
try
Reg.WriteString('RegistrationCode', '');
Reg.WriteString('RegistrationStr', '');
finally
Reg.Free;
end;
end;
end.