zoukankan      html  css  js  c++  java
  • 关于开放数组的小练习


    {整数求和函数,使用指定类型的开放数组}
    function Fun1(arr: array of Integer): Integer;
    var
      n: Integer;
    begin
      Result := 0;
      for n in arr do Inc(Result, n);
    end;
    
    {整数、浮点数或布尔值的求和函数,使用无类型的开放数组}
    function Fun2(arr: array of const): Double;
    var
      i: Integer;
    begin
      Result := 0;
      for i := Low(arr) to High(arr) do
      begin
        case arr[i].VType of
          vtInteger: Result := Result + arr[i].VInteger;
          vtExtended: Result := Result + arr[i].VExtended^;
          vtBoolean: Result := Result + Integer(arr[i].VBoolean);
        end;
      end;
    end;
    
    {测试}
    procedure TForm1.FormCreate(Sender: TObject);
    var
      n1,n2: Integer;
      f1,f2: Double;
    begin
      n1 := Fun1([1, 2, 3]);                   //6
      n2 := Fun1([1, 2, 3, 4, 5, 6, 7, 8, 9]); //45
    
      f1 := Fun2([1, 2, 3]);                   //6.00
      f2 := Fun2([True, 1.1, 2.2, 3.3]);       //7.60
    
      ShowMessageFmt('%d, %d, %f, %f', [n1, n2, f1, f2]);
    end;
    

  • 相关阅读:
    emacs jedi
    opencv 基本demo
    emacs列编辑
    observable operator example
    angular keydown 例子
    回调和匿名函数
    gin cors
    angular rxjs
    python dbus note
    视频截图
  • 原文地址:https://www.cnblogs.com/del/p/2015748.html
Copyright © 2011-2022 走看看