unit Unit2;interfacetype
TMyFunc = function (itest:integer):boolean; TMyClass = class
public
MyFunc: TMyFunc;
function Func(itest:integer):boolean;
procedure Test;
end; function Func2(itest:integer):boolean;implementationfunction TMyClass.Func(itest:integer):boolean;
begin
result := True;
end;function Func2(itest:integer):boolean;
begin
result := True;
end;procedure TMyClass.Test;
begin
MyFunc := Func2;
MyFunc := Func; // 为什么这一句无法编译??
end;end.谢谢!
TMyFunc = function (itest:integer):boolean; TMyClass = class
public
MyFunc: TMyFunc;
function Func(itest:integer):boolean;
procedure Test;
end; function Func2(itest:integer):boolean;implementationfunction TMyClass.Func(itest:integer):boolean;
begin
result := True;
end;function Func2(itest:integer):boolean;
begin
result := True;
end;procedure TMyClass.Test;
begin
MyFunc := Func2;
MyFunc := Func; // 为什么这一句无法编译??
end;end.谢谢!
解决方案 »
- 由于单位老有人晚上不关机,想做个简单工具监控一下哪些机器没关。
- 打开文件问题,请各位帮忙(急)!
- 请问Code Completion效果如何实现
- 获取WIN2K的用户名及密码程序
- 20个整数想一次性赋值给一个大小为20的整数数组,请问怎么赋值? 我的pascal很烂。
- 简单问题,在线求助!!
- 绝对免费电影下载!不看你会后悔一辈子!^_^
- 各位高手,帮我看看下面这段代码好吗?
- 在dbgrid里的滚动条的颜色怎么设置?(我的可用分不够,可以到别的贴子上拿分)
- 请问我在interface中声明变量在别的已引用的单元中为什么不能使用
- 帮忙看看吧 ! 做了大半个月了,还是没弄好,超级菜鸟“严重”“崩溃”求救。
- 请教诸位高手:为什么数据集滚动时,自动将记录变化保存,我希望当我执行table1.post时才保存的。郁闷!请支招,不胜感激!
MyFunc需要的是一个事件的指针,当然编译不过去了。
TMyFunc = function (itest:integer):boolean of object;
这样试下
如SetWindowsHookEx(iHook, HookProc, hInstance, 0);
这时候,如果HookProc如果是未声明为of object时是可以用的,但声明了of object就用不了了。
我这个HookProc是作为参数传到调用SetWindowsHookEx这样函数的地方的。搜索要同样问题的解决方法:淘金坑说的非常对啊,把类方法转化为32位指针
但是我不知道怎么做继续请教!
谢谢!
...
FWndProcInstance := MakeObjectInstance(SnapExCallback);
问题是你的
function TSnapPanel.SnapExCallback(var info: SNAP_INFO): Integer; stdcall;和要求的
原 型:CGSTATUS __stdcall CGOpenSnapEx(HCG hcg,SNAPPROC
pSnapFunc,void *pParam)根本不同,传进去,会出错的
你的Func定义在类外面不就可以了,也可以定义一个新的函数封装Func的调用,何必非要把一个类函数当回调函数用呢。
Func需要用到类里的东西。
function Func3(itest:integer):boolean;stacall;
var
AClass: TMyClass;
begin
AClass := TMyClass.Create;
Result := AClass.Func();
end;
回调函数就使用Func3
但是这样还是不行,对TMyClass里的内容进行了一定的操作后再调用.Func()才有用。其实还有另外一个方法,就是把Func()的地址直接付给 一个pointer,但我不知道怎么做。