瞧瞧delphi 的代码
比如format函数

解决方案 »

  1.   

    没那么复杂吧?在VB里用OPTION就搞定了。
      

  2.   

    Type OverClass=Class(TObject);
      function Test(a:integer):boolean;
      Function Test(a,b:integer):boolean;
    end;
     Function Test(a:integer):boolean;
     begin
       if a<>0 then Result:=true
        else Result:=false;
     end;
    Function Test(a,b:integer):boolean;
    begin
      if a<b then Result:=true
       else Result:=false;
    end;
    var
      k,j:boolean;
    begin
      K:=OverClass.Test(a);
      j:=OverClass.Test(a,b);
    end;
      

  3.   

    function Format(const Format: string; const Args: array of const): string;
    begin
      FmtStr(Result, Format, Args);
    end;procedure FmtStr(var Result: string; const Format: string;
      const Args: array of const);
    不明白怎么声明的const Args: array of const,请解释
      

  4.   

    procedure sample (p1:string); overload;
    procedure sample (p1,p2:string);overload;
    其他什么也不用管~~
    delphi调用时会自己识别参数!
      

  5.   

    谢谢 chons不羁之城的代码,可能我没有表达清楚我的意思。
    我想创建一个函数,可带有不确定个数的参数,而不是重载他。
      

  6.   

    谢谢lastlove(小豆芽),看来你也没明白我的意思
      

  7.   

    format就是用的数组啊,不是什么可变参数的
      

  8.   

    lastlove(小豆芽)
    那要在程序里分辨TSTRINGLIST里面的东西了,麻烦。
    我想的是函数可以识别,就象FORMAT那样的函数,他是这样声明的:
    procedure FmtStr(var Result: string; const Format: string;
    const Args: array of const);
    不明白怎么声明的const Args: array of const,请解释
      

  9.   

    如果你的函数没几个就用函数重载(overload)
    否则可用一个可变数组作为参数,不过你可以看看象format这样的函数的源代码
      

  10.   

    Procedure WriteCommData(const DataStr: array of char;len:integer; const Mode:integer = 0);............
    WriteCommData(tempstr,len);
    .........
    WriteCommData(tempstr,len,1);
    是这个意思吗?
      

  11.   

    type
    Args=array of const;
    ……
    var arg:args;
    New(arg,10);
    ……
    (释放内存我忘记用什么函数了,查查吧,好象是Free())关于自定义类型变量,请参考《Delphi 5 开发人员指南》。