Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Andy at Rushcliff
  Where is Andy at Rushcliff?
 Derby
 United Kingdom
 Andy at Rushcliff
 To: Marcia Akins
  Where is Marcia Akins?
 Akorn
 Ohio - United States
 Marcia Akins
Subject: RE: Defining my own code for a COM object event
Thread ID: 103972 Message ID: 104085 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Active X Controls & OLE Automation
Date: Friday, August 11, 2006 11:13:38 AM         
   



> The class has an event called "OnDone" which is called whenever i call the "Go" method and it completes successfully.
>
> The documentation for the "OnDone" method show a list of defined parameters which i can use.
>
> My question is: How do i define my own code for the "OnDone" event so that i can process my own code each time the "Go" method completes successfully.

>
> What you need to do is create a custom handler class that implement the interface of your COM component that has the OnDone method. You can then write your code in the OnDone method of your handler class.
>
> You associate your handler class with the COM component using the EVENTHANDLER() function.
>
> See EVENTHANDLER() and DEFINE CLASS Command - IMPLEMENTS Clause in the on-line help.
>
> The easiest way to create your custom handler object is to open the COM object's type library in the object browser and then drag the appropriate interface into a prg. This will create a skeleon program for you that you can modify.
>
> Regards,
> Marcia G. Akins
> Tightline Computers, Inc.


Thanks Marcia
I have played around with some code and this example below works great.


oMyObject = CREATEOBJECT("MYCOM.ClassName")

oevents = NEWOBJECT('ehandler')
EVENTHANDLER(oMyObject,oevents)

* insert my normal code for the object here

oMyObject.Go() &&this calls the "oMyObject.OnDone" event when complete



* Defined Classes

DEFINE CLASS ehandler AS session
IMPLEMENTS _IClassNameEvents IN "MYCOM.ClassName"

PROCEDURE _IClassName_OnSent(lRet As Number @, ErrDescription As VARIANT @, nKey As Number @, tParam As VARIANT @) as Logical

*here is my custom code for the OnDone event

*
ENDPROC

ENDDEFINE

ENTIRE THREAD

Defining my own code for a COM object event Posted by Andy at Rushcliff @ 8/10/2006 3:12:08 PM
RE: Defining my own code for a COM object event Posted by Andy Kramek @ 8/10/2006 4:23:02 PM
RE: Defining my own code for a COM object event Posted by Andy at Rushcliff @ 8/10/2006 4:45:34 PM
RE: Defining my own code for a COM object event Posted by Bernard Bout @ 8/10/2006 5:46:21 PM
RE: Defining my own code for a COM object event Posted by Andy at Rushcliff @ 8/10/2006 5:53:51 PM
RE: Defining my own code for a COM object event Posted by Bernard Bout @ 8/11/2006 6:20:52 AM
RE: Defining my own code for a COM object event Posted by Andy Kramek @ 8/10/2006 11:09:01 PM
RE: Defining my own code for a COM object event Posted by Andy at Rushcliff @ 8/10/2006 4:48:06 PM
RE: Defining my own code for a COM object event Posted by Marcia Akins @ 8/10/2006 8:54:00 PM
RE: Defining my own code for a COM object event Posted by Andy at Rushcliff @ 8/11/2006 11:13:38 AM
RE: Defining my own code for a COM object event Posted by Marcia Akins @ 8/11/2006 12:31:40 PM