Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Intercepting COM events
Message
De
23/08/2005 12:02:18
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Intercepting COM events
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01042980
Message ID:
01042980
Vues:
88
Hello, everyone

Unfortunatelly, all the samples in Help show how to intercept events from an ActiveX control, ADO recordset, and so on. None of them show how to build a VFP COM and later intercept events from it. I'll post here three very very short pieces of code. Can anyone explain to me why EventHandler does not work when I'm trying to handle events from VFP COM?

Here is the OlePublic class definition. Please create a new project and copy this code in a file named comtest.prg:
Define Class Application As Session OlePublic

	Procedure Init
	EndProc

	Procedure MyTestProc(tcStringToShow As String) As Boolean
         *!* This is a test method. The code entered here will be
         *!* executed from Exe's inner classes, under user's interaction.
	EndProc

EndDefine
Build this as Win32 Executable / COM Server (exe). Then run this piece of code: (vfpcomtest.prg):
Local oComObject, oEventsReceiverClass

oComObject = CreateObject("Comtest.Application")
oEventsReceiverClass = NewObject("myclass")

llResult = EventHandler(oComObject, oEventsReceiverClass)
MessageBox("Result of EventHandler(): " + Transform(llResult))

Define Class myclass As Session OlePublic

	Implements Iapplication In "comtest.Application"

	Procedure Iapplication_MyTestProc(tcStringToShow As String ) As LOGICAL
	* add user code here - this code is supposed to be executed automatically
         * whenever COM's MyTestProc procedure is executed.
	EndProc

EndDefine
As you can see, the EventHandler() function refuses to bind the VFP COM to the local class which implements the interface. However, when I do _exactly_ the same thing with a non-VFP COM server / ActiveX, it works. Here's the example (nonvfpcomtest.prg - I have used MSComm activex control in this test):
Local oComObject, oEventsReceiverClass

oComObject = CreateObject("MSCommLib.MSComm")
oEventsReceiverClass = NewObject("myclass")

llResult = EventHandler(oComObject, oEventsReceiverClass)
MessageBox("Result of EventHandler(): " + Transform(llResult))

Define Class myclass As Session OlePublic

	Implements DMSCommEvents IN "MSCommLib.MSComm"

	Procedure DMSCommEvents_OnComm() As VOID;
 				HELPSTRING "Occurs whenever the value of the CommEvent property changes."
	* add user code here
	EndProc

EndDefine
Can anyone, please, explain why is this, what I am missing and how can I achieve the ability to get some local code executed automatically whenever a method in VFP COM is executed? I have already wasted 3 days with this and I'm going nowhere. The boss gets nervous :(

Thank you.
Grigore Dolghin
Class Software.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform