在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//要点15: 调用其他单元的函数 //包含函数的单元: unit Unit2; interface function MyFun(x,y: Integer): Integer; {函数必须在接口区声明} implementation function MyFun(x,y: Integer): Integer; {函数必须在函数区实现} begin Result := x + y; end; end. //调用函数的单元: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses Unit2; {必须 uses 定义函数的单元} procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin i := MyFun(1,2); {调用函数} //i := Unit2.MyFun(1,2); {有时为了避免重名, 需要这样调用} ShowMessage(IntToStr(i)); {3} end; end. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论