简体   繁体   中英

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 im 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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM