Standard Functions in r_keeper 7


Arithmetic Functions

Function Abs(e : Extended) : Extended;

Returns the absolute value of the e parameter (e in modulus)


Div

Performs integer division without a remainder

int := 17 Div 2;

Function Random(i : integer) : Integer;

Generates an integer within the specified range

x:=Random(100); the x variable will be assigned an integer value ranging from 0 to 100

function Round ( const Number : Extended ) : Integer;

Rounding floating-point numbers to an integer

ShowMessage('Round(12.75) = '+IntToStr(Round(12.75)));

Round(12.75) = 13

function Trunc ( const Number : Extended ) : Integer;

Integer part of a floating-point number

ShowMessage('Trunc(12.75) = '+IntToStr(Trunc(12.75)));

Trunc(12.75) = 12

function IntToHex ( DecimalValue : Integer; MinimumWidth : Integer ) : string;

Converts a DecimalValue integer to a hexadecimal string having no less than MinimumWidth characters

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

Time Functions

Now : TDateTime

Displays current date and time

today := Now;

Date : TDateTime

Displays current date

today := Date;

Time : TDateTime

Displays current time

today := Time;

Function DayOfWeek ( Date : TDateTime ) : Integer;

Displays the day of the week index for the TDateTime value

//1 = 

Displays the day of the week index for the TDateTime value

//2 = Monday

//3 = Tuesday

//4 = Wednesday

//5 = Thursday

//6 = Friday

//7 = Saturday

if (DayOfWeek(Now)>=2) then // day of the week check

Function DayOfTheYear ( const  Date : TDateTime) : integer

Displays day of the year index

In contrast to pascal, the value for January 1 is 0 and not 1

d:=DayOfTheYear(Now)+1;


Function EncodeTime ( const Hour, Min, Sec, MSec : Integer ) : TDateTime;

Generates the TDateTime value from the hour, minute, second and millisecond values.

myDate := EncodeTime(12, 34, 56, 789);

Function EncodeDate ( const Year, Month, Day : Integer ) : TDateTime;

Generates the TDateTime value from the year, month and day values

myDate := EncodeDate(2000, 02, 29);

Function StrToTime ( const Time : string ) : TDateTime;

Converts a string containing the time in a specific format to the value of the TDateTime type

myTime := StrToTime('15:22:35');

Function StrToDate ( const Date : string ) : TDateTime;

Converts the date string to the value of the TDateTime type

myDate := StrToDate('15/03/75');

procedure DecodeTime ( const SourceDateTime : TDateTime; out Hour, Min, Sec, MSec : Integer ) ;

Divides the TDateTime value into separate time values

DecodeTime(myDate, myHour, myMin, mySec, myMilli);

procedure DecodeDate ( const SourceDate : TDateTime; out Year, Month, Day : Integer ) ;

Extracts the year, month and day values from the TDateTime variable

DecodeDate(myDate, myYear, myMonth, myDay);

String Functions

function StrGet(var S : String; I : Integer) : Char;

Returns the S string element with the I index


procedure StrSet(c : Char; I : Integer; var s : String);

Assigns the c value to the element with the I index in the S string


function Uppercase(s : string) : string;

Displays the s string in the upper case


function Lowercase(s : string) : string;

Displays the s string in the lower case


function Trim(s : string) : string;

Displays the s string without spaces and service characters at the beginning and at the end


function Length(s : String) : Longint;

Displays the s string length


procedure SetLength(var S: String; L: Longint);

Sets the S string size as the L value


function inttostr(i: Longint): string;

Converts an i interger value into a string


Int64ToStr(parametr :Int64):string;

Converts an Int64 i interger value into a string


function strtoint(s: string): Longint;

Converts the s string into an integer value


StrToInt64(parametr: String): int64;

Converts the s string into an Int64 integer value


function strtointdef(s: string; def: Longint): Longint;

Converts the s string into an integer value but displays the pre-defined def value for an undefined string


function copy(s: string; ifrom, icount: Longint): string;

Displays the substring of the s string that contains the character icount starting from the character having the ifrom number


function pos(substr, s: string): Longint;

