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

我正在尝试检查数组中是否存在整数值,但是即使该数组中存在整数,该函数也会返回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);
daneee 回答:函数在数组和整数比较上返回false?

这看起来是错误的:

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

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

  for i in sArray do
    if i = error then

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

本文链接:https://www.f2er.com/3084862.html

大家都在问