Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# and COM
Message
 
À
24/08/2001 09:03:16
Raymond Humphrys
Michigan Department of Community Health
Bath, Michigan, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Divers
Thread ID:
00548530
Message ID:
00548636
Vues:
18
>Are there any examples floating around how to do this?
>
>
>>>Is it possible to access a VFP table from a dll written using C#, that can
>>>pull records out of a table, delete them, and then pack the table?
>>>
>>>thanks
>>
>>You can create VFP Automation server that'll perform all those operations and use it from your C# program.

Hi Raymond,

Basically you do the following:
Create a program VFPServer.PRG

* VFPServer.PRG
DEFINE CLASS myVFPServer1 AS SESSION OLEPUBLIC
	DATASESSION = 2	&& set private datasession
PROCEDURE INIT()
	SYS(2335,0) && set unattended mode
ENDPROC
	
PROCEDURE myDoCmd(tcCmd)
	&tcCmd	&& execute whatever VFP command is passed
ENDPROC

PROCEDURE ERROR
	LPARAMETERS nError, cMethod, nLine
	#DEFINE CRLF  CHR(13) + CHR(10)
	LOCAL lcErrorMessage
	* Append to error log file
	lcErrorMessage = TRANSFORM(DATETIME()) + CRLF + ;
		THIS.NAME + CRLF + ;
		"Error Number   : " + TRANSFORM(nError) + CRLF + ;
		"Method         : " + cMethod + CRLF + ;
		"Line           : " + TRANSFORM(nLine) + CRLF + ;
		"Message        : " + MESSAGE()+ CRLF
	STRTOFILE(lcErrorMessage, "error.txt", .T.)
	* Notify the client
	COMRETURNERROR(THIS.NAME, lcErrorMessage)
ENDPROC

PROCEDURE myEval(tcExpr)
	RETURN EVAL(tcExpr)	&& evaluate the parameter, assuming it is  a valid VFP expression
ENDPROC

ENDDEFINE
Then, from the Command window:
BUILD PROJECT VFPserver FROM VFPServer
BUILD EXE VFPserver FROM VFPserver

oVFP = CREATEOBJECT("VFPserver.myVFPserver1")	&& create the VFP automation server object
oVFP.myDoCmd("use c:\temp\sometable") && use a sample table somewhere
?oVFP.myEval("'Table contains ' + TRANSFORM(RECCOUNT())")	&& get the record count
*This sample intended for VFP test. For C# you just use the appropriate syntax to instantiate this VFPServer and call its functions.
Note, that EXE COM server starts in the directory where VFP runtime is, so you have to set path to your directory where DBF is or use full path filename.

vfpServer.Error() method will return you any errors which may happen in your COM server.

Be careful with this server, it may execute any command for you, for example
oVFP.myDoCmd("DELETE FILE c:\*.*") && DON'T DO THIS!!!
:)
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform