I am writing a windows application in Lazarus/FreePascal (like Delphi). I have a TDataset object that is populated by 5000 rows, 2 columns of numerical values.
I need to pass this data to a C
function that I am importing statically from a .dll library.
Here is an excerpt from the library's manual that explains what format its parameters should be in:
flan_index_t flann_build_index(float* dataset,
int rows,
int cols,
float* speedup,
struct FLANNParameters* flann_params);
This function builds an index and return a reference to it. The arguments expected by this function are as follows: dataset, rows and cols - are used to specify the input dataset of points: dataset is a pointer to a rows cols matrix stored in row-major order (one feature on each row)
Can I simply pass the TDataSet object? Do I have to do something to it first so that the pointer is in the right form?
Obviously you can't pass the
TDataSet
object. It is a FreePascal object, and the function seems to expect a pointer to afloat
(which is probably a pointer to aSingle
in FreePascal). It probably expects a two-dimensional array offloat
's. You have to pass another pointer tofloat
and a pointer to aFLANNParameters
structure as well.Move()
won't work either. ATDataSet
is not an array.I guess you'll have to declare an array like Uwe said, populate it using your dataset and pass the array:
Shameless plug
Please read my Pitfalls of Conversion article about converting function declarations from C to Delphi (and probably FreePascal on Win32). Now I'm at it, you may want to read my article Addressing Pointers too.