************************************************************************ * ASPTools :: GetDebugInstance **************************************** *** Function: Allows debugging of the server *** Pops up debugger on SET STEP or dialog on error ************************************************************************ FUNCTION GetDebugInstance as Object LOCAL loObject THIS.oVFPDebug = CREATEOBJECT("VisualFoxPro.Application.8") THIS.oVFPDebug.Visible = .T. *** Now setup the environment - this will be custom *** for your particular server or object *** you might create a generally accessible function *** for this if more than one object are being debugged THIS.oVFPDebug.DoCmd("cd " + THIS.cAppStartPath) THIS.oVFPDebug.DoCmd("DO ASPTools") && Load class libs *** Have VFP create an instance of this object object loObject = THIS.oVFPDebug.Eval("CREATE('" + this.Class + "')") *** If you want the ASP scripting context *** you have to create it here oMTS = CreateObject("MTxAS.AppServer.1") this.oScriptingContext = oMTS.GetObjectContext() *** and attach it to our new instance loObject.oScriptingContext = this.oScriptingContext RETURN loObject ENDFUNC * ASPTools :: GetDebugInstance ************************************************************************ * ASPTools :: CloseDebugInstance **************************************** *** Function: Shuts down the debug instance created with *** GetDebugInstance ************************************************************************ FUNCTION CloseDebugInstance() THIS.oVFPDebug.visible = .F. THIS.oVFPDebug = 0 ENDFUNC * ASPTools :: CloseDebugInstanceAlthough this example is specific to ASP, it works in any environment (just remove the MTxAs reference code there) to return an instance of your object from the VFP environment back to the calling application.
#IF DEBUG oMain = CREATE("YourObject.YourClass") && Main COM Object oRef = oMain.GetDebugInstance() && VFP IDE will fire up #ELSE oRef = CREATE("YourObject.YourClass") && Main COM Object #ENDIF oRef.CallSomeMethod() && Will run through IDE instance ... more calls here oRef.CloseDebugInstance()Note that each object you want to handle through the IDE instance must be running through the IDE in order to be debugged so one thing you might do is build a generic factory class that can hand back these references a little more generically. For example if you instantiate a bunch of different objects you might create an IDE debug object that can instantiate the objects instead of using CREATEOBJECT() directly.