Your translation of the keywords
parameter is incorrect. You've used a Delphi open array. A Delphi open array results in two things being passed, the index of the final item in the array, and the pointer to the first element of the array. Delphi open arrays are simply never to be used for interop.
You need to declare that parameter like so:
keywords: PPAnsiChar
That is a pointer to PAnsiChar
.
Call the function like this:
PyArg_ParseTupleAndKeywords(..., @kwlist[0], ...)
Personally I would use a dynamic array to prepare your parameter:
var
kwlist: TArray<PAnsiChar>;
Initialise it like this:
kwlist := TArray<PAnsiChar>.Create('AAA', 'BBB', nil);
And pass it like this:
PPAnsiChar(kwlist)
or like this if you prefer:
@kwlist[0]
The latter is typesafe at least.
I note that you declared AAA
and BBB
to be of type PChar
. Surely that should be PAnsiChar
.
I'm far from sure that you've prepared all the other parameters correctly. I'm not familiar with this particular API call. For sure though, what I describe above is the first and most important problem to tackle.
I do wonder how you the caller are expected to deallocate the strings that are returned to you? I presume that you are expected to do that.