-
Notifications
You must be signed in to change notification settings - Fork 7
/
UHelper.pas
116 lines (93 loc) · 2.69 KB
/
UHelper.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
unit UHelper;
//------------------------------------------------------------------------------
interface
//-----------------------------------------------------------------------------
uses
Windows, Messages, SysUtils, Classes, Controls, Variants;
function QualityToStr(Quality:integer):string;
function VariantToString(Value: Variant): String;
function IntToBin(Value: Longint; Digits: Integer): string;
function IntToBool(Value: Longint; GetBit: Integer): Boolean;
function StrToHexStr(strIn: string): string;
function ByteToHexStr(byteIn: array of byte): string; Overload;
function ByteToHexStr(byteIn: array of byte; len: integer): string; Overload;
//------------------------------------------------------------------------------
implementation
//------------------------------------------------------------------------------
// HELPER
function QualityToStr(Quality:integer):string;
const
QUALITY_BAD = $00;
QUALITY_UNCERTAIN = $40;
QUALITY_GOOD = $C0;
begin
case Quality of
QUALITY_BAD: result:='bad';
QUALITY_GOOD: result:='good';
else
result:='uncertain';
end;
end;
function VariantToString(Value: Variant): String;
begin
case TVarData(Value).VType of
varSmallInt,
varInteger : Result := IntToStr(Value);
varSingle,
varDouble,
varCurrency : Result := FloatToStr(Value);
varDate : Result := FormatDateTime('dd/mm/yyyy', Value);
varBoolean : if Value then Result := 'True' else Result := 'False';
varString : Result := Value;
else
Result := '';
end;
end;
function IntToBin(Value: Longint; Digits: Integer): string;
var
i: Integer;
begin
Result := '';
for i := Digits downto 0 do
if Value and (1 shl i) <> 0 then
Result := Result + '1'
else
Result := Result + '0';
end;
function IntToBool(Value: Longint; GetBit: Integer): Boolean;
begin
Result := False;
if Value and (1 shl GetBit) <> 0 then
Result := True;
end;
function ByteToHexStr(byteIn: array of byte): string;
var
strHex: string;
y: Integer;
begin
strHex:= '';
for y:= Low(byteIn) to High(byteIn) do
strHex := strHex + IntToHex(byteIn[y],2)+' ';
Result:= chr(VK_TAB)+strHex;
end;
function ByteToHexStr(byteIn: array of byte; len: integer): string;
var
strHex: string;
y: Integer;
begin
strHex:= '';
for y:= Low(byteIn) to len-1 do
strHex := strHex + IntToHex(byteIn[y],2)+' ';
Result:= chr(VK_TAB)+strHex;
end;
function StrToHexStr(strIn: string): string;
var
strHex: string;
y: Integer;
begin
strHex:= '';
for y:= 1 to Length(strIn) do
strHex := strHex + IntToHex(ord(strIn[y]),2)+' ';
Result:= chr(VK_TAB)+strHex ;
end;
end.