HELP: how to use delphi to write interbase User Defined Functions

Can anyone tell me how I can write Interbase User Defined Functions using
delphi? In the help-files only C is used unfortunately... I have written a DLL
with some functions but when i use these from wisql I get errors like

conversion error from string "BLOB"

or weird exception messages... I'm not sure wether to declare my functions
cdecl, stdcall or pascal. Also according to the help-files I need to return
values by reference. I can just return the addr of a local variable but this
sometimes causes problems because I guess interbase tries to release the
memory; I can allocate memory myself but I'm afraid because of delphi's
heap-manager I'll end up with a lot more memory than I need, which interbase
will not all free, causing memory-leakage...

Does anybody out there have any experience in this matter?

Any help would be greatly appreciated...