微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

delphi – 为什么这个C到Pascal转换崩溃?

我有这个C代码

/*
  WARNING:  The order of this table must also match the order of a table
  located in AcquireResizefilter() in "resize.c" otherwise the users filter
  will not match the actual filter that is setup.
*/
typedef enum
{
  UndefinedFilter,PointFilter,BoxFilter,TriangleFilter,hermiteFilter,HannFilter,HammingFilter,BlackmanFilter,GaussianFilter,QuadraticFilter,CubicFilter,CatromFilter,MitchellFilter,JincFilter,SincFilter,SincFastFilter,KaiserFilter,WelchFilter,ParzenFilter,BohmanFilter,BartlettFilter,LagrangeFilter,lanczosFilter,lanczosSharpFilter,lanczos2Filter,lanczos2SharpFilter,RobidouxFilter,RobidouxSharpFilter,CosineFilter,SplineFilter,lanczosRadiusFilter,CubicSplineFilter,SentinelFilter  /* a count of all the filters,not a real filter */
} FilterType;

WandExport MagickBooleanType MagickResizeImage(MagickWand *wand,const size_t columns,const size_t rows,const FilterType filter)

我将它转换为Pascal,如下所示:

type
  FilterType =(
    UndefinedFilter,SentinelFilter);  // a count of all the filters,not a real filter

function MagickResizeImage(wand: PMagickWand; const columns: size_t; rows: size_t; const filter: FilterType): MagickBooleanType; cdecl; external MagickWandDLL;

当我调用MagickResizeImage()时,我收到了访问冲突:(

如果我改变const过滤器:FilterType到const过滤器:整数,它的工作原理.

知道我做错了什么吗?

解决方法

在Windows上的C中,枚举是一个int,因此大小为4个字节.在Delphi中,认情况下,它是一个单字节,如果有超过256个值,则为两个字节,依此类推.

您需要确保您的Delphi类型与C类型相同.例如,使用MINENUMSIZE指令.

{$mineNUMSIZE 4}

在定义枚举类型之前放置它.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