Subject Using UDF: "Connection Lost to Database"
Author Raymond Kennington
Using a UDF causes the error message: "Connection Lost to Database" to appear.

All the relevant code is below. What is causing this?

Is all memory correctly allocated and destroyed by the following?

How to make the following thread-safe?

Any other suggestions to improve the following?

TIA.

Raymond.
--------

library Algorithms;

uses
SysUtils,
Classes,
ConfNum in 'ConfNum.pas';

{$R *.res}

exports
CalcCheckDigit;

begin
end.

unit ConfNum;

interface

function CalcCheckDigit(var TheConfNum : PChar; ResultBuffer : PChar) : PChar; cdecl;
export;

implementation

uses
SysUtils;

function CalcCheckDigit(var TheConfNum : PChar; ResultBuffer : PChar) : PChar; cdecl;
export;
var
c : array[0..1] of Char;

i : Integer;
begin
Result := ResultBuffer;

c[0] := 'A';
c[1] := #0;

StrCopy(Result, c);
end;

initialization
IsMultiThread := True;

end.

DECLARE EXTERNAL FUNCTION CalcCheckDigit
CSTRING(11) CHARACTER SET NONE,
CSTRING(2) CHARACTER SET NONE
RETURNS PARAMETER 2
ENTRY_POINT 'CalcCheckDigit' MODULE_NAME 'Algorithms';

SELECT CalcCheckDigit('0000111111') FROM RDB$DATABASE;

--
Raymond Kennington
Programming Solutions
W2W Team B