简体   繁体   English

如何将char **转换为delphi?

[英]how to convert char ** to delphi?

I think char ** mean ppansiChar but i don't know how to use it after and the purpose. 我认为char **意思是ppansiChar但我不知道以后如何使用它以及目的。 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 它是可行的,但是我不知道现在如何将结果作为ppansiChar :(为什么不简单地使用pansiChar?所以将我用作ppansichar可能不对吗?通常MagickGetImageProfiles必须返回一个数组或类似的东西,因为在number_profiles中它是返回返回的配置文件数

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: 您可以同样设置{$POINTERMATH ON}并这样写:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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