Standards

Navigation:  Les scripts > Les autres scripts > Procedure and function >

Standards

Previous pageReturn to chapter overviewNext page

Round function

 

Returns the value of X rounded to the nearest whole number.

 

function Round(X: Real): Integer;

 

 

The Round function rounds a real-type value to an integer-type value.

 

X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is always the even number.

 

 

Trunc function

 

Truncates a real number to an integer.

 

function Trunc(X: Real): Integer;

 

 

The Trunc function truncates a real-type value to an integer-type value. X is a real-type expression. Trunc returns an Int64 value that is the value of X rounded toward zero.

 

Int function

 

Returns the integer part of a real number.

 

function Int(X: Real): Real;

 

 

Int returns the integer part of X; that is, X rounded toward zero. X is a real-type expression.

 

Frac function

 

Returns the fractional part of a real number.

 

function Frac(X: Real): Real;

 

 

The Frac function returns the fractional part of the argument X.

 

X is a real-type expression. The result is the fractional part of X; that is, Frac(X) = X - Int(X).

Exp function

 

Returns the exponential of X.

 

function Exp(X: Real): Real;

 

 

Exp returns the value of e raised to the power of X, where e is the base of the natural logarithms.

 

Abs function

 

Returns an absolute value.

 

function Abs(X);

 

 

Abs returns the absolute value of the argument, X.

 

X is an integer-type or real-type expression.

 

 

Ln function

 

Returns the natural log of a real expression.

 

function Ln(X: Real): Real;

 

 

Ln returns the natural logarithm (Ln(e) = 1) of the real-type expression X.

 

Power function

 

Raises Base to any power.

 

function Power(Base, Exponent: Real): Real;

 

 

Power raises Base to any power. For fractional exponents or exponents greater than MaxInt, Base must be greater than 0.

 

Logn function

 

function LogN(N, X: Extended): Extended;

 

 

LogN returns the log base N of X.

Sqr function

 

Returns the square of a number.

 

function Sqr(X: Extended): Extended;

 

 

The Sqr function returns the square of the argument.

 

X is a floating-point expression. The result, of the same type as X, is the square of X, or X*X.

 

 

Sqrt function

 

Returns the square root of X.

 

function Sqrt(X: Extended): Extended;

 

 

X is a floating-point expression. The result is the square root of X.

 

Sin function

 

Returns the sine of the angle in radians.

 

function Sin(X: Extended): Extended;

 

 

The Sin function returns the sine of the argument.

 

X is a real-type expression. Sin returns the sine of the angle X in radians.

 

Cos function

 

Calculates the cosine of an angle.

 

function Cos(X: Extended): Extended;

 

 

Cos returns the cosine of the angle X, in radians.

 

Tan function

 

Returns the tangent of X.

 

function Tan(X: Extended): Extended;

 

 

Tan returns the tangent of X. Tan(X) = Sin(X) / Cos(X).

 

 

Pi function

 

Returns 3.1415926535897932385.

 

function Pi: Extended;

 

 

Use Pi in mathematical calculations that require pi, the ratio of a circle's circumference to its diameter. Pi is approximated as 3.1415926535897932385.

 

Time function

 

Returns the current time.

 

function Time: Real;

 

Time returns the current time as a Real value.

 

Incmonth function

 

Returns a date shifted by a specified number of months.

 

function IncMonth(const Date: Real; NumberOfMonths: Integer): Real;

 

 

IncMonth returns the value of the Date parameter, incremented by NumberOfMonths months.  NumberOfMonths can be negative, to return a date N months previous.

 

If the input day of month is greater than the last day of the resulting month, the day is set to the last day of the resulting month.  The time of day specified by the Date parameter is copied to the result.

 

IsLeapYear function

 

Indicates whether a specified year is a leap year.

 

function IsLeapYear(Year: Word): Boolean;

 

 

 

Call IsLeapYear to determine whether the year specified by the Year parameter is a leap year.  Year specifies the calendar year.

 

Use DecodeDate to obtain the value of Year for IsLeapYear from a Real value.

 

EncodeTime function

 

Returns a Real value for a specified Hour, Min, Sec, and MSec.

 

function EncodeTime(Hour, Min, Sec, MSec: Word): Real;

 

 

EncodeTime encodes the given hour, minute, second, and millisecond into a Real value. Valid Hour values are 0 through 23. Valid Min and Sec values are 0 through 59. Valid MSec values are 0 through 999. If the specified values are not within range, an EConvertError exception is raised.

 

The resulting value is a number between 0 (inclusive) and 1 (not inclusive) that indicates the fractional part of a day given by the specified time. The value 0 corresponds to midnight, 0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, and so on.

 

EncodeDate function

 

Returns a TDateTime value that represents a specified Year, Month, and Day.

 

