Subject Re: UUID (octets) to something readable
Author woodsmailbox
> Is there some tutorial or guide do develop a multiplataform UDF
using
> pascal?
>

here's my mostly empirical findings and assumptions. btw please
correct what's wrong (again, only tested with fpc on linux).

#
#
# General tips:
# - by default, all input and output parameters are pointers, so `by
reference' is the implicit calling method.
# - if you never return null, use the `by value' calling method to
avoid having to malloc the result.
# - when returning `by reference', malloc() the result yourself, and
declare the udf with the `free_it' directive. for this to work
# you have to use either clib's malloc() (on linux), msvcrt's malloc()
(on windows) or ib_util's ib_util_malloc() (cross-platform -- just a
wrapper o'doze).
# - in case your udf takes cstring(N) as the <n>'th parameter and
returns cstring(at most N) of the same charset as that parameter,
# use `returns parameter <n>' instead, and just write on it's buffer
instead of malloc'ing another block.
# Null handling:
# - firebird 2.0+ will pass nulls as null pointers but only for
parameters declared as `by reference null'.
# otherwise you'll get a 0 (zero) for an integer or double parameter,
and an empty string for a string parameter.
# - null parameters can also be detected with the `by descriptor'
calling method.
# - returning a nil pointer is interpreted as null (note that you
can't say `returning ... by reference null'; tested in 2.1.1).
# Type mapping (firebird-freepascal):
# INTEGER BY REFERENCE - var Longint or PLongint if you want to
catch/return nulls
# INTEGER BY VALUE - Longint
# DOUBLE PRECISION BY REFERENCE - var Double or PDouble if you
want to catch/return nulls
# DOUBLE PRECISION BY VALUE - Double
# CSTRING(N) BY REFERENCE - PChar
# CSTRING(N) BY VALUE - doesn't make sense
# <anything> BY DESCRIPTOR - PParamDsc
# Charsets:
# - firebird gives/expects text parameters in the charsets the udf was
declared with.
# - gotcha: you won't be able to catch/return strings containing
ascii_char(0) characters except with the `by descriptor'
# with `varchar by reference' (instead of cstring), you get the length
at PLongint(param)^ and the contents at @param[2].
# Using descriptors:
# - declaring parameters as `<datatype> by descriptor' won't guarantee
you that the engine will give you the values in that datatype!
# instead you gotta check dsc_dtype yourself and interpret the value
accordingly. the advantage is you can write polymorphic functions.
#