我想把所有的自定义函数放在一个单元文件中然后在别的单元中 uses  自定义函数单元;直接使用自定义函数;例:
————————————————————————
unit Unit2;interfaceimplementationfunction  max(x,y:integer):integer;
var
  tmp:integer;
begin
  tmp:=x;
  if y> x then tmp:=y;
  Result:=tmp;
end;
end.————————————————————
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
uses
  Unit2;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption:=IntToStr(max(12,16));
end;end.但总是:
[Error] Unit1.pas(30): Undeclared identifier: 'max'

解决方案 »

  1.   

    unit Unit2;interface
    function  max(x,y:integer):integer;implementationfunction  max(x,y:integer):integer;
    var
      tmp:integer;
    begin
      tmp:=x;
      if y> x then tmp:=y;
      Result:=tmp;
    end;
    end.
      

  2.   

    将单元2加到interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,单元2;
      

  3.   

    在单元中alt+F11选中要引用的单元
    单元名称.函数的名称   就可以了
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,unit2;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
         private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      Label1.Caption:=IntToStr(form2.max(12,16));
    end;end.unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm2 = class(TForm)
      private
        { Private declarations }
      public
       function  max(x,y:integer):integer;
      end;var
      Form2: TForm2;implementation{$R *.dfm}
    function  tform2.max(x,y:integer):integer;
    var
      tmp:integer;
    begin
      tmp:=x;
      if y> x then tmp:=y;
      Result:=tmp;
    end;
    end.end.