The function searches for the first occurence of the Substr string in the S string and displays the integer value that is the index of the first Substr character in the S. If the Substr string is not found, Pos displays 0


procedure delete(var s: string; ifrom, icount: Longint);

Deletes the icount number of characters from the S string starting from the ifrom position


procedure insert(s: string; var s2: string; ipos: Longint);

Inserts the s string into the s2 string from the ipos position


function StrToFloat(s: string): Extended;

Displays a real (floating point) number converted from the s string


function TimeToStr ( Time : TDateTime ) : string;

Converts the time value of the TDateTime type into a string


function DateToStr ( Date : TDateTime ) : string;

Converts the TDateTime date value into a string


function FloatToStr(e : Extended) : String;

Displays the e value as a string


function Padl(s : string; I : longInt) : string;

Displays the s character string consisting of the set expression with spaces added to reach the indicated l length on the left


function Padr(s : string; I : longInt) : string;

Displays the s character string consisting of the set expression with spaces added to reach the indicated l length on the right


function Padz(s : string; I : longInt) : string;

Displays the s character string consisting of the set expression with zeros added to reach the indicated l length on the left


function Replicate(c : char; I : longInt) : string;

Displays the character string consisting of the set c character repeated l times


function StringOfChar(c : char; I : longInt) : string;

The function creates a new string of the l length filled with c characters


Function FormatDateTime ( const Formatting : string; DateTime : TDateTime ) : string;

The FormatDateTime function ensures rich formatting of the TDateTime DateTime value into a string. Formatting is defined by the Formatting string.

The Formatting string can contain a mixture of ordinary characters, transferred to the result string unchanged, and data formatting characters. Formatting is best explained using an example code.

The following (non-Asian) strings of a formatting character can be used in the formatting string:


y = Year as last two digits

yy = Year as last two digits

yyyy = Year as all four digits

m = Month number without 0

mm = Month number as two digits

mmm = Month using ShortDayNames (Jan)

mmmm = Month using LongDayNames (January)

d = Date without 0

dd = Date as two digits

ddd = Day using ShortDayNames (Sun)

dddd = Day using LongDayNames (Sunday)

ddddd = Date in ShortDateFormat

dddddd = Date in LongDateFormat


c = Using ShortDateFormat + LongTimeFormat

h = Hour without 0

hh = Hour as two digits

n = Minutes without 0

nn = Minutes as two digits

s = Seconds without 0

ss = Seconds as two digits

z = Milliseconds without 0

zzz = Milliseconds as two digits

t = Using ShortTimeFormat

tt = Using LongTimeFormat


am/pm = Used after h : displays 12 hours + am/pm

a/p = Used after h : displays 12 hours + a/p

ampm = As a/p but TimeAMString,TimePMString

/ = Substituted with the DateSeparator value

: = Substituted with the TimeSeparator value


In addition to this formatting, various above-mentioned options are affected by the following variables with their value as the default value:


DateSeparator = /

TimeSeparator = :

ShortDateFormat = dd/mm/yyyy

LongDateFormat = dd mmm yyyy

TimeAMString = AM

TimePMString = PM

LongTimeFormat = hh:mm:ss

ShortMonthNames = Jan, Feb ...

LongMonthNames = January, February ...

ShortDayNames = Sun, Mon ...

LongDayNames = Sunday, Monday ...

TwoDigitYearCenturyWindow = 50

var

  myDate : TDateTime;


begin

  // Inserting your TDateTime variable into the full date and time value:

  // 09/02/2000 в 01:02:03.004  (.004 milliseconds)

  myDate := EncodeDateTime(2000, 2, 9, 1, 2, 3, 4);


  // Only date: numeric values without zeros at the beginning (except for the year)

  ShowMessage('              d/m/y = '+

              FormatDateTime('d/m/y', myDate));


  // Only date: numeric values with zeros at the beginning

  ShowMessage('           dd/mm/yy = '+

              FormatDateTime('dd/mm/yy', myDate));


  // Using short names for days and months and adding a free-format text ('of')

  ShowMessage('  ddd d of mmm yyyy = '+

              FormatDateTime('ddd d of mmm yyyy', myDate));


  // Using long names for days and months

  ShowMessage('dddd d of mmmm yyyy = '+

              FormatDateTime('dddd d of mmmm yyyy', myDate));


  // Using only ShortDateFormat settings

  ShowMessage('              ddddd = '+

              FormatDateTime('ddddd', myDate));


  // Using only LongDateFormat settings

  ShowMessage('             dddddd = '+

              FormatDateTime('dddddd', myDate));


  // Using the settings ShortDateFormat + LongTimeFormat

  ShowMessage('                  c = '+

              FormatDateTime('c', myDate));

