有几个函数定义在本程序的其它unit上了,我可不可以直接调用,我怎么调用才不会出错?

解决方案 »

  1.   

    举个例子:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;     //这里引用 Unit2{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      form2.asdf;                 //这里调用 Unit2的函数
    end;end.
    ==================================================================
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
        procedure asdf;     //在这里声明
      end;var
      Form2: TForm2;implementation{$R *.dfm}procedure TForm2.asdf;      //实现部分
    begin
      showMessage('http://www.goomoo.net');
    end;end.
      

  2.   

    在implementation下使用uses unitname 进行声明
    然后调用就可以了
    for example;
    uses unitname
    procedure TfrmBillManage.ToolButton3Click(Sender: TObject);
    begin
      unitname.FunctionNameOrProcedureName;
    end;
      

  3.   

    在implementation下使用uses unitname 进行声明
    然后调用就可以了
    for example;
    uses unitname
    procedure TfrmBillManage.ToolButton3Click(Sender: TObject);
    begin
      unitname.FunctionNameOrProcedureName;
    end;
      

  4.   

    在implementation下使用uses unitname 进行声明
    然后调用就可以了
    for example;
    uses unitname
    procedure TfrmBillManage.ToolButton3Click(Sender: TObject);
    begin
      unitname.FunctionNameOrProcedureName;
    end;
      

  5.   

    //对手机号码进行移位
    function goalnumber(var s:String):String;
    var
       i,lengthofnumber:integer;   goalstr:string;
    begin
        lengthofnumber:=length(s);
        if lengthofnumber mod 2=0 then
          begin
           i:=1;
           goalstr:='';
           while i<lengthofnumber do
             begin
             goalstr:=goalstr+s[i+1];
             goalstr:=goalstr+s[i];
             i:=i+2;
             end;
           end
          else
          begin
             i:=1;
             goalstr:='';
             while i<lengthofnumber-1 do
               begin
              goalstr:=goalstr+s[i+1];
              goalstr:=goalstr+s[i];
             i:=i+2;
             end;
             goalstr:=goalstr+'F';
             goalstr:=goalstr+s[i];
          end; Result:=goalstr;
    end ;
    如上所示,我的函数是这样定义的:
    function goalnumber(var s:String):String;
    而不是function TForm2.goalnumber(var s:String):String;所以我用users unit2声明后仍然出错不能调用。
      

  6.   

    将unit2加入到unit1的uses部分就行了。
      

  7.   

    你把它 uses 一下不就可以吗?
      

  8.   

    uses unit_name就可以啦.简单