给你一个例子
//这是主程序
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, unitpub;//注意这里
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(getmax(strtoint(edit1.text), strtoint(edit2.text))));
end;
end.
//这是公共单元
unit Unitpub;
interface
function getmax(x, y: integer): integer;
implementation
function getmax(x, y: integer): integer;
begin
if x > y then
result := x
else
result := y;
end;
end.