-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit17.pas
164 lines (139 loc) · 4.21 KB
/
Unit17.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
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
unit Unit17;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, TileImage, StdCtrls, math;
type
TFormprevod = class(TForm)
TileImage1: TTileImage;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Formprevod: TFormprevod;
implementation
uses Unit1;
{$R *.DFM}
procedure TFormprevod.FormCreate(Sender: TObject);
begin
if unit1.jazyk = 'svk' then begin
caption := 'Prevody - HEX / DEC';
end;
tileimage1.picture := form1.tileimage1.picture;
edit1.Color := form1.RichEdit1.color;
edit1.font.Color := form1.RichEdit1.font.color;
edit2.Color := form1.RichEdit1.color;
edit2.font.Color := form1.RichEdit1.font.color;
label1.font.color := form1.label1.font.color;
label2.font.color := form1.label1.font.color;
if form1.AlphaBlend = true then begin
AlphaBlend := true;
AlphaBlendValue := Form1.AlphaBlendValue;
end;
end;
procedure TFormprevod.Edit1KeyPress(Sender: TObject; var Key: Char);
var cislodec : byte;
cislosuccess : boolean;
begin
cislosuccess := false;
for cislodec := 48 to 57 do begin
if Ord(key) = cislodec then begin
key := Chr(cislodec);
cislosuccess := true;
end;
end;
if Ord(key) = 8 then cislosuccess := true;
if not cislosuccess then key := Chr(3);
end;
procedure TFormprevod.Edit2KeyPress(Sender: TObject; var Key: Char);
var cislosuccess : boolean;
cislodec : byte;
begin
cislosuccess := false;
for cislodec := 48 to 57 do begin
if Ord(key) = cislodec then begin
key := Chr(cislodec);
cislosuccess := true;
end;
end;
if Ord(key) = 8 then cislosuccess := true;
if Key = 'A' then cislosuccess := true;
if Key = 'B' then cislosuccess := true;
if Key = 'C' then cislosuccess := true;
if Key = 'D' then cislosuccess := true;
if Key = 'E' then cislosuccess := true;
if Key = 'F' then cislosuccess := true;
if Key = 'a' then begin
Key := 'A';
cislosuccess := true;
end;
if Key = 'b' then begin
Key := 'B';
cislosuccess := true;
end;
if Key = 'c' then begin
Key := 'C';
cislosuccess := true;
end;
if Key = 'd' then begin
Key := 'D';
cislosuccess := true;
end;
if Key = 'e' then begin
Key := 'E';
cislosuccess := true;
end;
if Key = 'f' then begin
Key := 'F';
cislosuccess := true;
end;
if not cislosuccess then key := Chr(3);
end;
procedure TFormprevod.Edit1Change(Sender: TObject);
begin
if length(edit1.text) > 0 then begin
edit2.text := inttohex(strtoint(edit1.text),1);
end else begin
edit2.text := '';
edit1.text := '';
end;
end;
procedure TFormprevod.Edit2Change(Sender: TObject);
var delkahex : byte;
vysledekDEC, tempvysledek : integer;
begin
if length(edit2.text) > 0 then begin
vysledekDEC := 0;
for delkaHEX := 0 to length(edit2.text)-1 do begin
if edit2.text[delkahex + 1] = 'A' then tempvysledek := 10 else begin
if edit2.text[delkahex + 1] = 'B' then tempvysledek := 11 else begin
if edit2.text[delkahex + 1] = 'C' then tempvysledek := 12 else begin
if edit2.text[delkahex + 1] = 'D' then tempvysledek := 13 else begin
if edit2.text[delkahex + 1] = 'E' then tempvysledek := 14 else begin
if edit2.text[delkahex + 1] = 'F' then tempvysledek := 15 else begin
tempvysledek := strtoint(edit2.text[delkahex + 1]);
end;
end;
end;
end;
end;
end;
vysledekDEC := vysledekDEC + round(power(16,length(edit2.text) - 1 - delkaHEX)) * tempvysledek;//strtoint(edit1.text[length(edit1.text) - delkaHEX]);
end;
edit1.text := inttostr(vysledekDEC);
end else begin
edit1.text := '';
end;
end;
end.