Ditulis oleh arifw di/pada Kamis, 24 April 2008

function ChangeAlpha(input: string): string;
var
a: Char;
begin
Result := input;
for a := ‘A’ to ‘Z’ do
begin
Result := StringReplace(Result, a, IntToStr(Ord(a) – 55), [rfReplaceAll]);
end;
end;
function CalculateDigits(iban: string): Integer;
var
v, l: Integer;
alpha: string;
number: Longint;
rest: Integer;
begin
iban := UpperCase(iban);
if Pos(‘IBAN’, iban) > 0 then
Delete(iban, Pos(‘IBAN’, iban), 4);
iban := iban + Copy(iban, 1, 4);
Delete(iban, 1, 4);
iban := ChangeAlpha(iban);
v := 1;
l := 9;
rest := 0;
alpha := ”;
try
while v <= Length(iban) do
begin
if l > Length(iban) then
l := Length(iban);
alpha := alpha + Copy(iban, v, l);
number := StrToInt(alpha);
rest := number mod 97;
v := v + l;
alpha := IntToStr(rest);
l := 9 – Length(alpha);
end;
except
rest := 0;
end;
Result := rest;
end;
function CheckIBAN(iban: string): Boolean;
begin
iban := StringReplace(iban, ‘ ‘, ”, [rfReplaceAll]);
if CalculateDigits(iban) = 1 then
Result := True
else
Result := False;
end;
Author: www.swissdelphicenter.ch
Ditulis dalam Delphi, Math, Programming | Bertanda: Math | Leave a Comment »
Ditulis oleh arifw di/pada Kamis, 24 April 2008

function CalculateAge(Birthday, CurrentDate: TDate): Integer;
var
Month, Day, Year, CurrentYear, CurrentMonth, CurrentDay: Word;
begin
DecodeDate(Birthday, Year, Month, Day);
DecodeDate(CurrentDate, CurrentYear, CurrentMonth, CurrentDay);
if (Year = CurrentYear) and (Month = CurrentMonth) and (Day = CurrentDay) then
begin
Result := 0;
end
else
begin
Result := CurrentYear – Year;
if (Month > CurrentMonth) then
Dec(Result)
else
begin
if Month = CurrentMonth then
if (Day > CurrentDay) then
Dec(Result);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := Format(‘Your age is %d’, [CalculateAge(StrToDate('01.03.1953'), Date)]);
end;
Ditulis dalam Delphi, Math, Programming | Bertanda: Math | Leave a Comment »
Ditulis oleh arifw di/pada Kamis, 24 April 2008

function PntInTriangle(Px, Py, x1, y1, x2, y2, x3, y3: Double): Boolean;
var
Or1, Or2, Or3: Double;
begin
Or1 := Orientation(x1, y1, x2, y2, Px, Py);
Or2 := Orientation(x2, y2, x3, y3, Px, Py);
Or3 := Orientation(x3, y3, x1, y1, Px, Py);
Result := (Or1 = Or2) and (Or2 = Or3);
end;
function Orientation(x1, y1, x2, y2, Px, Py: Double): Integer;
var
Orin: Double;
begin
Orin := (x2 – x1) * (py – y1) – (px – x1) * (y2 – y1);
if Orin > 0.0 then Result := +1
else if Orin < 0.0 then Result := -1
else
Result := 0;
end;
Ditulis dalam Delphi, Math, Programming | Bertanda: Math | Leave a Comment »