-
Notifications
You must be signed in to change notification settings - Fork 0
/
unitmain.pas
91 lines (69 loc) · 1.87 KB
/
unitmain.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
unit UnitMain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
StrUtils;
type
{ TFormMain }
TFormMain = class(TForm)
ButtonOK: TButton;
ButtonExit: TButton;
SiteNumber: TEdit;
ProductKey: TEdit;
GroupBoxMain: TGroupBox;
LabelDash: TLabel;
LabelMain: TLabel;
procedure ButtonOKClick(Sender: TObject);
procedure ButtonExitClick(Sender: TObject);
procedure FormClose(Sender: TObject);
private
public
end;
var
FormMain: TFormMain;
implementation
{$R *.lfm}
{ TFormMain }
procedure Validator(Site: String; Product: String);
var
blacklist: array of String = ('333', '444', '555', '666',
'777', '888', '999');
isSiteValid: Boolean;
isProductValid: Boolean;
ProductSum: Integer;
Index: Integer;
begin
{ Site Code Validation }
isSiteValid := False;
if IndexStr(Site, Blacklist) = -1 then isSiteValid := True;
ProductSum := 0;
for Index := 1 to Length(Product) do begin
ProductSum := ProductSum + StrToInt(Product[Index]);
end;
{ Product Key Mod7 Algorithm Validation}
isProductValid := False;
if (ProductSum mod 7 = 0) then isProductValid := True;
{ End Result }
if (isProductValid and isSiteValid) then
ShowMessage('The Key is Valid!')
else ShowMessage('Sorry, This Key is Invalid!');
end;
procedure TFormMain.ButtonOKClick(Sender: TObject);
begin
if (Length(SiteNumber.Text) < 3) or (Length(ProductKey.Text) < 7) then
ShowMessage('Please, Enter a Valid Product Key!')
else begin
Validator(SiteNumber.Text, ProductKey.Text);
end;
end;
procedure TFormMain.ButtonExitClick(Sender: TObject);
begin
ShowMessage('Goodbye!');
Halt;
end;
procedure TFormMain.FormClose(Sender: TObject);
begin
Halt;
end;
end.