[geos-devel] How to modify the C API for use in Delphi?

TLama tlama at inbox.com
Thu Jul 9 09:05:35 PDT 2015

Hi everyone,

I'm a long time Delphi developer and I've just ported a few functions from the Geos C API
and I must say that I'm impressed from this library. So far I've been playing with the library
basic features. Now to the problem I've hit now. The message callback prototype...

We cannot implement GEOSMessageHandler callback in Delphi due to its variadic parameter
(the workarounds mentioned here http://stackoverflow.com/a/15051364/960757 are no good
for me).

I see that the API is now in some stable state so I'm ready to modify it for my own purpose
(though I would be very grateful for some conditional change from your side). I can receive
only the optional arguments e.g. as an array of strings in Delphi.

Since there is at most 1 optional argument passed to the variadic parameter, I was thinking
about a simple prototype with two string parameters, but that would mean to modify quite a
big part of the geos_ts_c.cpp file, and that's what I would like to avoid. Besides that, I don't
know if you'll use more than one optional argument in the future, so this is not the way to go.

My question is, what would be the simplest way to modify the C API so that the callback
GEOSMessageHandler prototype would not use variadic parameter (...) but instead pass
the optional arguments as an array of string? I'm hoping in some "magical" template that
will do the change in one place (sorry, I'm quite a C language noob).

Is there a way to easily "turn" the GEOSMessageHandler prototype to be something like:

typedef void (*GEOSMessageHandler)(const char *fmt, int argc, const char **args);

Such callback I would be able to implement in Delphi, the one with the variadic parameter
I cannot. And it seems to be the only thing that prevents me from using this library in Delphi
(yes, I know, it's an ancient language :)

Could you help me with this problem?

Thank you

(sorry, this is a repost in plain text because the HTML one is broken)

Publish your photos in seconds for FREE
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4

More information about the geos-devel mailing list