Subject | Re: [firebird-support] Need help writing a UDF... |
---|---|
Author | Ivan Prenosil |
Post date | 2005-05-23T11:41:25Z |
RETURNS DOUBLE PRECISION BY VALUE
Ivan
Ivan
> since a few days I try to get a UDF up and running on my computer. I tried
> to write it in Delphi.
> The sample Modulo UDF is working fine on my computer. But now I need a UDF
> returning a simple calculation. Each time I call the external function in a
> select, the server crashes.
> Can anybody tell me what I'm doing wrong? I tried as data types in the
> declare external function syntax "float" and "double precision"
>
> DECLARE EXTERNAL FUNCTION DISTANCE
> DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION
> RETURNS DOUBLE PRECISION
> ENTRY_POINT 'Distance' MODULE_NAME 'DistanceUDF';
>
> And my unit in the DLL-project looks as follows:
>
> unit Unit1;
>
> interface
>
> function Distance(var lon1, lon2, lat1, lat2: real): real; cdecl; export;
>
> implementation
> uses MATH;
>
> function Distance(var lon1, lon2, lat1, lat2: real): real;
> begin
> result := 6740 * arccos(( SIN(lat1/57.29577951) * SIN(lat2/57.29577951) )
> + (COS(lat1/57.29577951) * COS(lat2/57.29577951) *
> COS((lon1/57.29577951)-(lon2/57.29577951))) );
> end;
>
> end.