-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathJPL.Utils.pas
119 lines (93 loc) · 3.32 KB
/
JPL.Utils.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
unit JPL.Utils;
{
Jacek Pazera
http://www.pazera-software.com
}
{$I .\..\jp.inc}
{$IFDEF FPC}{$mode delphi}{$ENDIF}
interface
function IfThenStr(BoolValue: Boolean; const ResultIfTrue: string; ResultIfFalse: string = ''): string;
function IfThenInt(BoolValue: Boolean; const ResultIfTrue: integer; ResultIfFalse: integer = -1): integer;
function IfThenUInt(BoolValue: Boolean; const ResultIfTrue: UInt32; ResultIfFalse: UInt32 = 0): UInt32;
function IfThenInt64(BoolValue: Boolean; const ResultIfTrue: Int64; ResultIfFalse: Int64 = -1): Int64;
function IfThenUInt64(BoolValue: Boolean; const ResultIfTrue: UInt64; ResultIfFalse: UInt64 = 0): UInt64;
function IfThenFloat(BoolValue: Boolean; const ResultIfTrue: Double; ResultIfFalse: Double = -1): Double;
function NumberIn(const Number: integer; IntValArray: array of integer): Boolean; overload;
function NumberIn(const Number: Int64; Int64ValArray: array of integer): Boolean; overload;
function NumberIn(const Number: Cardinal; CardinalValArray: array of Cardinal): Boolean; overload;
function NumberIn(const Number: Double; DoubleValArray: array of Double): Boolean; overload;
implementation
function IfThenStr(BoolValue: Boolean; const ResultIfTrue: string; ResultIfFalse: string = ''): string;
begin
if BoolValue then Result := ResultIfTrue
else Result := ResultIfFalse;
end;
function IfThenInt(BoolValue: Boolean; const ResultIfTrue: integer; ResultIfFalse: integer = -1): integer;
begin
if BoolValue then Result := ResultIfTrue else Result := ResultIfFalse;
end;
function IfThenUInt(BoolValue: Boolean; const ResultIfTrue: UInt32; ResultIfFalse: UInt32 = 0): UInt32;
begin
if BoolValue then Result := ResultIfTrue else Result := ResultIfFalse;
end;
function IfThenInt64(BoolValue: Boolean; const ResultIfTrue: Int64; ResultIfFalse: Int64 = -1): Int64;
begin
if BoolValue then Result := ResultIfTrue else Result := ResultIfFalse;
end;
function IfThenUInt64(BoolValue: Boolean; const ResultIfTrue: UInt64; ResultIfFalse: UInt64 = 0): UInt64;
begin
if BoolValue then Result := ResultIfTrue else Result := ResultIfFalse;
end;
function IfThenFloat(BoolValue: Boolean; const ResultIfTrue: Double; ResultIfFalse: Double = -1): Double;
begin
if BoolValue then Result := ResultIfTrue else Result := ResultIfFalse;
end;
function NumberIn(const Number: integer; IntValArray: array of integer): Boolean;
var
i: integer;
begin
Result := False;
for i := 0 to Length(IntValArray) - 1 do
if IntValArray[i] = Number then
begin
Result := True;
Break;
end;
end;
function NumberIn(const Number: Int64; Int64ValArray: array of integer): Boolean;
var
i: integer;
begin
Result := False;
for i := 0 to Length(Int64ValArray) - 1 do
if Int64ValArray[i] = Number then
begin
Result := True;
Break;
end;
end;
function NumberIn(const Number: Cardinal; CardinalValArray: array of Cardinal): Boolean;
var
i: integer;
begin
Result := False;
for i := 0 to Length(CardinalValArray) - 1 do
if CardinalValArray[i] = Number then
begin
Result := True;
Break;
end;
end;
function NumberIn(const Number: Double; DoubleValArray: array of Double): Boolean;
var
i: integer;
begin
Result := False;
for i := 0 to Length(DoubleValArray) - 1 do
if DoubleValArray[i] = Number then
begin
Result := True;
Break;
end;
end;
end.