Delphi初学者,有个问题想请问一下,急!

bruce_华仔 2013-05-14 08:00:14
我想请问一下,我在一个窗体中写好了这个:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TFunctionParameter = function(const value : integer) : string;
var
Form1: TForm1;
function One(const number : integer) : string;
function Two(const number : integer) : string;
function DynamicFunction(f : TFunctionParameter; const number : integer) : string;

implementation

{$R *.dfm}
function One(const number : integer) : string;
begin
result := IntToStr(number);
end;
function Two(const number : integer) : string;
begin
result := IntToStr(2 * number) ;
end;

function DynamicFunction(f : TFunctionParameter; const number : integer) : string;
begin
result := f(number);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ss : String;
begin
ss := DynamicFunction(One,StrToInt(edit1.Text));
ShowMessage('第一个的值:'+ss);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
ss : String;
begin
ss := DynamicFunction(Two,StrToInt(edit1.Text));
ShowMessage('第二个的值:'+ss);
end;
end.

====================================
然后我在另一个页面不知道怎么去调用这个页面中的函数...求指教
...全文
108 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
憨厚小情郎 2013-05-15
  • 打赏
  • 举报
回复
先把需要调用的函数窗口加载上,然后form名+函数名这么调用就可以了。 其实我是来增加回复的,分又不偶用啦。楼上的说的挺详细的。
sololie 2013-05-14
  • 打赏
  • 举报
回复
哈哈,同一秒发帖,猿粪啊猿粪啊
feiba7288 2013-05-14
  • 打赏
  • 举报
回复
在另一个页面的interface下Use Unit1;,然后就可以直接像下面这样用你的那些函数了 var ss : String; begin ss := DynamicFunction(One,StrToInt(edit1.Text)); ShowMessage('第一个的值:'+ss); end; var ss : String; begin ss := DynamicFunction(Two,StrToInt(edit1.Text)); ShowMessage('第二个的值:'+ss); end;
sololie 2013-05-14
  • 打赏
  • 举报
回复
这些函数定义在unit Unit1; 假设你在 unit unit2中 unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm2 = class(TForm) .... implementation {$R *.dfm} uses unit1; // 引入unit1单元 .... // 然后就可以调用unit1的DynamicFunction begin unit1.function One(100); end;

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