Passing and Returning Dates to a Delphi-created UDF

By: Borland Staff

Abstract: A Protection Exception or erroneous results may occur if special precautions are not taken

Using a UDF that takes date values as parameters or returns 
date values may result in a Protection Exception or erroneous 
results if the DLL does not take special precautions to 
protect the date values.

Each date value is stored in two 32-bit integers: a signed integer 
for the date, and a unsigned integer for the time. Use this Delphi 
code to define this structure (ISC_QUAD) and the pointer to this 
structure (PISC_QUAD):

   {InterBase Date/Time Record}
   ISC_QUAD = record
      isc_quad_high : Integer ;  // Date
      isc_quad_low  : Cardinal ; // Time

To protect the return value, declare a thread-safe ISC_QUAD variable 
outside of the function definition that will hold the return value 
(if the return value is a date).

   tempquad : ISC_QUAD;

Then, write your function so that the result points to the threaded 

// This function adds a number of days to an existing date.

function DayAdd( var Days: Integer; IBDate PISC_QUAD) : PISC_QUAD; cdecl; export;

   tempquad.isc_quad_high := IBDate^.isc_quad_high + Days;
   tempquad.isc_quad_low  := IBDate^.isc_quad_low;
   Result := @tempquad;

Server Response from: ETNASC03