Big question on the assignment of event property of VCL object in BCB(100分)

  • 主题发起人 主题发起人 RoboCop
  • 开始时间 开始时间
R

RoboCop

Unregistered / Unconfirmed
GUEST, unregistred user!
I created a TImage object dynamiclly,and I wanted to response to the mouse click on it,so I wrote a handler function just like this:
void __fastcall MyOnClick(TObject *Sender)
then
I should assign it (the function pointer MyOnClick) to OnClick event of my TImage object,so I wrote the following code:
pImg->OnClick=(TNotifyEvent)MyOnClick;
But I got the following compiler error:
Cannot cast from 'void (_fastcall *)(System::TObject *)' to 'void (_fastcall * (_closure )(System::TObject *))(System::TObject *)'
I was completely confused,and would you topguns like to help me?
Thank you very much!
 
Hehe.. In BCB, there is a special keyword defined for event handlers.
You must write your event handler as:
void __fastcall __closure MyOnClick(TObject *Sender);

Good luck!
 
很遗憾,你的解答并不正确,会得到另一个编译错误.事实上我自己也曾经试过.
现在我自己已经有答案了:
给Event属性赋值,函数必须为类成员才行.看下面这段例子真相即可大白于天下:

class TForm1 : public TForm
{
....
public:
void __fastcall MyonClick(TObject *Sender); //Define like this
};

...
TForm1 *Form1;
...
//必须这样,否则编译器弄不清是要调用函数还是要函数指针的地址
pImg->OnClick=(TNotifyEvnet)&Form1->MyOnClick;

我自己解决了这个问题,那悬红该怎么处理呢? Can I take it back?
 
分数你是拿不会去了,不过可以给我 ^_^
我的意思是说你应该在提问之前看看已答问题集,
可以节约分数,我曾经解答过这种问题.
当然,现在已答问题越来越多了,想搜索到确实不容易.
而且网又那么慢... :(
 
Tell me a secret trick,then
I give it to you ;-)
 
What kind of trickdo
you want?
 
How about these:
1.How can I get notified when Win95's taskbar switches between show and hide mode?
2.I want to use IE to display HTMLdo
cuments in my own window,how can Ido
it?This is a question on
OLE,I wish you are an OLE master
Thank u
 
1. yet to look-up :)
2. Simply import "MS Internet controls"(ActiveX/OCX),
and then
use them.
 
Thank u,I've solved it(IE),not perfect,but it works.
How can I detect IE has been installed correctly?(Not tell me check the regsitry)
 
I think it depends on how you use/call IE.
1. if you use the OCX as I suggested, there is no way to detect,
because you programm can't startup correctly in the machine
without IE installed.
2. if you call IE by CreateOleObject(actually Ido
n't know the
object name should be used yet), the try ... except statement
can alreadydo
the check.
3. Within the foreseeable future, you can always expect IE to be
installed in Win95/98/NT... ^_*
 
dwwang the master:
Would u mind to email your great tips and advises to me?My email is
robocop@188.net.
And have you got the answer to my first question?
thank u
 
Whatdo
you mean by "great tips and advises"?
As to the question, I'm still looking for :-)
 

Similar threads

I
回复
0
查看
720
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
1K
import
I
后退
顶部