Subject writing udf for Windows
Author unclejung
I writing udf in Delphi 6 that take a varchar as input and returns
a varchar. My concern is memory leak. After reading the "Building
UDF Libraries" article by Gregory H. Deatz and updated by Craig
Stuntz, I chose to have Interbase allocate the memory for the
returning varchar as follow:

DECLARE EXTERNAL FUNCTION myudf
CSTRING(1024), CSTRING(1024)
RETURNS parameter 2
ENTRY_POINT 'udf_myudf' MODULE_NAME 'myudflib'

My problem: it doesn't work - the function returns nothing. But if I
change it to:

DECLARE EXTERNAL FUNCTION myudf
CSTRING(1024), CSTRING(1024)
RETURNS CSTRING(1024)
ENTRY_POINT 'udf_myudf' MODULE_NAME 'myudflib'

then the function would return what I expect.

The Delphi funtion is as followed:

function udf_myudf (szSource: PChar; var szResult : PChar) : PChar;
cdecl;
var
SL : TStringList;
begin
Result := szResult;

//preparing the returning string
SL := TStringList.Create;
SL.Sorted := TRUE;
SL.CommaText := szSource;

//assigning the returning string
Result := PChar (SL.CommaText);

//freeing temporary memory
SL.Free;
end;

Any idea?

Thanks

Jung