我想请问一下,我在一个窗体中写好了这个:
unit Unit1;interfaceuses
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.====================================
然后我在另一个页面不知道怎么去调用这个页面中的函数...求指教
unit Unit1;interfaceuses
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.====================================
然后我在另一个页面不知道怎么去调用这个页面中的函数...求指教
解决方案 »
- delphi2007打开delphi创建的project的问题
- 如何禁止WebBrowser执行脚本?
- 请教一个有关DLL释放的问题
- 程序出错
- 用惯了MS Server SQL Server(ODBC)+Delphi开发数据库,现在想用Oracle+Delphi,要注意哪些问题?
- DELPHI7序列号???????????急急急急急急急
- edit显示问题
- 大家来看一下,我的郁闷的问题!!!
- 初学DELPHI,请推荐几本好书?
- delphi2007中用TWebBrowser给微信发送中文消息显示unicode码
- 求助:DBGrid中怎樣顯示SQL中固定為空的一列?
- delphi 更新文件指定字段
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;
假设你在 unit unit2中unit Unit2;interfaceuses
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;
其实我是来增加回复的,分又不偶用啦。楼上的说的挺详细的。