一个函数能够输入一个变量,而输出两个变量吗?

解决方案 »

  1.   

    输入一个变量,输出两个变量,就只能将输入变量定义前面加var当成一个输出的变量
      

  2.   

    例子:
    procedure dosth(const a:string;var{var指传址调用,可以实现给函数传入变量地址,改变相应地址的值,相当于传出结果} b : string;var c : string);
    begin
      b := a;
      c := a;
    end;
      

  3.   

    理想化的想返回两个值,当然是不可能。
    但是有其他很多方法达到同样的效果。
    比如:
    1.定义一个有两个数据域的记录类型。返回值类型为此记录类型。
    type  TR=record
            v1:Integer;
            v2:Integer;
          end;
    function FuncName(...):TR;2.通过定义参数为变参。可作为返回值用。function FuncName(var v1:Integer;var v2:Integer):...;
      

  4.   

    能给出function的具体例子和调用例子吗?
      

  5.   

    用保留字OUT也可以实现吧
    Function temp(out a:integer;out b integer;c:string);
    a 和b 就是要返回的数,在函数中赋值,c为输入的参数
      

  6.   

    定义一个结构体,用于返回数据
    例如:
      TPara = record
        ID:Integer;
        FName:String;
      end;function GetPara(InParam:Integer):TPara;
    begin
      Result.ID := 1;
      Result.FName := 'aaa';
    end;
      

  7.   

    那么在button1中怎样调用这个函数啊?
      

  8.   

    TPara = record
        ID:Integer;
        FName:String;
      end;function GetPara(InParam:Integer):TPara;
    begin
      Result.ID := 1;
      Result.FName := 'aaa';
    end;procedure tform1.button1click(sender:tobject);
    begin
      GetPara(1);
     showmessage(inttostr(GetPara.ID));
     showmessage(GetPara.FName);
    end;