UDF's Written in Delphi and Interbase
I have tried to create a UDF for an Interbase DB with Delphi. The udf is a
function that calculates the distance between a pair of Latitudes and
Longitudes. The inputs are all Double and the return value is a double. I
wrote a test application in Delphi that tests the .dll and it works
perfectly.
Then, I set up the declaration in Interbase after copying the .dll to the
same directory as the ib_udf.dll (which contains the trig functions used in
my .dll and that have already been declared in the Interbase DB. No matter
what I specify as the return type I get nonsensical data, sometimes the same
values no matter what the input values. My guess is that there is some kind
of conversion problem happening between Delphi data types and Interbase
data. My function has no 'includes' since there are no string variables:
Here is the function code in Delphi:
library IB_MAMSudf;
uses
SysUtils,
Classes;
{$R *.RES}
function GetDistance(ClientLatitude, ClientLongitude, ClinicLatitude,
ClinicLongitude: Double): Double; StdCall;
begin
If ((ClientLatitude <> ClinicLatitude) And (ClientLongitude <>
ClinicLongitude)) Then
Result := 3959 * (Arctan(-(Sin(ClientLatitude / 57.3) *
Sin(ClinicLatitude / 57.3) +
Cos(ClientLatitude / 57.3) * Cos(ClinicLatitude / 57.3) *
Cos(ClinicLongitude / 57.3 -
ClientLongitude / 57.3)) / (Sqrt(-(Sin(ClientLatitude / 57.3) *
Sin(ClinicLatitude / 57.3)
+ Cos(ClientLatitude / 57.3) * Cos(ClinicLatitude / 57.3) *
Cos(ClinicLongitude / 57.3 -
ClientLongitude / 57.3)) * (Sin(ClientLatitude / 57.3) *
Sin(ClinicLatitude / 57.3) +
Cos(ClientLatitude / 57.3) * Cos(ClinicLatitude / 57.3) *
Cos(ClinicLongitude / 57.3 -
ClientLongitude / 57.3)) + 1))) + 2 * Arctan(1))
Else
Result := 30;
end;
exports
GetDistance;
end.
Hers is my Declaration:
DECLARE EXTERNAL FUNCTION GETDISTANCE
DOUBLE PRECISION,DOUBLE PRECISION,DOUBLE PRECISION,DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'GetDistance'
MODULE_NAME 'IB_MAMSudf.dll'
Any help would be greatly appreciated as I can not find any examples of how
to create a udf in Delphi. All the examples in the Interbase docs are for C
and I don't know C.
Thanks in advance
John Griffith jo...@barjohn.com