PRB: NEWOBJECT() Requires Null or "" for 2nd & 3rd Parameters

ID: Q194668

The information in this article applies to:

SYMPTOMS

Using the NEWOBJECT() function, leaving any parameters blank while filling subsequent parameters results in the following syntax error:

   Program Error.
   Function argument value, type, or count is invalid.

CAUSE

Microsoft Visual FoxPro does not allow empty parameters in internal methods and functions.

RESOLUTION

When running the NEWOBJECT() function passing an optional parameter, make sure to pass "" or NULL in any optional parameter that precedes the one being passed.

STATUS

This behavior is by design.

MORE INFORMATION

This functionality differs from the NEWOBJECT method. The NEWOBJECT method allows for passing empty parameters because Visual FoxPro does allow empty parameters when calling iDispatch methods from Component Object Model (COM) objects.

Steps to Reproduce Behavior

Run the following code from a program file:

   CLEAR
   PUBLIC oX
   ********NEWOBJECT METHOD*************
   *!* The NEWOBJECT method allows blank arguments between those filled.
   oX = CREATEOBJECT('cst1','One')
   ?oX.cprop
   oX.NEWOBJECT('cst3','cst1',,,'Two') && Works
   ?oX.cst3.cprop

   ********NEWOBJECT FUNCTION Used Below***********
   oX=NEWOBJECT('cst1','','','Three')   && Works
   ?oX.cprop
   oX=NEWOBJECT('cst1',NULL,NULL,'Four') && Works
   ?oX.cprop
   oX=NEWOBJECT('cst1',,,'Five') && Fails with Syntax error
   ?oX.cprop
   *!* NEWOBJECT Function errors with blank arguments between those filled.
   DEFINE CLASS cst1 AS CUSTOM
      cprop = ''
      PROCEDURE INIT
         LPARAMETERS tctest
         THIS.cprop = tctest
     ENDPROC
   ENDDEFINE

Additional query words: kbVFp600 kbOOP
Keywords          : kbVFp600 
Version           : WINDOWS:6.0
Platform          : WINDOWS
Issue type        : kbprb

Last Reviewed: October 24, 1998