Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking Parameters
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Checking Parameters
Divers
Thread ID:
01108949
Message ID:
01108949
Vues:
43
This is a bit long, but I need to explain my question clearly.

I want a consistant way to check parameters passed into COM objects.

Right now, I use something like the following:
PROCEDURE MyProc(aSomeArray AS Variant) AS Boolean HELPString "This method does..."
WITH This

  IF PCOUNT() = 1

    IF TYPE("aSomeArray[1]") # T_UNDEFINED

      ** Code for this method goes here
									
    ELSE
      ERROR 232, "aSomeArray" && 'aSomeArray' is not an array
    ENDIF
			
  ELSE
    ERROR 1229 && Too few arguments
  ENDIF

ENDWITH
Problem is, this is a lot of code for only 1 parameter. With methods that take 4 or 5 parameters, this
could get really ugly.

I am considering switching to something like:
PROCEDURE MyProc(aSomeArray AS Variant) AS Boolean HELPString "This method does..."
WITH This

 IF .CheckParams("MyProc", @aSomeArray)

   ** Code for this method goes here

 ENDIF

ENDWITH


HIDDEN PROCEDURE CheckParams(sProcName, p1, p2, p3, p4, p5) AS Boolean

  LOCAL bRetVal AS Boolean
  bRetVal = TRUE

  WITH This
   
   DO CASE

     CASE sProcName = "MyProc"
      DO CASE
        CASE TYPE("p1") # T_LOGICAL
          ERROR 1229 && Too few arguments
          bRetVal = TRUE

        CASE TYPE("p1[1]") # T_UNDEFINED
          ERROR 232, "aSomeArray" && 'aSomeArray' is not an array
          bRetVal = TRUE

      ENDCASE

   ENDCASE

  ENDWITH

  RETURN bRetVal

ENDPROC
I welcome any thoughts/input on this.

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform