我想把所有的自定义函数放在一个单元文件中然后在别的单元中 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'
————————————————————————
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'
解决方案 »
- 生日散分帖!
- 如何在程序中使用adoquery1实现创建新表的功能???????????????????????????????
- 关于ADOTable里取字段取值,赋值出现的问题,求教!
- delphi有类似pb的datawindow的saveas功能的控件,可以将数据集保存为dbf或excel等其他格式吗??
- 见鬼了,我TMyStringGrid中创建一个TEdit对象出问题
- 我是今年的毕业生,还有几天就要去济南一家网络公司工作了。请大家给我点忠告吧
- 入门的问题
- 图形按扭
- delphi新手问一些菜鸟问题,tSynMemo not found 是什么问题?请轻拍砖~
- 点messagedlg对话框中的“取消”按钮会出现错误提示,为什么?
- 这样情况怎么截取字符呢?
- 一本好书想到大家一起分享
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.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,单元2;
单元名称.函数的名称 就可以了
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.