举例:tpye
myfunc1=function(a:integer):integer;////
myfunc=function(a:XXXX):integer; ///这里的XXXX不知该填什么好,请指点var
func1:myfunc1;
func:myfunc;
 implementationfunction func1(a:integer):integer;
begin
result:=a+a;
end;
如果像函数1那样定义话,那么我在实现部分定了了函数后就可以通过 func(100)等调用函数1,但是如果我想让我的函数通过我自己来决定函数的参数类型的话要怎样做??
也就是说当我  调用Func时,如果格式是:func(100),那么我得函数就调用参数未整形的版本
如果调用为func(1.2),那么函数就调用另外一个版本实现
function func(a:real):real;
begin
result:=a+a;
end;这样该函数要如何去做??
我得问题也就是说,怎样再定义一个函数时先不指定它函数参数的类型,然后通过我在调用时指定参数的类型,请大家指点一下啊!麻烦了

解决方案 »

  1.   

    这个不难呀,在DELPHI中有这样一个类型叫什么这想不起来的,你看看,他是自动识别类型。你找找吧,
      

  2.   

    定义一个采用Variant类型作为参数的函数即可,可以在函数中判断真正的数据类型是什么,不过,这样的执行效率会有些降低。function aFunc(aParam:Variant):string;
    begin
    case VarType(aParam) of
      varInteger:result:='整型';
      varString:result:='字符串';
      varDate:result:='日期';
      varBoolean:result:='布尔型';
      //等等,请参阅 VarType 函数的用法!
    end;
    end;
      

  3.   

    你可以用variant,不过建议你用重载。因为对应不同参数类型你可能对应不同处理方法,用重载符合OOP编程的规范,而且以后如果要添加不同类型直接添加对应方法就可以了,如果用variant没有这么灵活。function(AValue: integer): integer;
    function(AVAlue: string): integer;var
      result1, result2: integer;
    begin
      result1 := function(5);
      result2 := function('5');
    end;
      

  4.   

    我曾经见过一个函数的变量参数类型是  Untype 类型,如:
    它的声明如下
    function a(var aa);integer;假如我想把aa赋值给另外一个变量,那么这个变量该声明为什么类型呢??
    如果声明为
    variant
    byte
    integer
    ......声明为以上任何一种都会出现类型不匹配。
    var
    aaa:variant;
    aaaa:byte;aaa:=aa;
    aaaa:=aa;  (不管怎样还是无法赋值)
    有什么其他办法吗?请指教~
      

  5.   

    用可变类型VARIANT是一个好主意。
      

  6.   

    user Variant or OleVariantdifference:The OleVariant type exists on both the Windows and Linux platforms. The main difference between Variant and OleVariant is that Variant can contain data types that only the current application knows what to do with. OleVariant can only contain the data types defined as compatible with OLE Automation which means that the data types that can be passed between programs or across the network without worrying about whether the other end will know how to handle the data.else to  dyf2001(西风) ,Thank you for that good way to me...