本帖最后由 unearth 于 2010-11-03 15:07:20 编辑

解决方案 »

  1.   

    把GetComponentHandle改成一般的函数,函数和方法是有区别的
      

  2.   

    首先GetComponentHandle不要为from1的成员函数,去掉TForm1的限制,至于参数的传递,参考
    http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=92561
      

  3.   

    function TForm1.GetComponentHandle(Hwnd:Integer;LParam:LongInt): Boolean;
    var
      Buffer:array[0..255] of Char;
    begin
      Result:=True;
      GetWindowText(Hwnd,Buffer,100);
      if StrPas(Buffer)='Button1' then
      begin
        PInteger(LParam)^:=Hwnd;
        Result:=False;         //终止循环
      end;
    end;
    此方法是一个类方法,它的类型为TMethod,占8个字节,在FormCreate中对GetComponentHandle取地址得到的实际上是一个TMethod。因此,你需要将GetComponentHandle改成普通方法
    function GetComponentHandle(Hwnd:Integer;LParam:LongInt): Boolean;
    var
      Buffer:array[0..255] of Char;
    begin
      Result:=True;
      GetWindowText(Hwnd,Buffer,100);
      if StrPas(Buffer)='Button1' then
      begin
        PInteger(LParam)^:=Hwnd;
        Result:=False;         //终止循环
      end;
    end;