Subject | Firebird UDF |
---|---|
Author | jorge_mosquera |
Post date | 2006-11-21T14:43:34Z |
Firebird 1.5.3
Delphi 5 Enterprise
Windows XP SP2
I've write the following function inside a dll delphi
<< BEGIN FUNCTION >>
function Get_Age(Born,Limit : TDate) : String;
{*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*}
procedure SigMes(Var D1: TDate);
begin
D1 := IncMonth(D1,1)
end;
{*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*}
function Rellenar(const Valor, Largo : integer) : string;
var
cad : string;
begin
Cad := IntToStr(Valor);
if Length(cad) < Largo then
Cad := StringOfChar('0', Largo - Length(cad)) + cad;
Result := Cad;
end;
{*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*}
Var
D1 : TDate;
Meses : Integer;
ano, Mes, Dia : Integer;
begin
ano := 0;
Mes := 0;
Dia := 0;
Meses := 0;
try
if Born > Limit then begin
Result := '0000000';
exit;
end;
except
Result := '0000000';
exit;
end;
D1 := Born;
While incMonth(D1, 1) <= Limit do
begin
inc(Meses);
SigMes(D1);
end;
ano := Meses div 12;
Mes := Meses mod 12;
Dia := trunc(Limit - D1);
Result := Rellenar(Ano, 3) + Rellenar(Mes, 2) + Rellenar(Dia, 2);
end;
<< END FUNCTION >>
After, import it to firebird
declare external function Get_Age
varchar(10), Date
returns varchar(7)
entry_point 'Get_Age' module_name 'fxsitis.dll';
but when try to use it, an "access violation" appears
select fecha_nacimiento,
get_age(cast(fecha_nacimiento as Date), current_date)
from afiliados where numero_Carnet = 52000003
What's wrong?
Delphi 5 Enterprise
Windows XP SP2
I've write the following function inside a dll delphi
<< BEGIN FUNCTION >>
function Get_Age(Born,Limit : TDate) : String;
{*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*}
procedure SigMes(Var D1: TDate);
begin
D1 := IncMonth(D1,1)
end;
{*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*}
function Rellenar(const Valor, Largo : integer) : string;
var
cad : string;
begin
Cad := IntToStr(Valor);
if Length(cad) < Largo then
Cad := StringOfChar('0', Largo - Length(cad)) + cad;
Result := Cad;
end;
{*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*}
Var
D1 : TDate;
Meses : Integer;
ano, Mes, Dia : Integer;
begin
ano := 0;
Mes := 0;
Dia := 0;
Meses := 0;
try
if Born > Limit then begin
Result := '0000000';
exit;
end;
except
Result := '0000000';
exit;
end;
D1 := Born;
While incMonth(D1, 1) <= Limit do
begin
inc(Meses);
SigMes(D1);
end;
ano := Meses div 12;
Mes := Meses mod 12;
Dia := trunc(Limit - D1);
Result := Rellenar(Ano, 3) + Rellenar(Mes, 2) + Rellenar(Dia, 2);
end;
<< END FUNCTION >>
After, import it to firebird
declare external function Get_Age
varchar(10), Date
returns varchar(7)
entry_point 'Get_Age' module_name 'fxsitis.dll';
but when try to use it, an "access violation" appears
select fecha_nacimiento,
get_age(cast(fecha_nacimiento as Date), current_date)
from afiliados where numero_Carnet = 52000003
What's wrong?