Professional Documents
Culture Documents
1
...decode a TDate type ?
Author: SwissDelphiCenter.ch
2
...convert Hex codes ?
Author: SwissDelphiCenter.ch
3
...get the difference between 2 dates ?
Author: SwissDelphiCenter.ch
difference:=trunc(date1-date2);
ShowMessage(inttostr(difference));
end;
4
...get the week number of a date ?
Author: unknown
var
FirstWeekDay : Integer = 2;
{ Wochentag, mit dem die Woche beginnt
(siehe Delphi-Wochentage)
2 : Montag (nach DIN 1355) }
FirstWeekDate : Integer = 4;
{ 1 : Beginnt am ersten Januar
4 : Erste-4 Tage-Woche (nach DIN 1355)
7 : Erste volle Woche }
{ liefert die Wochennummer und das Jahr, zu dem die Woche geh rt }
{ get weeknumber and year of the given week number}
procedure DateToWeek(ADate:TDateTime; var AWeek,AYear:Word);
var
Month,Day : Word;
begin
ADate:=ADate-((DayOfWeek(ADate)-FirstWeekDay+7) mod 7)+ 7-FirstWeekDate;
DecodeDate(ADate,AYear,Month,Day);
AWeek:=(Trunc(ADate-EncodeDate(AYear,1,1)) div 7)+1;
end;
5
...get the last day of the current month ?
Author: Fred
6
a shorter way to do get the last day of the current month
Author: Henk Schreij
7
...use TTime with over 24 hours ?
Author: Zandy
8
..convert a Binary Number into a Decimal Number ?
Author: tom
9
...calculate simple arithmetical expressions ?
Author: tom
procedure NextChar;
var
s: string;
begin
if ipos > length(SMyExpression) then
begin
z := #9;
exit;
end
else
begin
s := copy(SMyExpression, ipos, 1);
z := s[1];
inc(ipos);
end;
if z = ' ' then
nextchar;
end;
10
function Expression: real;
var
w: real;
begin
w := term;
while z in ['+', '-'] do
if z = '+' then
w := w + term
else
w := w - term;
Expression := w;
end;
begin
ipos := 1;
Result := RealToStr(Expression,digits);
end;
11
procedure TForm1.Button1Click(Sender: TObject);
Var
sMyExpression : string;
begin
sMyExpression := '12.5*6+18/3.2+2*(5-6.23)';
ShowMessage(sMyExpression + ' = '+ Calculate(sMyExpression,3));
end;
12
...measure an elapsed time with a high-resolution performance counter ?
Author: Gstatter, Erhard
//Example, Beispiel:
Sie m chten eine Routine mit einer Repeat, While oder For i := ...
hinsichtlich der
durchlaufenen Zeit messen, um z. B. Optimierungsaktivit ten durchzufhren.
implementation
uses Windows, dialogs;
Procedure StartTimer;
Begin
bOK := QueryPerformanceFrequency(Res);
IF bOK THEN
QueryPerformanceCounter(t1);
end;
Procedure StopTimer;
Begin
IF bOK THEN
QueryPerformanceCounter(t2);
end;
Procedure LoopRoutine;
VAR
iCounter : integer;
Begin
StartTimer;
// Put here some kind of loop: For, While or Repeat
FOR i := 0 TO iCounter DO ...
{ WHILE....
repeat...until}
{ After the Loop/
Nach Abschluss der Schleifenroutine:}
IF bOK THEN
QueryPerformanceCounter(t2);
end;
Procedure StartSchleife;
Begin
LoopRoutine;
IF bOK THEN
{$IFDEF VER80}
// Show the elapsed time:
MessageDlg('Der Schleifendurchlauf dauerte: '+Format('%g Sekunden.',
[(t2.QuadPart-t1.Quadpart)/Res.QuadPart]));
$ELSE {$IFDEF VER120}
MessageDlg('Der Schleifendurchlauf dauerte: '+Format('%g Sekunden.',
[(t2-t1)/Res]));
{$ENDIF}
end;
...is a Time AM or PM ?
13
Author: --
procedure AM_or_PM;
begin
if(Frac(Time) < 0.5) then
ShowMessage('AM')
else
ShowMessage('PM');
end;
14
...Get the number of the day in the year ?
Author: SwissDelphiCenter.ch
15
...round a number correctly ?
Author: SwissDelphiCenter.ch
Example/ Beispiel:
x:= Round(17.5) => x = 18
16
Author: tom
function StrToHex(s : string) : LongWord;
var
b : Byte;
c : Char;
begin
Result := 0;
s := UpperCase(s);
for b := 1 to Length(s) do
begin
Result := Result * 16;
c := s[b];
case c of
'0'..'9': Inc(Result, ord(c) - ord('0'));
'A'..'F': Inc(Result, ord(c) - ord('A')+10);
else raise EConvertError.Create('Keine Hexadezimal-Zahl');
end;
end;
end;
17
... encrypt text using key numbers?
Author: Rafael Giusti
20
...convert an Integer to an octal number ?
Author: Katja Hoffmann
Homepage: http://www.katjahoffmann.gmxhome.de
function IntToOct(value:longint; digits:integer):string;
var
rest : longint;
oct : string;
i : integer;
begin
oct := '';
while value > 0 do
begin
rest := value mod 8;
value := value div 8;
oct := inttostr(rest)+oct;
end;
for i := length(oct)+1 to digits do
oct := '0'+oct;
result := oct;
end;
21
...convert an octal number to integer ?
Author: Katja Hoffmann
Homepage: http://www.katjahoffmann.gmxhome.de
function OctToInt(value:string):longint;
var
i : integer;
int: integer;
begin
int:=0;
for i:=1 to length(value) do
begin
int:=int*8+strtoint(copy(value,i,1));
end;
result:=int;
end;
22
...round numbers to a predetermined number of decimals ?
Author: Dean
23
Its good, but, try this...
Author: Srgio Alexandre
24
...convert a decimal number to roman numerals ?
Author: Thomas Stutz
Homepage: http://www.swissdelphicenter.ch
function DecToRoman(Decimal: LongInt): String;
const
Numbers : Array[1..13] of Integer =
(1, 4, 5, 9, 10, 40, 50, 90, 100,
400, 500, 900, 1000);
Romans: Array[1..13] of string =
('I', 'IV', 'V', 'IX', 'X', 'XL',
'L', 'XC', 'C', 'CD', 'D', 'CM', 'M');
var
i: Integer;
begin
Result := '';
for i := 13 downto 1 do
while (Decimal >= Numbers[i]) do
begin
Decimal := Decimal - Numbers[i];
Result := Result + Romans[i];
end;
end;
//Example:
//Beispiel:
25
...check if the Cursor is on a line ?
Author: Johannes Steiner
{
Check if a Point(X,Y) (e.g a Cursor) is on a Linie (x1,y1) ; (x2,y2)
d = line width (min. 1)
Testen, ob sich der Punkt(X,Y) (z.B der Maus-Cursor) auf der Linie x1,y1 nach
x2,y2 befindet.
d = halbe Liniendicke (min 1)
durch direkte Programmierung der FPU wird die Unit Math nicht ben tigt
nur mit 80387 oder h her einsetzbar!
}
26
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
p : TPoint;
begin
GetCursorPos(p);
p := ScreenToClient(p);
if CursorOnLinie(p.x,p.y,0,0,Width,Height,1) then
Caption := 'Mouse on line.'
else
Caption := 'Mouse not on line.'
end;
27
...calculate the value of a polynomial at a given point ?
Author: Los Bgu
// Simultaneous evaluation of a given polynomial and its first derivative at
a given point
// Simultane Berechnung des Wertes eines Polynoms n-ten Grades und seiner
Ableitung
Type
TPolynomArray = Array of Double;
X := 2.5;
Horner(VarArrayOf([-97,19,-59,13,4,3]),X,FX,derivation);
Showmessage(Format('x = %n'#13#10'f(x) = %n'#13#10'f''(x) = %n',
[X,FX,derivation]));
end;
28
...check if a number is prime ?
Author: Hagen Reddmann
30
...fastly retrieve the high-order word from 32bit var ?
Author: Martin
The HiWord function retrieves the high-order word
from the given 32-bit value.
********
Die HiWord Funktion extrahiert die das h herwertige Wort (Word) von einem
gegebenen 32-bit Wert.
31
...invert a matrix ?
Author: Kiro Georgiev
type
RCOMat = array of array of Extended;
var
DimMat: integer;
irow := 1;
icol := 1;
for i := 0 to Pred(DimMat) do
begin
big := 0;
for j := 0 to Pred(DimMat) do
begin
if (ipiv[j] <> 1) then
begin
for k := 0 to Pred(DimMat) do
begin
if (ipiv[k] = 0) then
if (Abs(aa[j, k]) >= big) then
begin
big := Abs(aa[j, k]);
irow := j;
icol := k;
end else;
end;
end;
end;
ipiv[icol] := ipiv[icol] + 1;
if (irow <> icol) then
begin
for l := 0 to Pred(DimMat) do
begin
dum := aa[irow, l];
aa[irow, l] := aa[icol, l];
aa[icol, l] := dum;
end;
for l := 0 to Pred(DimMat) do
begin
dum := aa[irow + DimMat + 1, l];
aa[irow + DimMat + 1, l] := aa[icol + DimMat + 1, l];
aa[icol + DimMat + 1, l] := dum;
end;
end;
indxr[i] := irow;
indxc[i] := icol;
if (aa[icol, icol] = 0) then;
32
pivinv := 1.0 / aa[icol, icol];
aa[icol, icol] := 1.0;
for l := 0 to Pred(DimMat) do aa[icol, l] := aa[icol, l] * pivinv;
for l := 0 to Pred(DimMat) do aa[icol + DimMat + 1, l] :=
aa[icol + DimMat + 1, l] * pivinv;
for ll := 0 to Pred(DimMat) do
begin
if (ll <> icol) then
begin
dum := aa[ll, icol];
aa[ll, icol] := 0.0;
for l := 0 to Pred(DimMat) do aa[ll, l] := aa[ll, l] aa
[icol, l] * dum;
for l := 0 to Pred(DimMat) do aa[ll + DimMat + 1, l] :=
aa[ll + DimMat + 1, l] - aa[icol + DimMat + 1, l] *
dum;
end;
end;
end;
33
...calculate the factorial of a given number ?
Author: Los B gu
Homepage: www.begue.de
{
The factorial of a positive integer is defined as:
Die Fakultt einer positiven Nummer ist wie folgt definiert:
n! = n*(n-1)*(n-2)*(n-3)*...*2*1
1! = 1
0! = 1
Example/Beispiel: 5! = 5*4*3*2*1
}
34
...Draw the Mandelbrot Fractal?
Author: Max Kleiner
Homepage: http://max.kleiner.com
35
procedure TForm1.Button1Click(Sender: TObject);
var
R: TRect;
au, ao: Integer;
dX, dY, bo, bu: Double;
begin
// Initialize Mandelbrot
R.Left := 0;
R.Right := 200;
R.Top := 0;
R.Bottom := 205;
ao := 1;
au := -2;
bo := 1.5;
bu := -1.5;
//direct scaling cause of speed
dX := (ao - au) / (R.Right - R.Left);
dY := (bo - bu) / (R.Bottom - R.Top);
DrawMandelbrot(Self.Canvas, dX, dY, au, bu, R.Right, R.Bottom);
end;
36
...convert numbers from one base to another?
Author: Emiliano Alvarez
Homepage: http://www.mainhattan.de.vu/
function BaseConvert(NumIn: string; BaseIn: Byte; BaseOut: Byte): string;
var
i: integer;
currentCharacter: char;
CharacterValue: Integer;
PlaceValue: Integer;
RunningTotal: Double;
Remainder: Double;
BaseOutDouble: Double;
NumInCaps: string;
s: string;
begin
if (NumIn = '') or (BaseIn < 2) or (BaseIn > 36) or (BaseOut < 1) or
(BaseOut > 36) then
begin
Result := 'Error';
Exit;
end;
NumInCaps := UpperCase(NumIn);
PlaceValue := Length(NumInCaps);
RunningTotal := 0;
for i := 1 to Length(NumInCaps) do
begin
PlaceValue := PlaceValue - 1;
CurrentCharacter := NumInCaps[i];
CharacterValue := 0;
if (Ord(CurrentCharacter) > 64) and (Ord(CurrentCharacter) < 91) then
CharacterValue := Ord(CurrentCharacter) - 55;
if CharacterValue = 0 then
if (Ord(CurrentCharacter) < 48) or (Ord(CurrentCharacter) > 57) then
begin
BaseConvert := 'Error';
Exit;
end else
CharacterValue := Ord(CurrentCharacter);
37
if Remainder >= 10 then
CurrentCharacter := Chr(Trunc(Remainder + 55))
else
begin
s := IntToStr(trunc(remainder));
CurrentCharacter := s[Length(s)];
end;
Result := CurrentCharacter + Result;
end;
end;
// Example, Beispiel
38
...determine if a number is prime, quickly (2)?
Author: John A. Stockton
{ *** HTPrimes
**************************************************************
author: john.a.stockton@btopenworld.com
Comments, suggestions, bug reports -- all welcome.
***************************************************************************
***************************************************************************
}
unit HTPrimes;
const
MaxPrime = High(Cardinal) - 4;
{ The highest prime in the range of the Cardinal type.
P(203,280,221) = 4,294,967,291. }
type
TPrimeFactor = record
p, q: Cardinal;
end;
39
{ Record and dynamic array types used by the GetPrimeFactors function
(see below). }
40
function IsSeniorTwin(Nmbr: Cardinal): Boolean;
{ True if Nmbr and Nmbr - 2 form a twin pair. }
False if Nmbrs are not mutually relatively prime, or if Nmbrs has less
than
two elements. }
False if Nmbrs are not pairwise relatively prime, or if Nmbrs has less
than
two elements. }
uses Math;
{$B-}
43
{ ******************************* function MulMod (safe but slow version)
***
function MulMod(x, y, m: Cardinal): Cardinal;
var
i, j: Cardinal;
begin
i := x mod m;
j := y mod m;
asm
mov eax, i
mul j
div m
mov i, edx
end;
MulMod := i;
end; }
44
Result := (i = N - 1);
Inc(r);
end;
end;
end; { function StrongProbablePrime }
WeakProbablePrime := (i = 1);
end;
end; { function WeakProbablePrime }
45
begin
{ Not quite as trivial as negating IsPrime(Nmbr), but almost. }
IsComposite := (Nmbr > 3) and (not IsPrime(Nmbr));
end; { function IsComposite }
{ Store the found factor. Append it to Fctrs if it's not already known,
otherwise increment the exponent. }
if (i > k) then
begin
k := i;
SetLength(Fctrs, Length(Fctrs) + 1);
Fctrs[High(Fctrs)].p := i;
Fctrs[High(Fctrs)].q := 1;
end else
Inc(Fctrs[High(Fctrs)].q);
{ Divide Nmbr by the last factor found. If this doesn't reduce Nmbr to
one then go back to find the lowest prime factor of the new value. }
Nmbr := Nmbr div i;
until (Nmbr = 1);
end;
end; { function GetPrimeFactors }
49
else if IsPrime(Nmbr) then
Result := Nmbr
else
begin
Result := 2;
while ((Nmbr mod Result) > 0) do
Result := NextPrime(Result);
end;
end; { function LeastPrimeFactor }
50
Result := 0
else
begin
j := Low(Nmbrs);
Result := GreatestCommonDivisor(Nmbrs[j], Nmbrs[j + 1]);
for i := j + 2 to High(Nmbrs) do
Result := GreatestCommonDivisor(Result, Nmbrs[i]);
end;
end; { function GreatestCommonDivisor(Nmbrs: array of Cardinal) }
51
Result := (Length(Nmbrs) > 1);
if Result then
begin
i := Low(Nmbrs);
while (Result and (i <= High(Nmbrs))) do
begin
j := i + 1;
while (Result and (j <= High(Nmbrs))) do
begin
Result := (Result and AreRelativelyPrime(Nmbrs[i], Nmbrs[j]));
Inc(j);
end;
Inc(i);
end;
end;
end; { function ArePairwisePrime }
52
Result := 0;
if ((Nmbr > 2) and ((Nmbr and 1) = 0)) then
begin
i := 2;
while (i <= (Nmbr div 2)) do
begin
if IsPrime(Nmbr - i) then
Inc(Result);
i := NextPrime(i);
end;
end;
end; { function CountGoldbachPairs }
To
do ---------------------------------------------------------------------
Any suggestions?
v1.1, 13 June
2002 --------------------------------------------------------
Additions:
function WeakProbablePrime
function PseudoPrime
function StrongPseudoprime
function RandomPrime
Changes:
01 Moved IsPrime's declaration to make it more obvious.
02 MulMod: Promoted so WeakProbablePrime can use it.
53
03 Mulmod: 'Safe' version re-written to permit SPRP and PRP with large
bases.
04 IsPrime: Shortened the prime factor list. The shorter list seems to
be more efficient in combination with the SPRP tests.
05 IsPrime: Scrapped the restriction that (trial factor) <= Sqrt(Nmbr).
With the short prime factor list, calculating Trunc(Sqrt(Nmbr))
is an unwarranted overhead. Also replaced the while loop with a
repeat until loop, because it looks neater and doesn't damage
performance.
v1.0, 12 June
2002 --------------------------------------------------------
Original release. }
54
...use Base64 encoding and decoding?
Author: Steve Schafer
Homepage: http://www.teamb.com
function Decode(const S: AnsiString): AnsiString;
const
Map: array[Char] of Byte = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0);
var
I: LongInt;
begin
case Length(S) of
2: begin
I := Map[S[1]] + (Map[S[2]] shl 6);
SetLength(Result, 1);
Move(I, Result[1], Length(Result))
end;
3: begin
I := Map[S[1]] + (Map[S[2]] shl 6) + (Map[S[3]] shl 12);
SetLength(Result, 2);
Move(I, Result[1], Length(Result))
end;
4: begin
I := Map[S[1]] + (Map[S[2]] shl 6) + (Map[S[3]] shl 12) +
(Map[S[4]] shl 18);
SetLength(Result, 3);
Move(I, Result[1], Length(Result))
end;
end;
end;
55
function Encode(const S: AnsiString): AnsiString;
const
Map: array[0..63] of Char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
'abcdefghijklmnopqrstuvwxyz0123456789+/';
var
I: LongInt;
begin
I := 0;
Move(S[1], I, Length(S));
case Length(S) of
1: Result := Map[I mod 64] + Map[(I shr 6) mod 64];
2: Result := Map[I mod 64] + Map[(I shr 6) mod 64] +
Map[(I shr 12) mod 64];
3: Result := Map[I mod 64] + Map[(I shr 6) mod 64] +
Map[(I shr 12) mod 64] + Map[(I shr 18) mod 64]
end
end;
56
...Calculate Easter Day for a specified year?
Author: Mark Lussier
function Easter(Year: Integer): TDateTime;
{----------------------------------------------------------------}
{ Calculates and returns Easter Day for specified year. }
{ Originally from Mark Lussier, AppVision <MLussier@best.com>. }
{ Corrected to prevent integer overflow if it is inadvertently }
{ passed a year of 6554 or greater. }
{----------------------------------------------------------------}
var
nMonth, nDay, nMoon, nEpact, nSunday, nGold, nCent, nCorx, nCorz: Integer;
begin
{ The Golden Number of the year in the 19 year Metonic Cycle: }
nGold := (Year mod 19) + 1;
{ Calculate the Century: }
nCent := (Year div 100) + 1;
{ Number of years in which leap year was dropped in order... }
{ to keep in step with the sun: }
nCorx := (3 * nCent) div 4 - 12;
{ Special correction to syncronize Easter with moon's orbit: }
nCorz := (8 * nCent + 5) div 25 - 5;
{ Find Sunday: }
nSunday := (Longint(5) * Year) div 4 - nCorx - 10;
{ ^ To prevent overflow at year 6554}
{ Set Epact - specifies occurrence of full moon: }
nEpact := (11 * nGold + 20 + nCorz - nCorx) mod 30;
if nEpact < 0 then
nEpact := nEpact + 30;
if ((nEpact = 25) and (nGold > 11)) or (nEpact = 24) then
nEpact := nEpact + 1;
{ Find Full Moon: }
nMoon := 44 - nEpact;
if nMoon < 21 then
nMoon := nMoon + 30;
{ Advance to Sunday: }
nMoon := nMoon + 7 - ((nSunday + nMoon) mod 7);
if nMoon > 31 then
begin
nMonth := 4;
nDay := nMoon - 31;
end else
begin
nMonth := 3;
nDay := nMoon;
end;
Easter := EncodeDate(Year, nMonth, nDay);
end; {Easter}
57
...calculate the german holidays?
Author: Benny Baumann
unit Feiertage;
// Unit Holidays;
interface
uses
Windows, SysUtils;
// Function to call to get the Holiday Table with all Holidays of a year
// Der Funktionsaufruf, um die Feiertage eines Jahres abzufragen
function GetHolidayTable(Year: Word): THolidayTable;
implementation
58
// Function to get easter sunday
// Function zur Berechnung des Ostersonntags
function GetEasterDate(YYYY: Word): TDateTime;
var
A, B, C, D, E, F, G, H, I, K, L, M, N, P: Word;
DD, MM: Word;
begin
a := YYYY mod 19;
b := YYYY div 100;
c := YYYY mod 100;
d := b div 4;
e := b mod 4;
f := (b + 8) div 25;
g := (b - f + 1) div 3;
h := (19 * a + b - d - g + 15) mod 30;
i := c div 4;
k := c mod 4;
l := (32 + 2 * e + 2 * i - h - k) mod 7;
m := (a + 11 * h + 22 * l) div 451;
n := (h + l - 7 * m + 114) div 31;
p := (h + l - 7 * m + 114) mod 31 + 1;
DD := p;
MM := n;
Result := EncodeDate(YYYY, MM, DD);
end;
var
EDate: TDateTime;
begin
// Add fixed holidays
// Hinzufgen der festen Feiertage
AddHoliday(1, 1, 'Neujahr');
AddHoliday(1, 5, 'Tag der Arbeit');
AddHoliday(3, 10, 'Tag der deutschen Einheit');
AddHoliday(31, 10, 'Reformationstag');
// AddHoliday(24, 12, 'Heiligabend');
AddHoliday(25, 12, '1. Weihnachtsfeiertag');
AddHoliday(26, 12, '2. Weihnachtsfeiertag');
// AddHoliday(31, 12, 'Silvester');
// Add holidays relative to easter sunday
// Hinzufgen der Feiertage, die von Ostern abhngen
EDate := GetEasterDate(Year);
AddHoliday(EDate, 'Ostersonntag');
AddHoliday(EDate - 2, 'Karfreitag');
AddHoliday(EDate + 1, 'Ostermontag');
AddHoliday(EDate + 39, 'Christi Himmelfahrt');
AddHoliday(EDate + 49, 'Pfingstsonntag');
AddHoliday(EDate + 50, 'Pfingstmontag');
// Gets 3rd Wednesday in November
// Ermittelt den 3. Mitwoch im November
EDate := EncodeDate(Year, 11, 1);
EDate := EDate + ((11 - DayOfWeek(EDate)) mod 7) + 14;
AddHoliday(EDate, 'Bu- und Bettag');
end;
end.
var
r: IntNo;
begin
r := Multiply(40000000, 80000000);
ShowMessage(IntToStr(r.Hi32) + ', ' + IntToStr(r.low32))
end;
61
...calculate the logarithm for a variable base?
Author: Alexander Schimpf
Homepage: http://www.hitstec.de
(*
*)
62
...validate an IBAN?
Author: Katja Hoffmann
Homepage: http://www.katjahoffmann.gmxhome.de
// IBAN = International Bank Account Number
// Example : CH10002300A1023502601
63
begin
iban := StringReplace(iban, ' ', '', [rfReplaceAll]);
if CalculateDigits(iban) = 1 then
Result := True
else
Result := False;
end;
64
...calculate the age of a person?
Author: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
65
...sort an Array with the Shell Sort Algorithm?
Author: Stormer
{
The following procedure sorts an Array with the
fast Shell-Sort algorithm.
Invented by Donald Shell in 1959,
the shell sort is the most efficient of the O(n2)
class of sorting algorithms
}
{
Die folgende Prozedur Sortiert ein Array mit
dem schnellem Shell-Sort Algorithmus.
}
end;
66
...find the greatest common factor (GCF) of integers?
Homepage: http://www.geocities.com/peter_bone_uk
{
The greatest common factor, or GCF, is the greatest factor
that divides two numbers.
}
{
Der GGT zweier Zahlen ist der gr te gemeinsame Teiler
dieser Zahlen, also die gr te Zahl, durch die beide
Zahlen teilbar sind.
}
uses
math;
// Example:
procedure TForm1.Button1Click(Sender: TObject);
var
Res: Integer;
begin
Res := GCF(120, 30);
ShowMessage(Inttostr(Res));
end;
67
{******************}
Result := 1;
68