我们都知道下面的定义
TNotifyEvent=procedure(Sender:TObject)of Object;
它提供了一个对象成员函数的指针,数据内容中包括对象信息和过程信息,
我希望可以有一种方式可以实现不包括对象信息的指向对象成员的指针.
就想C++中的指向对象成员的指针,

解决方案 »

  1.   

    TNofityEvent的功能我知道,
    我就是需要类似于使用C++成员指针的方法
      

  2.   

    TNotifyEvent=procedure(Sender:TObject)of   Object;
    就是类似于使用C++成员指针的方法,至于其中的Sender参数并不是必须的,你自己定义类型时可以不用,如:
    TMyProc=procedure of Object;
    TMyFunc=function(a: Integer): Integer of Object;等等
      

  3.   

    sorry,你们说的方法.我都知道,
    TNotifyEvent=procedure(Sender:TObject)of Object;
    不光包括了成员函数地址,而且还包含引用对象的信息.
    它的使用,是针对特定对象元素的.我的希望有种方法可以只包含成员函数信息,而不包含引用对象信息;
    在使用时,我再通过特定的对象引用.有人用过C++的成员指针(成员数据指针/成员函数指针)吗?
      

  4.   

    lz要的可能是下面这种指针:class Example
    {
        long value;
    public:
        Example(void){ value = 0; }
        void set_value(long v){ value = v; }
        long get_value(){ return value; }
    };void main()
    {
        long (Example::*fp)() = &Example::get_value;
        Example e;
        long v = (e.*fp)();
    }
    这样的成员函数指针只包含类成员函数地址,不指向特定的对象。
    Delphi可以用MethodAddress取得说明在published部分类方法的地址,但是不好直接通过指针调用该方法,因为Delphi类方法的调用标准是fastcall,同时Pascal也是强类型语言,但是可以用BASM模拟,例如:
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        function GetValue: Integer;
      private
        { Private declarations }
        value: Integer;
      public
        { Public declarations }
         procedure SetValue(v: Integer);
      end;var
      Form1: TForm1;implementation{$R *.dfm}function TForm1.GetValue: Integer;
    begin
      Result := value;
    end;procedure TForm1.SetValue(v: Integer);
    begin
      value := v;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      func: Pointer;
      v: Integer;
    begin
      func := TForm1.MethodAddress('GetValue');   // 取得类方法地址,与具体对象无关
      SetValue(10);                               // 具体对象Form1
      asm
        mov   eax, Form1
        mov   edx, func
        call  edx
        mov   v, eax
      end;
      ShowMessage(IntToStr(v));
    end;
      

  5.   

    (p1,p2)-->(p3,p2) or (p1,p3)
      

  6.   

    我想,Delphi对Pascal的扩展,还是很有限的.
    谢谢大家支持!