gpt4 book ai didi

delphi - 为什么 C 到 Pascal 的转换会崩溃?

转载 作者:行者123 更新时间:2023-12-03 15:19:53 26 4
gpt4 key购买 nike

我有这个 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)

我将其转换为帕斯卡,如下所示:

type
FilterType =(
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

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

当我调用 MagickResizeImage() 时,出现访问冲突:(

如果我将 const filter: FilterType 更改为 const filter: integer,它就可以工作。

知道我做错了什么吗?

最佳答案

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

您需要确保您的 Delphi 类型与 C 类型大小相同。例如使用MINENUMSIZE指示。

{$MINENUMSIZE 4}

将其放在定义枚举类型之前。

关于delphi - 为什么 C 到 Pascal 的转换会崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48953749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com