Rookie Academy:
[UDF Series 4]: Passing and returning data to a UDF written in Delphi
translated by warton
Author: chris levesque, tina grubbe, brett bandy
-------------------------------------------------- ----------------------------------
[Translator’s statement]:
I have translated several articles about writing UDF before. Although some friends may have gotten a little help from them, they may not be familiar with UDF.
There are still some problems in understanding. Today, I will translate two more articles, both of which are from mer system (http://www.mers.com)
Yes, interested friends can view the original text.
[argument]:
When the dynamic link library does not take special precautions for protected data values, our UDF has data results with parameter values or return values.
May be in a protected exception or error result.
[Solution]:
Each date value is stored in two 32-bit integer types: a signed integer representing the date, and a
An unsigned integer of time. Use delphi code to define this structure (isc_quad) and the pointer to the 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;
In order to protect the return value, declare a thread-safe isc_quad variable outside the function definition so that it holds the return value (if the return value
is a date type data).
threadvar
tempquad : isc_quad;
Then write your function so that the result points to the thread variable.
//define function
// 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;
The author comes from: mer systems inc.. http://www.mers.com