Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OLE Exception code using my class
Message
 
To
22/08/2007 15:44:09
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01249645
Message ID:
01249699
Views:
22
Jay,

I just realized you are doing something wrong, that would not be bad if it weren't for the fact that I believe I gave you the code to do it! Sorry about that. You can not reference this in the INIT of the object, for is it not yet fully initialized, so, you need to adjust your code a little, I tested this and it seems to work (well, I get an error when the binded events fired but those should be easy to fix)

Remove the EVENTHANDLER from your init to a different method, I called it Setup()
	procedure setup() as Boolean
		local llSuccess
		llSuccess = EVENTHANDLER(THIS.oSock, THIS)
		if llSuccess && You should move this out, just put it as test
			? 'Event handler succeeded'
		else
			? 'Event handler failed'
		endif
		return llSuccess
	ENDPROC
This almost works, still is not firing DataArrival though
clear
oxServer = CREATEOBJECT( "EMPS_Class" )
oxServer.Setup()
oxServer.oSock.LocalPort = 6565
oxServer.oSock.Listen()
? 'Server State', oxServer.oSock.State

ox = CREATEOBJECT( "EMPS_Class" )
ox.Setup()
ox.oSock.Connect(oxServer.oSock.LocalIP, 6565)
lnStart = Seconds()
do while ox.oSock.State = 6 and Seconds() - lnStart <= 5
	doevents
enddo

? 'Client State', ox.oSock.State, 'Elapsed time: ', Seconds() - lnStart
if ox.oSock.State = 7
	ox.oSock.SendData("This is a test.")
endif

ox.oSock.close()
oxServer.oSOck.Close()

**********************************************************
DEFINE CLASS EMPS_Class AS SESSION OLEPUBLIC
**********************************************************

	IMPLEMENTS DMSWinsockControlEvents IN "c:\windows\system32\mswinsck.ocx"

	**********************************************************
	PROCEDURE DMSWinsockControlEvents_Error(NUMBER AS INTEGER, DESCRIPTION AS STRING, Scode AS NUMBER, SOURCE AS STRING, HelpFile AS STRING, HELPCONTEXT AS NUMBER, CancelDisplay AS LOGICAL) AS VOID HELPSTRING "Error occurred"
		* add user code here
		ENDPROC


	**********************************************************
	PROCEDURE DMSWinsockControlEvents_DataArrival(bytesTotal AS NUMBER) AS VOID HELPSTRING "Occurs when data has been received from the remote computer"

		strData = SPACE(256)  && Define string to pass to GetData

		THIS.oSock.GETDATA(@strData)

		* Testing code to parse HL7 billing data from Medinotes Client to EM tables
		? 'Data received: ', strData

		ENDPROC


	**********************************************************
	PROCEDURE DMSWinsockControlEvents_Connect() AS VOID HELPSTRING "Occurs connect operation is completed"
		* add user code here
		? 'Connected'
		ENDPROC


	**********************************************************
	PROCEDURE DMSWinsockControlEvents_ConnectionRequest(requestID AS NUMBER) AS VOID HELPSTRING "Occurs when a remote client is attempting to connect"

		#DEFINE sckClosed 0

		? 'Connection accepted', requestID
		IF THIS.oSock.State <> sckClosed
			THIS.oSock.CLOSE
		ENDIF

		*!* Accept the request with the requestID
		*!* parameter.
		THIS.oSock.ACCEPT(requestID)

		ENDPROC


	**********************************************************
	PROCEDURE DMSWinsockControlEvents_Close() AS VOID HELPSTRING "Occurs when the connection has been closed"
		* add user code here
		? 'Closed'
		ENDPROC


	**********************************************************
	PROCEDURE DMSWinsockControlEvents_SendProgress(bytesSent AS NUMBER, bytesRemaining AS NUMBER) AS VOID HELPSTRING "Occurs during process of sending data"
		* add user code here

		ENDPROC


	**********************************************************
	PROCEDURE DMSWinsockControlEvents_SendComplete() AS VOID HELPSTRING "Occurs after a send operation has completed"
		* add user code here

		ENDPROC


	oSock = NULL


	**********************************************************
	PROCEDURE INIT

		THIS.oSock = CREATEOBJECT("MSWinsock.Winsock.1")

	procedure setup
		if EVENTHANDLER(THIS.oSock, THIS)
			? 'Event handler succeeded'
		else
			? 'Event handler failed'
		endif
	ENDPROC

ENDDEFINE
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform