2004-06-07 19:17:31 +00:00
|
|
|
{
|
|
|
|
:: X2UtMisc is a collection of functions not fitting into any of the other
|
|
|
|
:: categories.
|
|
|
|
::
|
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2UtMisc;
|
|
|
|
|
|
|
|
interface
|
2007-08-10 12:48:00 +00:00
|
|
|
uses
|
|
|
|
Types;
|
|
|
|
|
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
//:$ Returns IfTrue or IfFalse depending on the Value
|
2007-06-13 05:47:25 +00:00
|
|
|
function iif(const AValue: Boolean; const AIfTrue: Integer;
|
|
|
|
const AIfFalse: Integer = 0): Integer; overload;
|
2004-06-07 19:17:31 +00:00
|
|
|
|
|
|
|
//:$ Returns IfTrue or IfFalse depending on the Value
|
2007-06-13 05:47:25 +00:00
|
|
|
function iif(const AValue: Boolean; const AIfTrue: String;
|
|
|
|
const AIfFalse: String = ''): String; overload;
|
2004-06-07 19:17:31 +00:00
|
|
|
|
|
|
|
//:$ Compares two integers
|
|
|
|
//:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and
|
|
|
|
//:: -1 when Value1 is less than Value2.
|
|
|
|
function CompareInt(const AValue1, AValue2: Integer): Integer; overload;
|
|
|
|
|
|
|
|
//:$ Compares two integers
|
|
|
|
//:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and
|
|
|
|
//:: -1 when Value1 is less than Value2.
|
|
|
|
function CompareInt(const AValue1, AValue2: Cardinal): Integer; overload;
|
|
|
|
|
|
|
|
//:$ Compares two integers
|
|
|
|
//:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and
|
|
|
|
//:: -1 when Value1 is less than Value2.
|
|
|
|
function CompareInt(const AValue1, AValue2: Int64): Integer; overload;
|
|
|
|
|
2004-11-02 12:59:27 +00:00
|
|
|
//:$ Compares two floating point values
|
|
|
|
//:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and
|
|
|
|
//:: -1 when Value1 is less than Value2.
|
|
|
|
function CompareFloat(const AValue1, AValue2: Single): Integer; overload;
|
|
|
|
|
|
|
|
//:$ Compares two floating point values
|
|
|
|
//:: Returns 0 if the values are equal, 1 if Value1 is greater than Value2 and
|
|
|
|
//:: -1 when Value1 is less than Value2.
|
|
|
|
function CompareFloat(const AValue1, AValue2: Double): Integer; overload;
|
|
|
|
|
2004-06-08 19:58:59 +00:00
|
|
|
//:$ Checks if the value is within the specified range
|
|
|
|
//:: Returns the Default parameter is the range is exceeded, otherwise
|
2007-08-10 12:48:00 +00:00
|
|
|
//:: the value is returned. The overloads without a Default parameter
|
|
|
|
//:: return the nearest Min or Max value.
|
|
|
|
function InRange(const AValue, AMin, AMax, ADefault: Integer): Integer; overload;
|
|
|
|
function InRange(const AValue, AMin, AMax, ADefault: Int64): Int64; overload;
|
|
|
|
function InRange(const AValue, AMin, AMax: Integer): Integer; overload;
|
|
|
|
function InRange(const AValue, AMin, AMax: Int64): Int64; overload;
|
|
|
|
|
|
|
|
//:$ Returns the width of a rectangle
|
2009-02-25 10:51:58 +00:00
|
|
|
function RectWidth(const ARect: TRect): Integer; {$IFDEF D2006PLUS}inline;{$ENDIF}
|
2007-08-10 12:48:00 +00:00
|
|
|
|
|
|
|
//:$ Returns the height of a rectangle
|
2009-02-25 10:51:58 +00:00
|
|
|
function RectHeight(const ARect: TRect): Integer; {$IFDEF D2006PLUS}inline;{$ENDIF}
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-06-08 19:58:59 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
implementation
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
function iif(const AValue: Boolean; const AIfTrue, AIfFalse: Integer): Integer;
|
|
|
|
begin
|
|
|
|
if AValue then
|
|
|
|
Result := AIfTrue
|
|
|
|
else
|
|
|
|
Result := AIfFalse;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
function iif(const AValue: Boolean; const AIfTrue, AIfFalse: String): String;
|
|
|
|
begin
|
|
|
|
if AValue then
|
|
|
|
Result := AIfTrue
|
|
|
|
else
|
|
|
|
Result := AIfFalse;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
function CompareInt(const AValue1, AValue2: Integer): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
if AValue1 > AValue2 then
|
|
|
|
Result := 1
|
|
|
|
else if AValue1 < AValue2 then
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
function CompareInt(const AValue1, AValue2: Cardinal): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
if AValue1 > AValue2 then
|
|
|
|
Result := 1
|
|
|
|
else if AValue1 < AValue2 then
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
function CompareInt(const AValue1, AValue2: Int64): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
if AValue1 > AValue2 then
|
|
|
|
Result := 1
|
|
|
|
else if AValue1 < AValue2 then
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-11-02 12:59:27 +00:00
|
|
|
function CompareFloat(const AValue1, AValue2: Single): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
if AValue1 > AValue2 then
|
|
|
|
Result := 1
|
|
|
|
else if AValue1 < AValue2 then
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
2004-11-02 12:59:27 +00:00
|
|
|
function CompareFloat(const AValue1, AValue2: Double): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
if AValue1 > AValue2 then
|
|
|
|
Result := 1
|
|
|
|
else if AValue1 < AValue2 then
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
|
|
|
function InRange(const AValue, AMin, AMax, ADefault: Integer): Integer;
|
|
|
|
begin
|
|
|
|
Result := ADefault;
|
|
|
|
|
|
|
|
if (AValue >= AMin) and (AValue <= AMax) then
|
|
|
|
Result := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function InRange(const AValue, AMin, AMax, ADefault: Int64): Int64;
|
2004-06-08 19:58:59 +00:00
|
|
|
begin
|
|
|
|
Result := ADefault;
|
|
|
|
|
|
|
|
if (AValue >= AMin) and (AValue <= AMax) then
|
|
|
|
Result := AValue;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 12:48:00 +00:00
|
|
|
|
|
|
|
function InRange(const AValue, AMin, AMax: Integer): Integer;
|
|
|
|
begin
|
|
|
|
Result := AValue;
|
|
|
|
|
|
|
|
if Result < AMin then
|
|
|
|
Result := AMin
|
|
|
|
else if Result > AMax then
|
|
|
|
Result := AMax;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function InRange(const AValue, AMin, AMax: Int64): Int64;
|
|
|
|
begin
|
|
|
|
Result := AValue;
|
|
|
|
|
|
|
|
if Result < AMin then
|
|
|
|
Result := AMin
|
|
|
|
else if Result > AMax then
|
|
|
|
Result := AMax;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function RectWidth(const ARect: TRect): Integer;
|
|
|
|
begin
|
|
|
|
Result := (ARect.Right - ARect.Left);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function RectHeight(const ARect: TRect): Integer;
|
|
|
|
begin
|
|
|
|
Result := (ARect.Bottom - ARect.Top);
|
|
|
|
end;
|
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
end.
|