函数在数组和整数比较上返回 false?

Function returning false on array and integer compare?

我正在尝试检查数组中是否存在整数值,但即使数组中存在整数,函数也返回 false。

这是我正在使用的代码。错误是 404 但它返回 false:

const
  cErrors: array [0 .. 3] of integer = (401, 404, 409, 411);

function isInError(const error: integer; const sArray: array of integer): Boolean;
var
  i: integer;
begin
  Result := False;
  for i in sArray do
    if sArray[i] = error then
      Result := True;
  ShowMessage(error.ToString);// it's returining false always and this showmessage is just verify the error code
end;

我这样称呼它:

if (isInError(sPdf.LastErrorCode, cErrors)) then
  ShowMessage(sPdf.LastErrorCode.toString);

这看起来不对:

  for i in sArray do
    if sArray[i] = error then

for .. in 已经从数组中提取值。

  for i in sArray do
    if i = error then

同时打开范围检查以确保您不会超出数组边界。