function EncodeDate(Year, Month, Day: Word): Real;

 

 

EncodeDate returns a Real value from the values specified as the Year, Month, and Day parameters.

 

The year must be between 1 and 9999.

 

Valid Month values are 1 through 12.

 

Valid Day values are 1 through 28, 29, 30, or 31, depending on the Month value. For example, the possible Day values for month 2 (February) are 1 through 28 or 1 through 29, depending on whether or not the Year value specifies a leap year.

 

If the specified values are not within range, EncodeDate raises an EConvertError exception.

 

FormatDateTime function

 

Formats a TDateTime value.

 

function FormatDateTime(const Format: string; DateTime: TDateTime): string;

 

 

FormatDateTime formats the TDateTime value given by DateTime using the format given by Format. The following format specifiers are supported:

 

Specifier        Displays

c        Displays the date using the format given by the ShortDateFormat global variable, followed by the time using the          format given by the LongTimeFormat global variable. The time is not displayed if the fractional part of the DateTime value is zero.

d        Displays the day as a number without a leading zero (1-31).

dd        Displays the day as a number with a leading zero (01-31).

ddd        Displays the day as an abbreviation (Sun-Sat) using the strings given by the ShortDayNames global variable.

dddd        Displays the day as a full name (Sunday-Saturday) using the strings given by the LongDayNames global variable.

ddddd        Displays the date using the format given by the ShortDateFormat global variable.

dddddd        Displays the date using the format given by the LongDateFormat global variable.

m        Displays the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.

mm        Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.

mmm        Displays the month as an abbreviation (Jan-Dec) using the strings given by the ShortMonthNames global variable.

mmmm        Displays the month as a full name (January-December) using the strings given by the LongMonthNames global variable.

yy        Displays the year as a two-digit number (00-99).

yyyy        Displays the year as a four-digit number (0000-9999).

h        Displays the hour without a leading zero (0-23).

hh        Displays the hour with a leading zero (00-23).

n        Displays the minute without a leading zero (0-59).

nn        Displays the minute with a leading zero (00-59).

s        Displays the second without a leading zero (0-59).

ss        Displays the second with a leading zero (00-59).

z        Displays the millisecond without a leading zero (0-999).

zzz        Displays the millisecond with a leading zero (000-999).

t        Displays the time using the format given by the ShortTimeFormat global variable.

tt        Displays the time using the format given by the LongTimeFormat global variable.

am/pm        Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.

a/p        Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.

ampm        Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the TimeAMString global variable for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.

/        Displays the date separator character given by the DateSeparator global variable.

:        Displays the time separator character given by the TimeSeparator global variable.

'xx'/"xx"        Characters enclosed in single or double quotes are displayed as-is, and do not affect formatting.

Format specifiers may be written in upper case as well as in lower case letters--both produce the same result.

If the string specified by the Format parameter is empty, the TDateTime value is formatted as if a 'c' format specifier had been given.

 

Insert procedure

 

Inserts a substring into a string beginning at a specified point.

 

procedure Insert(Source: string; var S: string; Index: Integer);

 

 

Insert merges Source into S at the position S[index].

 

Source is a string-type expression. S is a string-type variable of any length. Index is an integer-type expression. It is a character index and not a byte index.

 

Delete procedure

 

Removes a substring from a s string.

 

procedure Delete(var S: string; Index, Count:Integer);

 

 

Delete removes a substring of Count characters from string S starting with S[Index]. S is a string-type variable. Index and Count are integer-type expressions.

 

If Index is larger than the length of S, no characters are deleted. If Count specifies more characters than remain starting at the S[Index], Delete removes the rest of the string.

 

Copy function

 

Returns a substring of a string.

 

function Copy(S; Index, Count: Integer): string;

 

 

S is an expression of a string or dynamic-array type. Index and Count are integer-type expressions. Copy returns a substring or sub array containing Count characters or elements starting at S[Index].

 

If Index is larger than the length of S, Copy returns an empty string or array.

 

If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned.

 

Note:        When S is a dynamic array, Copy can only be used as a parameter in a call to a procedure or function that expects an array parameter. That is, it acts like the Slice function when working with dynamic arrays.

 

 

Pos function

 

Returns the index value of the first character in a specified substring that occurs in a given string.

 

function Pos(Substr: string; S: string): Integer;

 

 

Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.

 

Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.

 

 

StrToIntDef function

 

Converts a string that represents an integer (decimal or hex notation) to a number.

 

function StrToIntDef(const S: string; Default: Integer): Integer;

 

StrToIntDef converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToIntDef returns the number passed in Default.

 

 

StrToInt function

 

Converts a string that represents an integer (decimal or hex notation) to a number.

 

function StrToInt(const S: string): Integer;

 

 

StrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToInt raises an EConvertError exception.

 

 

