看例程:
type
FunTYpe = function(X :integer):INteger; //定义一个过程类型
TForm1 = class(TForm)
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Function Doub(x:Integer) :integer; //定义一个成员函数
public
{ Public declarations }
end;
implementation{$R *.DFM}Function TForm1.Doub(x:Integer) :integer;
Begin
result := 2*x ;
End;
procedure TForm1.Button1Click(Sender: TObject);
Var
Dou : FunTYpe;
begin
dou := Doub; 赋值 *******************错误信息,regular procedure Or
************************method pointer ***************
end;
end.
问题,如何避免出错,一定要普通函数指针,才可以赋值吗?
type
FunTYpe = function(X :integer):INteger; //定义一个过程类型
TForm1 = class(TForm)
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Function Doub(x:Integer) :integer; //定义一个成员函数
public
{ Public declarations }
end;
implementation{$R *.DFM}Function TForm1.Doub(x:Integer) :integer;
Begin
result := 2*x ;
End;
procedure TForm1.Button1Click(Sender: TObject);
Var
Dou : FunTYpe;
begin
dou := Doub; 赋值 *******************错误信息,regular procedure Or
************************method pointer ***************
end;
end.
问题,如何避免出错,一定要普通函数指针,才可以赋值吗?
procedure TForm1.Button1Click(Sender: TObject);
Var
Dou : FunTYpe;
begin
dou := @Doub; 赋值 *******************错误信息,regular procedure Or
************************method pointer ***************
end;
请大家多多指点。很急
声明:
本人保证所提供的方法是所知的最好方法
解答问题纯属公益性质
所以请不要向我追问
如果有时间自会关注后续问题
分析:
//在计算机中一切都可以看成数据
//函数和方法当然也是一种数据
//是数据一定就有存储的位置和其存储的值
//是数据也一定有其存储的规则
方法就是包含在类里面的函数
普通函数的上级区域是单元
方法的上级区域则是类
就是说它们等级就不一样
如果要访问函数就必须先确定其所在单元
如果要访问方法则就必须先确定其所在类及类所在单元
//方法可以直接访问类中的元素
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := '这里的Caption就是类实例的属性';
end;
总之方法和函数肯定不是同一种类型
也没有什么复杂
方法就是类中的函数
还要怎么讲?
实际工作中慢慢理解吧!
问题:函数类型和方法类型的区别是什么?
设计:Zswang
日期:2002-10-07
方案:声明方法类型(事件类型)
附言:主要是区域不同。总不能说北京在广州的什么地方吧!
//*)type
FunType = function(X: Integer): Integer of object; //定义一个方法类型
//~~~~~~~~~~
声明:
本人保证所提供的方法是所知的最好方法
解答问题纯属公益性质
所以请不要向我追问
如果有时间自会关注后续问题
分析:
//在计算机中一切都可以看成数据
//函数和方法当然也是一种数据
//是数据一定就有存储的位置和其存储的值
//是数据也一定有其存储的规则
方法就是包含在类里面的函数
普通函数的上级区域是单元
方法的上级区域则是类
就是说它们等级就不一样
如果要访问函数就必须先确定其所在单元
如果要访问方法则就必须先确定其所在类及类所在单元
//方法可以直接访问类中的元素
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := '这里的Caption就是类实例的属性';
end;
总之方法和函数肯定不是同一种类型
也没有什么复杂
方法就是类中的函数
还要怎么讲?
实际工作中慢慢理解吧!
问题:函数类型和方法类型的区别是什么?
设计:Zswang
日期:2002-10-07
方案:声明方法类型(事件类型)
附言:主要是区域不同。总不能说北京在广州的什么地方吧!
//*)type
FunType = function(X: Integer): Integer of object; //定义一个方法类型
//~~~~~~~~~~