|
| Re: How to fire a com event |
 |
Tue, 18 Mar 2008 10:42:06 -070 |
"Maurice" <manker@tpg.com.au> wrote in message
news:47df71f1@newsgroups.borland.com...
> Create a new VCL Forms project
> Create a COM Object (X) with Event support code enabled
The only reason to do that is if the COM object is going to be used by
external programs. In which case, you should use an Automation Object, not
a COM object.
Beyond that, there is no point in creating a COM object for private use
within the same program that defines it. If you are going to expose access
to a COM object for other programs to use, then they will create the object
instances, not you. Simply keep track of the instances that get created,
such as by having TXImpl's constructor and destructor add/remove the
object's 'this' pointer to a list somewhere in your code. You can then run
through the instances when needed, calling Fire_MyEvent() on them.
Gambit
|
| Post Reply
|
| Re: How to fire a com event |
 |
Tue, 18 Mar 2008 16:04:44 -070 |
"Maurice" <manker@tpg.com.au> wrote in message
news:47e0471d$1@newsgroups.borland.com...
> But I am still puzzled -- I thought it was the job of
> Fire_MyEvent() to iterate through the list of clients stored
> in the TEvents_X:ConnectionPointContainer and call
> MyEvent() on each
It is supposed to, but the connection point logic is not implemented
correctly, at least in my experience. Each client ends up with its own
connection point list, so Fire_...() methods only have 1 client object to
ever call into, and thus the need to call Fire_...() on each client manually
one at a time manually. At least, that has always been my experience in all
of my own COM servers. The connection point list is not as global as it is
supposed to be.
Gambit
|
| Post Reply
|
| How to fire a com event |
 |
Tue, 18 Mar 2008 18:40:36 +110 |
I am sure there is a simple answer to this: in BDS 2006 (C++) I do the
following
Create a new VCL Forms project
Create a COM Object (X) with Event support code enabled
Add a method (MyEvent) to the IXEvents interface
Include the X implementation header in the form unit
Place a button on the form with the following code
//---------------------------------------------------------------------------
void __fastcall TForm1::FireEventClick(TObject *Sender)
{
Fire_MyEvent();
}
//---------------------------------------------------------------------------
Of course it doesn't work because is not a global function but a method of
the TEvents_X template class
If a method is added to the IX interface and its definition includes a call
to Fire_MyEvent(); then there's no problem.
I have tried all sorts of things to create a pointer to an instance of this
class, eg
CComPtr<TEvents_X<TXImpl> > ptr; // or CComPtr<X> ptr;
ptr.CoCreateInstance(CLSID_X);
ptr->Fire_MyEvent();
but to no avail. What am I doing wrong?
Thanks - Maurice
|
| Post Reply
|
| Re: How to fire a com event |
 |
Wed, 19 Mar 2008 09:50:07 +110 |
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:47e0010a$2@newsgroups.borland.com...
> Simply keep track of the instances that get created, such as by having
> TXImpl's constructor and destructor add/remove the object's 'this' pointer
> to a list somewhere in your code. You can then run through the instances
> when needed, calling Fire_MyEvent() on them.
>
Great! That does what I want.
But I am still puzzled -- I thought it was the job of Fire_MyEvent() to
iterate through the list of clients stored in the
TEvents_X:ConnectionPointContainer and call MyEvent() on each:
template <class T> HRESULT
TEvents_X<T>::Fire_MyEvent(void)
{
T * pT = (T*)this;
pT->Lock();
IUnknown ** pp = m_vec.begin();
while (pp < m_vec.end())
{
if (*pp != NULL)
{
m_EventIntfObj.Attach(*pp);
m_EventIntfObj.MyEvent();
m_EventIntfObj.Attach(0);
}
pp++;
}
pT->Unlock();
return S_OK;
}
|
| Post Reply
|
|
|
|
|
|
|
|
|
|