end;


d/m/y = 9/2/00

dd/mm/yy = 09/02/00

ddd d of mmm yyyy = Wed 9 Feb 2000

dddd d of mmmm yyyy = Wednesday 9 February 2000

ddddd = 09/02/2000

dddddd = 09 February 2000

c = 09/02/2000 01:02:03

function FormatFloat(const Mask: string; d : Extended) : String;

The function ensures rich formatting of a Value floating-point number into a string.


The formatting string can contain a mixture of free-format text and control characters:

0: Displays numbers or 0

#: Additional numeric representation

,: Displays thousands

.: Displays decimal numbers

E+: Displays a character exponent

E-: Additional exponent character representation

;: Separator for positive, negative and zero values

var

  float : extended;


begin

  // Setting your own floating-point number

  float := 1234.567;


  // Displaying a typical value using all format options


  // Rounding a decimal value

  ShowMessage('##### : '+FormatFloat('#####', float));

  ShowMessage('00000 : '+FormatFloat('00000', float));

  ShowMessage('0 : '+FormatFloat('0'    , float));

  ShowMessage('#,##0 : '+FormatFloat('#,##0', float));

  ShowMessage(',0 : '+FormatFloat(',0'   , float));

  ShowMessage('');


  // Allowing a decimal value

  ShowMessage('0.#### : '+FormatFloat('0.####', float));

  ShowMessage('0.0000 : '+FormatFloat('0.0000', float));

  ShowMessage('');


  // Scientific Format

  ShowMessage('0.0000000E+00 : '+FormatFloat('0.0000000E+00', float));

  ShowMessage('0.0000000E-00 : '+FormatFloat('0.0000000E-00', float));

  ShowMessage('#.#######E-## : '+FormatFloat('#.#######E-##', float));

  ShowMessage('');


  // Allowing a free-format text

  ShowMessage('"Value = "0.0 : '+FormatFloat('"Value = "0.0', float));

  ShowMessage('');


  // Different format of negative numbers

  ShowMessage('0.0 : '+FormatFloat('0.0'              , -1234.567));

  ShowMessage('0.0 "CR";0.0 "DB" : '+

              FormatFloat('0.0 "CR";0.0 "DB"', -1234.567));

  ShowMessage('0.0 "CR";0.0 "DB" : '+

              FormatFloat('0.0 "CR";0.0 "DB"',  1234.567));

  ShowMessage('');


  // Different format of zero values

  ShowMessage('0.0 : '+FormatFloat('0.0' , 0.0));

  ShowMessage('0.0;-0.0;"Nothing" : '+

              FormatFloat('0.0;-0.0;"Nothing"', 0.0));

end;


##### : 1235

00000 : 01235

0 : 1235

#,##0 : 1,235

,0 : 1,235


0.#### : 1234.567

0.0000 : 1234.5670


0.0000000E+00 : 1.2345670E+03

0.0000000E-00 : 1.2345670E03

#.#######E-## : 1.234567E3


"Value = " : Value = 1234.6


0.0 : -1234.6

0.0 "CR";0.0 "DB" : 1234.6 DB

0.0 "CR";0.0 "DB" : 1234.6 CR


0.0 : 0.0

0.0;-0.0;"Nothing" : Nothing

Array Handling

function getarraylength(var v: array): Integer;

Displays the v array length


procedure setarraylength(var v: array; i: Integer);

Sets the v array length as the i value


Work with the Variant Type

function VarGetType(x: Variant): TVarType;

Displays the type code of data contained in the variable x


function Null: Variant;

Returns the NULL value


  • No labels