Skip to content

Commit

Permalink
Utils: +func. NumberIn
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdp committed Aug 21, 2020
1 parent 27f5357 commit 7100d07
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Base/JPL.Utils.pas
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
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
Expand Down Expand Up @@ -44,4 +61,59 @@ function IfThenFloat(BoolValue: Boolean; const ResultIfTrue: Double; ResultIfFal
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.

0 comments on commit 7100d07

Please sign in to comment.