>IF FILE("myclass.dll") > DECLARE integer DllUnregisterServer IN myclass.dll && a missing step? > DllUnregisterServer() > CLEAR DLLS >ENDIF >BUILD PROJECT myserver FROM myclass >BUILD DLL myserver from myserver recomp && the DLL is called myServer >*now test this COM server: >ox = CreateObject("myserver.myclass") && create the server object >ox.mydocmd("USE home(1)+'samples\data\customer'") && use a table >?ox.myeval("RECCOUNT()") && get the record count > >DEFINE CLASS myclass AS session OLEPUBLIC && the class is myClass > PROCEDURE MyDoCmd(cCmd as String) as Variant ; > helpstring "Execute a VFP cmd" > &cCmd && just execute parm as if it were a fox command > FUNCTION MyEval(cExpr as String) ; > helpstring "Evaluate a VFP expression" > RETURN &cExpr && evaluate parm as if it were a fox expr > FUNCTION Error(nError, cMethod, nLine) > COMreturnerror(cMethod+' err#='+str(nError,5)+; > ' line='+str(nline,6)+' '+message(),_VFP.ServerName) > && this line is never executed >ENDDEFINE >>
>Sub t() >Dim ox As New myserver.myclass && MyServer.MyClass >ox.mydocmd ("set exclusive off") >ox.mydocmd ("use d:\fox70\test\customer") >n = ox.MyEval("reccount()") >nflds = ox.MyEval("fcount()") >nsecs = ox.MyEval("seconds()") >For i = 1 To n > For j = 1 To nflds > cc = "evaluate(field(" & j & "))" > Application.Sheets(1).Cells(i, j).Value = ox.MyEval(cc) > Next > ox.mydocmd ("skip") >Next >MsgBox (ox.MyEval("seconds()") - nsecs) >End Sub >>
* prg that creates and builds MTDLL - first ran this Local m.myDLL TEXT TO m.myDLL noshow DEFINE CLASS testclass as Session olepublic Datapath = "C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 7\SAMPLES\DATA" PROCEDURE GetCustomerAmt(tcCustomerID as String) as Currency LOCAL ARRAY aMaxAmt[1] SELECT maxordamt ; FROM (ADDBS(this.DataPath)+"customer") ; WHERE cust_id == UPPER(m.tcCustomerID) ; INTO ARRAY aRetVal return IIF(_Tally>0,aRetVal,NTOM(0)) ENDPROC PROCEDURE TimePlease() as Datetime RETURN DATETIME() endproc enddefine ENDTEXT Strtofile(m.myDLL,'opubclass.prg') Build Project VFPopubtest From opubclass.prg Build Mtdll VFPopubtest From VFPopubtest recompileThe I went to excel and created these 2 macros :
Sub proc1() Dim myVFP_COM As Object Set myVFP_COM = CreateObject("VFPopubtest.TestClass") ActiveCell.Offset(0, 1).Value = myVFP_COM.GetCustomerAmt(ActiveCell.Value) Set myVFP_COM = Nothing End Sub Sub proc2() Dim myVFP_COM As Object Set myVFP_COM = CreateObject("VFPopubtest.TestClass") ActiveCell.Value = myVFP_COM.TimePlease() Set myVFP_COM = Nothing End SubThen I assigned those macros to Ctrl+K and Ctrl+L.