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

TLama tlama at inbox.com
Thu Jul 23 14:25:09 PDT 2015


Thank you very much for the modification you made in one of the last
commits. It resolves my issue, however, I was hoping for an advice,
not a direct modification of the API, but I'm really impressed from
your effort!

For the API itself might be good to consider returning an ordinal error
code except the hardcoded message text.

This would allow users to "switch" in their error (or notice) handlers
and act accordingly to certain situations. Let's take for example the
GEOSGeomGetX_r function. Now you can recognize what error caused the
function to fail only by its text. Because how else you would find out
it failed due to "Argument is not a Point".

If there were passed also error codes like e.g.

#define ERROR_UNKNOWN_EXCEPTION 666
#define ERROR_STANDARD_EXCEPTION 667
#define ERROR_ARGUMENT_NOT_POINT 668

you would at least reliably recognize that the input was wrong. But it's
just my two cents into the error handling. I saw that Mateusz dropped a
few comments about replacing repetitive code blocks by macros, so that
might be the time to think about error handing improvements.

I think that ideal might be if all the functions were returning a "bool"
value indicating if they failed, remembering their last error code and a
message (for general and unknown exceptions). The users could then query
the last error and message (just like e.g. Windows API does), so there
were no error and notice callbacks.

But that would completely broke the existing API, so it's just my secret
wish (which I can still realize with the current API).

Thank you for your support and this library!
TLama

> -----Original Message-----
> From: tlama at inbox.com
> Sent: Thu, 9 Jul 2015 08:05:35 -0800
> To: geos-devel at lists.osgeo.org
> Subject: [geos-devel] How to modify the C API for use in Delphi?
> 
> 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
> TLama
> 
> (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
> 
> 
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth




More information about the geos-devel mailing list