IntToStr function

 

Converts an integer to a string.

 

function IntToStr(Value: Integer): string;

 

 

IntToStr converts an integer into a string containing the decimal representation of that number.

 

Format function

 

Returns a formatted string assembled from a format string and an array of arguments.

 

function Format(const Format: string; const Args: array of const): string;

 

 

This function formats the series of arguments in the open array Args. Formatting is controlled by the format string Format; the results are returned in the function result as a string.

 

Format specifiers have the following form:

 

"%" [index ":"] ["-"] [width] ["." prec] type

 

A format specifier begins with a % character. After the % come the following, in this order:

 

An optional argument index specifier, [index ":"]

 An optional left justification indicator, ["-"]

 An optional width specifier, [width]

 An optional precision specifier, ["." prec]

 The conversion type character, type

 

The following table summarizes the possible values for type:

 

dDecimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros.

u        Unsigned decimal. Similar to 'd' but no sign is output.

eScientific. The argument must be a floating-point value. The value is converted to a string of the form "-d.ddd...E+ddd". The resulting string starts with a minus sign if the number is negative. One digit always precedes the decimal point.The total number of digits in the resulting string (including the one before the decimal point) is given by the precision specifier in the format string—a default precision of 15 is assumed if no precision specifier is present. The "E" exponent character in the resulting string is always followed by a plus or minus sign and at least three digits.
fFixed. The argument must be a floating-point value. The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative.The number of digits after the decimal point is given by the precision specifier in the format string—a default of 2 decimal digits is assumed if no precision specifier is present.
gGeneral. The argument must be a floating-point value. The value is converted to the shortest possible decimal string using fixed or scientific format. The number of significant digits in the resulting string is given by the precision specifier in the format string—a default precision of 15 is assumed if no precision specifier is present.Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses fixed point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format.
nNumber. The argument must be a floating-point value. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format corresponds to the "f" format, except that the resulting string contains thousand separators.
mMoney. The argument must be a floating-point value. The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator, and CurrencyDecimals global variables, all of which are initialized from the Currency Format in the International section of the Windows Control Panel. If the format string contains a precision specifier, it overrides the value given by the CurrencyDecimals global variable.
pPointer. The argument must be a pointer value. The value is converted to an 8 character string that represents the pointers value in hexadecimal.
sString. The argument must be a character, a string, or a PChar value. The string or character is inserted in place of the format specifier. The precision specifier, if present in the format string, specifies the maximum length of the resulting string. If the argument is a string that is longer than this maximum, the string is truncated.
xHexadecimal. The argument must be an integer value. The value is converted to a string of hexadecimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has fewer digits, the resulting string is left-padded with zeros.

 

Conversion characters may be specified in uppercase as well as in lowercase—both produce the same results.

For all floating-point formats, the actual characters used as decimal and thousand separators are obtained from the DecimalSeparator and ThousandSeparator global variables.

Index, width, and precision specifiers can be specified directly using decimal digit string (for example "%10d"), or indirectly using an asterisk character (for example "%*.*f"). When using an asterisk, the next argument in the argument list (which must be an integer value) becomes the value that is actually used. For example,

 

Format('%*.*f', [8, 2, 123.456])

 

is the same as

 

Format('%8.2f', [123.456]).

 

 

A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (a "-" character preceding the width specifier), the result is left-justified by adding blanks after the value.

 

An index specifier sets the current argument list index to the specified value. The index of the first argument in the argument list is 0. Using index specifiers, it is possible to format the same argument multiple times. For example "Format('%d %d %0:d %1:d', [10, 20])" produces the string '10 20 10 20'.

 

 

FloatToStr function

 

Converts a floating point value to a string.

 

function FloatToStr(Value: Extended): string;

 

 

FloatToStr converts the floating-point value given by Value to its string representation. The conversion uses general number format with 15 significant digits.

 

For greater control over the formatting of the string, use the FloatToStrF function.

 

 

FloatToStrF function

 

Converts a floating point value to a string, using a specified Format, Precision, and Digits.

 

function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): string;

 

 

FloatToStrF converts the floating-point value given by Value to its string representation.

 

The Value parameter is the value to convert.

 The Precision parameter specifies the precision of the given value. It should be 7 or less for values of type Single, 15 or less for values of type Double, and 18 or less for values of type Extended.

 The Digits and Format parameters together control how the value is formatted into a string. For details, see the description of TFloatFormat.

 

For all formats, the actual characters used as decimal and thousand separators are obtained from the DecimalSeparator and ThousandSeparator global variables.

 

If the given value is a NAN (not-a-number), the resulting string is 'NAN'. If the given value is positive infinity, the resulting string is 'INF'. If the given value is negative infinity, the resulting string is '-INF'.

 

IntToHex function

 

Returns the hex representation of an integer.

 

