function proc(h:hwnd;lparam:lparam):bool;
begin
edit1.text:=inttostr(h);
result:=true;
end;
在編譯時提示edit1 undeclare,如改為
function tform1.proc(h:hwnd;lparam:lparam):bool;
就沒有上述問題,但編譯到調用過程enumchildwindows(handle,@proc,0);會提示:
variable required.
請問兩種函數的定義有何分別??
如果用第一種定義方法,edit1又該如何聲明?
begin
edit1.text:=inttostr(h);
result:=true;
end;
在編譯時提示edit1 undeclare,如改為
function tform1.proc(h:hwnd;lparam:lparam):bool;
就沒有上述問題,但編譯到調用過程enumchildwindows(handle,@proc,0);會提示:
variable required.
請問兩種函數的定義有何分別??
如果用第一種定義方法,edit1又該如何聲明?
function proc(h:hwnd;lparam:lparam):bool;
表示这个函数并不是属于哪个类,不是某个类的方法;
function tform1.proc(h:hwnd;lparam:lparam):bool;
表示这个是属于类TForm1的方法。你的Edit1是类TForm1的一个字段,所以在第一种方法里不能直接使用,在这里却可以用。所以,在第一种方法里,你也可以这样
function proc(h:hwnd;lparam:lparam):bool;
begin
Form1.edit1.text:=inttostr(h); // 假设你的TForm1有Form1这个对象
result:=true;
end;
第一种方法里你可以将Edit1作为参数传给proc
第二种是类里的一个方法, 不能用做标准的windows回调函数
begin
Form1.edit1.text:=inttostr(h);
result:=true;
end;
或
function Form1.proc(h:hwnd;lparam:lparam):bool;
begin
edit1.text:=inttostr(h);
result:=true;
end;//不过这以前要申明一次------------
有空到www.nxrs.net坐坐
function Form1.proc(h:hwnd;lparam:lparam):bool;編譯到調用過程enumchildwindows(handle,@proc,0);會提示:
variable required.
這又是什麼原因呢??
請再指教.
对它来说proc是不可见的