重建丢失的代码(InArray) - cont [英] reconstructing lost code (InArray) - cont

查看:612
本文介绍了重建丢失的代码(InArray) - cont的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一位开发人员的代码中缺少一个单元。



我已经能够破译一些,这里的专家帮助我与他人, / p>

我需要一个名为InArray的布尔函数。



我知道它需要一个TIntArray和整数,并返回一个布尔值无论整数是否存在于TIntArray中

  TIntArray = Integer数组; 


函数InArray(A:TIntArray; n:整数):Boolean;
begin
// result:=
end;

我不知道剩下的如何完成。



任何帮助将不胜感激。



thanx

解决方案

最有可能的是,函数测试如果 n 属于数组:

  function InArray(A:TIntArray; n:Integer):boolean; 
var
i:integer;
begin
result:= false;
for i:= low(A)to high(A)do
if A [i] = n then
Exit(true);
结束

如果您使用旧版本的Delphi(< 2009),则必须执行



 函数InArray(A:TIntArray; n:Integer):boolean; 
var
i:integer;
begin
result:= false;
for i:= low(A)to high(A)do
如果A [i] = n then
begin
result:= true;
break;
结束
结束


I am missing a unit from some code that another developer worked on.

I have been able to decipher some, and experts here have helped me with others,

I need a boolean function called InArray.

I know it takes a TIntArray and integer and returns a boolean of whether or not the integer exists in the TIntArray

TIntArray = array of Integer;


function InArray (A: TIntArray; n: Integer): Boolean;
begin
 // result:=
end;

I am not sure how the rest of it is completed.

any help would be appreciated.

thanx

解决方案

Most likely, the function tests if n belongs to the array:

function InArray(A: TIntArray; n: Integer): boolean;
var
  i: integer;
begin
  result := false;
  for i := low(A) to high(A) do
    if A[i] = n then
      Exit(true);
end;

If you are using an old version of Delphi (<2009), you have to do

function InArray(A: TIntArray; n: Integer): boolean;
var
  i: integer;
begin
  result := false;
  for i := low(A) to high(A) do
    if A[i] = n then
    begin
      result := true;
      break;
    end;
end;

instead.

这篇关于重建丢失的代码(InArray) - cont的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