function IntToHex(Value: Integer; Digits: Integer): string;

 

 

IntToHex converts a number into a string containing the number's hexadecimal (base 16) representation. Value is the number to convert. Digits indicates the minimum number of hexadecimal digits to return.

 

Uppercase function

 

Returns a copy of a string in uppercase.

 

function UpperCase(const S: string): string;

 

 

UpperCase returns a copy of the string S, with the same text but with all 7-bit ASCII characters between 'a' and 'z' converted to uppercase. To convert 8-bit international characters, use AnsiUpperCase instead.

 

Lowercase function

 

Converts an ASCII string to lowercase.

 

function LowerCase(const S: string): string;

 

 

LowerCase returns a string with the same text as the string passed in S, but with all letters converted to lowercase. The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To convert 8-bit international characters, use AnsiLowerCase.

 

AnsiUpperCase function

 

Converts a string to upper case.

 

function AnsiUpperCase(const S: string): string;

 

 

AnsiUpperCase returns a string that is a copy of S, converted to upper case. The conversion uses the current Windows locale.

 

Note:        This function supports multi-byte character sets (MBCS).

 

AnsiLowerCase function

 

Returns a string that is a copy of the given string converted to lower case.

 

function AnsiLowerCase(const S: string): string;

 

 

AnsiLowerCase returns a string that is a copy of the given string converted to lower case. The conversion uses the current Windows locale. This function supports multi-byte character sets (MBCS).

 

CompareStr function

 

Compares two strings case sensitively.

 

function CompareStr(const S1, S2: string): Integer;

 

CompareStr compares S1 to S2, with case-sensitivity. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2. The compare operation is based on the 8-bit ordinal value of each character and is not affected by the current Windows locale.

 

AnsiCompareStr function

 

Compares strings based on the current Windows locale with case sensitivity.

 

function AnsiCompareStr(const S1, S2: string): Integer;

 

 

AnsiCompareStr compares S1 to S2, with case sensitivity. The compare operation is controlled by the current Windows locale. The return value is:

 

Condition        Return Value

S1 > S2        > 0

S1 < S2        < 0

S1 = S2        = 0

Note:        Most Windows locales consider lowercase characters to be less than the corresponding uppercase characters.  This is in contrast to ASCII order, in which lowercase characters are greater than uppercase characters.  Thus,

 

AnsiCompareStr('a','A')

returns a value less than zero, while

CompareStr('a','A')

returns a value greater than zero.

 

CompareText function

 

Compares two strings by ordinal value without case sensitivity.

 

function CompareText(const S1, S2: string): Integer;

 

 

CompareText compares S1 and S2 and returns 0 if they are equal. If S1 is greater than S2, CompareText returns an integer greater than 0. If S1 is less than S2, CompareText returns an integer less than 0. CompareText is not case sensitive and is not affected by the current Windows locale.

 

Thus for example, CompareText will indicate that the string

 

ABC

 

is less than

 

aaa

 

because A is less than a in ascii order. This is in contrast to a case-insensitive comparison, where the B would make the first string larger, or a locale-based comparison (most locales consider capital letters larger than small).

 

AnsiCompareText function

 

Compares strings based on the current Windows locale without case sensitivity.

 

function AnsiCompareText(const S1, S2: string): Integer;

 

 

AnsiCompareText compares S1 to S2, without case sensitivity. The compare operation is controlled by the current Windows locale. AnsiCompareText returns a value less than 0 if S1 < S2, a value greater than 0 if S1 > S2, and returns 0 if S1 = S2.

 

RandG function

 

Generates random numbers with Gaussian distribution.

 

function RandG(Mean, StdDev: Extended): Extended;

 

 

RandG produces random numbers with Gaussian distribution about the Mean. This is useful for simulating data with sampling errors and expected deviations from the Mean.

Random function

 

Generates random numbers within a specified range.

 

function Random [ ( Range: Integer) ];

 

 

Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range

 

0 <= X < 1.

 

To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.

 

Note:        Because the implementation of the Random function may change between compiler versions, we do not recommend using Random for encryption or other purposes that require reproducible sequences of pseudo-random numbers.

 

 

Randomize procedure

 

Initializes the random number generator with a random value.

 

procedure Randomize;

 

Randomize initializes the built-in random number generator with a random value (obtained from the system clock). The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.

 

Do not combine the call to Randomize in a loop with calls to the Random function. Typically, Randomize is called only once, before all calls to Random.

 

RandSeed procedure

 

RandSeed stores the built-in random number generator's seed.

 

procedure RandSeed(n: Integer);

 

 

By assigning a specific value to RandSeed, the Random function can repetitively generate a specific sequence of random numbers. This is useful for applications that deal with data statistics and simulations. For applications that deal with encryption see the note under the Random function.