Subject UDF for formatting dates/times
Author Rick Roen
Firebird 1.5
Delphi 7 Pro

I'm confused about why my UDF works when I declare like this:

function fbFormatDateTime( FormatStr: PChar; var Year, Month, Day,
Hour, Min: Integer ): PChar; cdecl; export;

____________________

and does not work (disconnects from FB server upon execution) when
declared like this:

function fbFormatDateTime( FormatStr: PChar; Year, Month, Day, Hour,
Min: Integer ): PChar; cdecl; export;

_______________

The difference is in the "var" declaration before the year, month
etc.

BTW, I am just looking to format dates and times from within a SP
and could not find any other appropriate UDF in the free UDF
libraries. Is there something better available?

Also, I assume since I am using PChars and CStrings that I do not
need further memory freeing - is that correct?

Thanks,

Rick

Here is the full declaration in FB:

DECLARE EXTERNAL FUNCTION F_FORMAT_DATETIME
CSTRING(30),
INTEGER,
INTEGER,
INTEGER,
INTEGER,
INTEGER
RETURNS CSTRING(60)
ENTRY_POINT 'fbFormatDateTime' MODULE_NAME 'Primavera_UDF';

And here is the full Delphi UDF declaration:

function fbFormatDateTime( FormatStr: PChar; var Year, Month, Day,
Hour, Min: Integer ): PChar; cdecl; export;
var
Str: String;
begin
if not ( ( (Year>=1990) and (Year<=2100) ) and
( (Month>=1) and (Month<=12) ) and
( (Day>=1) and (Day<=31) ) and
( (Hour>=0) and (Hour<=23) ) and
( (Min>=0) and (Min<=60) ) ) then begin
Result := PChar( 'date/time error' );
Exit;
end;

Str := FormatDateTime( FormatStr, EncodeDateTime( Year, Month,
Day, Hour, Min, 0, 0 ) );
Result := PChar( Str );
end;