[fpc-pascal] Get value of PPChar ?

Sven Barth pascaldragon at googlemail.com
Sun Apr 16 18:37:22 CEST 2017


On 16.04.2017 16:58, fredvs wrote:
> Hello.
> 
> A C method is defined like this:
> 
> MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta);
> 
> and translated in Pascal with this:
> 
> function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PPChar): integer;
> cdecl;

This is wrong. "var" essentially results in a "char***".

What you want is either

function mpg123_icy(mh: Tmpg123_handle; icy_meta: PPChar): integer; cdecl;

or

function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PChar): Integer;
cdecl;

And how you'll need to use it will depend upon the function's
documentation: if the function will allocate the buffer then you simply
need to pass in a PChar variable (second case) or a pointer to one
(first case). If you need to allocate the buffer yourself then you first
need to do a GetMem with an appropriate size before you do the same.

Regards,
Sven



More information about the fpc-pascal mailing list