Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Debug a COM server
Message
 
À
02/04/2003 13:53:52
Héctor Lizarraga
Gobierno Del Edo de Querétaro
Querétaro, Mexique
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00773134
Message ID:
00774362
Vues:
21
Hi Hector,

>Hi, does anyone knows how can I debug a vfp COM server? because the entire build/register/test process is a pain.

Yes you can basically use the VFP environment to do this. It's a bit of work but it boils down to including a factory method in your code that can instantiate the VFP runtime and pass back a reference to the object:
************************************************************************
* 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 :: CloseDebugInstance
Although 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.

You can SET STEP ON in your code and then to use it looks something like this:
#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.

Maurice's approach is similar although I prefer the simplicity of this setup.

Keep in mind that if you use .Net you will need to use late binding against each of the returned objects, which is really a pain. If you use ASP or other COM client you can simply swap the debug references from the live reference in some way.

Regards,
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform