zeus
zeus

Reputation: 13345

how to convert char ** to delphi?

I think char ** mean ppansiChar but i don't know how to use it after and the purpose. I have this function

char **MagickGetImageProfiles(MagickWand *,const char *,size_t *), 

that i translate like this :

function MagickGetImageProfiles(wand: PMagickWand; const pattern: pAnsiChar; const number_profiles: pSize_t): ppAnsiChar;

it's work, however i don't know what to do now with the result as ppansiChar :( why not simple pansiChar ? so maybe i m wrong to use it as ppansichar ? normally MagickGetImageProfiles must return you an array or somethink like this because in number_profiles it's return the number of profiles returned

Upvotes: 0

Views: 538

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

It's a pointer to an array of strings. Personally I'd declare the function like this:

function MagickGetImageProfiles(
    wand: PMagickWand; 
    pattern: pAnsiChar; 
    out number_profiles: size_t
): ppAnsiChar; cdecl;

Call it like this:

var
  i: Integer;
  number_profiles: size_t;
  profiles, p: ppAnsiChar;
... 
profiles := MagickGetImageProfiles(wand, pattern, number_profiles);
// error checking goes here, as described by API documentation 
p := profiles;
for i := 0 to number_profiles-1 do begin
  Writeln(p^);
  Inc(p);
end;
MagickRelinquishMemory(profiles);

You could equally set {$POINTERMATH ON} and write it like this:

var
  i: Integer;
  number_profiles: size_t;
  profiles: ppAnsiChar;
... 
profiles := MagickGetImageProfiles(wand, pattern, number_profiles);
// error checking goes here, as described by API documentation 
p := profiles;
for i := 0 to number_profiles-1 do
  Writeln(profiles[i]);
MagickRelinquishMemory(profiles);

Upvotes: 4

Related Questions