Firebird UDF or UDR

Hi

I am trying to write a Delphi Firebird 3 UDF.

I have put some calls to Windows.OutputDebugStringW into my exported routines but no messages are being shown using dbgview.

My test stored procedure is

CREATE PROCEDURE TEST_TABLECODE_UDF
RETURNS (
    XMESSAGE varchar(100),
    XNAME varchar(40),
    XVALUE integer,
    XRESULT integer )

AS
  BEGIN
   xName = 'Configuration';
   xResult = TableCode_Value(xMessage
                             ,xName
                             ,xValue
                             );
   SUSPEND;
   xName = 'xxxration';
   xResult = TableCode_Value(xMessage
                             ,xName
                             ,xValue
                             );
   SUSPEND;
   xValue = 95;
   xResult = TableCode_Name(xMessage
                            ,xValue
                            ,xName
                            );
   SUSPEND;
   xValue = -2;
   xResult = TableCode_Name(xMessage
                            ,xValue
                            ,xName
                            );
   SUSPEND;
   xValue = 9999;
   xResult = TableCode_Name(xMessage
                            ,xValue
                            ,xName
                            );
   SUSPEND;  
   END

and I get 5 records back when I run a select on TEST_TABLECODE_UDF.

Is there anyone out there who could help me and/or provide a working set of code (both Firebird and Delphi) that works.

My Firebird definition of my UDF is

DECLARE EXTERNAL FUNCTION TABLECODE_NAME
cstring(100), integer, cstring(40)
RETURNS integer
ENTRY_POINT 'TABLECODE_VALUE2NAME'
MODULE_NAME 'CollexUDF';

My routine takes in an integer and returns a VARCHAR field into the cstring(40) input field. If there are any errors a message is return into the cstring(100) field and the result returned is 0, otherwise the function returns a 1.

I wanted to return a boolean instead of an integer but got runtime errors.

I know UDF are on the way out and UDR’s should be used but I though UDFs would be easier to start with.

I would also appreciate some assistance with writing Delphi UDRs if some could help.

Thanks in advance
Graeme Keast

1 Like

FYI @Graeme I edited the post to put the code in code blocks to make it more readable.

Thanks Vincent.

Must remember the 3 ticks.

Don’t know if this is useful Graeme but might be worth a look :slightly_smiling_face: