Fórum Alguém pode me ajudar com está UDF de decodigicar data #37193

29/06/2003

0

Tenho a seguinte funçao escrita em delphi funcionando, criei um dll
se removo a clausula ´cdecl;´ funciona em delphi se deixo não funciona

mas o objetivo é usalá no IB7 mas não funciona quando digito seguinte comando ele derruba o IBServer.

este é o comando ´select decodifica(365) AS TER FROM RDB$DATABASE´
este é o parametro que usei para declarar a udf:

DECLARE EXTERNAL FUNCTION DECODIFICA
FLOAT
RETURNS CSTRING (20) FREE_IT
ENTRY_POINT ´DecodificaData´ MODULE_NAME ´dt´;


Como resolvo isto ?


está é a Funçao




library dt;

uses
SysUtils;

var
ResultString:String; //ShortString;
SaveExit:Pointer;

{$R *.res}

//function DecodificaData(data3:Double):ShortString;
function DecodificaData(data3:Double):String;
cdecl;

var data:tdatetime;
Year , Month , Day : Word;
begin
data:=data3;
DecodeDate(Data, Year, Month, Day);
if year=1899 then begin year:=0 end;
if DateToStr( Data ) = ´00/00/0000´ then

begin Day := 00; Month := 00; Year := 0000; end;

if Month > 0 then Month := Month - 1;
//if Year-1899 > 0 then Year := Year - 1; //

if Year >= 1900 then //
Year := Year-1900;

if (Day = 30) or(day = 31 ) then
begin Day := 0; Month := Month + 1; end;
if (Month = 12) then begin Month := month-month;
Year := year + 1;
end;
//if r=2 then
begin
ResultString:=FloatToStr(Day)+´D´+´/ ´+FloatToStr(Month)+´M´+´/ ´+FloatToStr(Year)+´A´;
Result:=ResultString;
end;

end;

procedure LibExit;
begin
//FreeMem(ResultString);
ExitProc:=SaveExit;
end;
exports
DecodificaData;//(data3:Double):ShortString;
begin
SaveExit:=ExitProc;
ExitProc:=@libExit;
//GetMem(resultString,256);}

end.


Lourival_martin

Lourival_martin

Responder

Posts

30/06/2003

Afarias

O Interbase não entende dados tipo ´string´ do Delphi, vc tem que usar PChar no lugar de strings.

Existem diversas ´precauções´ usando PChars (para retorno de valores em UDFs) por isso recomendo vc dar uma lida em alguns artigos.

Veja algumas informações no site http://www.ibphoenix.com/ e em http://bdn.borland.com/ ou faça uma busca no google.

No site da IBPhoenix vc encontrará algumas UDFs gratúitas escritas em Delphi (FreeUDFLib por exemplo) que vc poderá tomar como exemplo.


T+


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar