zoukankan      html  css  js  c++  java
  • 类型变化的开放数组参数

    View Code
    procedure ShowMsg(const fmtStr:string; const params: array of const);
    begin
    ShowMessageFmt(fmtStr,params);
    end;

    function SumAll(const Args: array of const): Extended;
    var
    I: Integer;
    begin
    Result := 0;
    for I := Low(Args) to High(Args) do
    case Args[I].VType of
    vtInteger: Result :=
    Result + Args[I].VInteger;
    vtBoolean:
    if Args[I].VBoolean then
    Result := Result + 1;
    vtChar:
    Result := Result + Ord(Args[I].VChar);
    vtExtended:
    Result := Result + Args[I].VExtended^;
    vtString, vtAnsiString:
    Result := Result + StrToIntDef((Args[I].VString^), 0);
    vtWideChar:
    Result := Result + Ord(Args[I].VWideChar);
    vtCurrency:
    Result := Result + Args[I].VCurrency^;
    end;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    i: Integer;
    d: Double;
    e: Extended;
    begin
    i := 99;
    d := 10.8;
    e := SumAll([1,2,3,4,5]);
    ShowMessageFmt('%f',[e]);

    e := SumAll([i,2.5,3,d,5]);
    ShowMessageFmt('%f',[e]);

    ShowMsg('Integer:%d, Double:%f',[i,d]);
    end;
  • 相关阅读:
    struts2笔记之if控制标签
    struts2标签之iterator遍历集合
    struts2获得session和request
    数据库操作语句
    weixinapp api
    struts2笔记之tree标签输出树
    struts2笔记之整合Tiles
    C++中的符号
    JSP布局相关使用
    5.Github仓库
  • 原文地址:https://www.cnblogs.com/Jekhn/p/2324890.html
Copyright © 2011-2022 走看看