前面我已經(jīng)翻譯了幾篇關(guān)于編寫udf的文章,雖然一些朋友可能也從中得到了一點(diǎn)幫助,但是可能對(duì)udf的 認(rèn)識(shí)還存在一些問(wèn)題。今天,我再翻譯兩文章,這兩篇文章都是來(lái)自mer system (http://www.mers.com) 的,有興趣的朋友可以查看原文。
[解決方案]: 每一個(gè)日期值被保存在兩個(gè)32位的整數(shù)類型之中:一個(gè)表示日期的signed integer,和一個(gè)表示 時(shí)間的unsigned integer。使用delphi代碼來(lái)定義這個(gè)結(jié)構(gòu)(isc_quad)和結(jié)構(gòu)的指針(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; 為了保護(hù)返回值,在函數(shù)定義的外部申明一個(gè)線程安全的isc_quad變量,使它保存返回值(如果返回值 是一個(gè)日期型的數(shù)據(jù))。 threadvar tempquad : isc_quad; 然后編寫你的函數(shù)以便結(jié)果指向線程變量。
// 定義函數(shù) // 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;