zoukankan      html  css  js  c++  java
  • delphi 开放数组参数

    在函数中如果数组的个数不定,可以使用开放数组参数
    
    实参可以接受静态数组和动态数组
    
    procedure p1(a:array of Byte);
    begin
    
    ShowMessage( IntToHex( Integer(@a),2));
    ShowMessage(IntToStr(a[0]));
    end;
    
    procedure TForm1.btn1Click(Sender: TObject);
    var
    a:array[0..5] of Byte;
    begin
    ShowMessage(IntToHex( Integer(@a),2));
    p1(a);
    end;
    
    procedure TForm1.btn2Click(Sender: TObject);
    var
    a:array of Byte;
    
    begin
    SetLength(a,10);
    a[0]:=10;
    ShowMessage(IntToHex( Integer(@a),2));
    p1(a);
    end;
    
    经常使用的
    
    array of const 类型的数组就能实现把不同类型、不同个数元素组成的数组一下子传递给例程。如下面Format 函数的定义:
    
    function Format (const Format: string;
    
    const Args: array of const): string;
    
    
  • 相关阅读:
    3.22
    练习 3.16
    简单工厂模式
    Java-不可变字符串
    java中的缓冲流
    TCP协议下java通信
    nginx优化
    nginx反向代理
    shell-for循环
    shell-数组
  • 原文地址:https://www.cnblogs.com/beeone/p/1812371.html
Copyright © 2011-2022 走看看