Problem: 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. Solution: 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): type {InterBase Date/Time Record} ISC_QUAD = record isc_quad_high : Integer ; // Date isc_quad_low : Cardinal ; // Time end; PISC_QUAD = ^ISC_QUAD; 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). threadvar tempquad : ISC_QUAD; Then, write your function so that the result points to the threaded variable. // This function adds a number of days to an existing date. function DayAdd( var Days: Integer; IBDate PISC_QUAD) : PISC_QUAD; cdecl; export; begin tempquad.isc_quad_high := IBDate^.isc_quad_high + Days; tempquad.isc_quad_low := IBDate^.isc_quad_low; Result := @tempquad; end;
Last Modified: 27-SEP-00