Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Syntax checking
Message
De
27/11/2001 05:52:44
 
 
À
27/11/2001 05:13:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00586184
Message ID:
00586195
Vues:
19
Pascal,
The only way I can think of is to COMPILE the code and check for an .ERR file. This seems to work, but unfortunately requires the COMPILE command which was not available in the runtime before VFP6 SP5 (I think). Anyway, here's a simple syntax checker that returns the compiler's error message if there's a syntax error, otherwise a blank:
?SyntaxChecker("BROWSE") && returns ''
?SyntaxChecker("BORWSE") && returns 'BORWSE'
                                    'Error in line 1: Unrecognized command verb.'

PROCEDURE SyntaxChecker
LPARAMETERS tcCode

lcTempPrg = AddBs(SYS(2023)) + "A" + RIGHT(SYS(3), 7) + ".TMP"
lcErrFile = FORCEEXT(lcTempPrg, "ERR")

STRTOFILE(tcCode, lcTempPrg)
COMPILE (lcTempPrg)

IF FILE(lcErrFile)
   *-- an error occurred
   lcRetVal = FILETOSTR(lcErrFile)
ELSE
   lcRetVal = ""
ENDIF

*-- cleanup
DELETE FILE (FORCEEXT(lcTempPrg, "*") )

RETURN lcRetVal
HTH
>How can I check if a command contained in a string has valid syntax, whithout executing it. Thought it was possible, but can't find how (VFP 5.0).
>
>I have a program that dynamically builds a query, so I want to know if the query has correct syntax before executing it.
Daniel
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform