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;
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=92561
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;