Kbase P133264: Default constructor is required to instantiate class when a constructor is defined with parameters
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  15/07/2008 |
|
Status: Unverified
SYMPTOM(s):
Default constructor is required to instantiate class when a constructor is defined with parameters
Mismatched number of parameters supplied to '<function or method>'. Expecting <number> but <number> were specified. (2680)
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.1x
CAUSE:
When a constructor is defined in a class to take parameters, calling it with no parameters returns errors. This is because, at runtime, a constructor with a signature including no parameters is searched for and not found.
e.g.
/* foo.cls */
CLASS foo:
CONSTRUCTOR PUBLIC foo ( INPUT bar AS CHARACTER ):
END CONSTRUCTOR.
END CLASS.
/* foocaller.p */
DEFINE VARIABLE oFoo AS foo NO-UNDO.
oFoo = NEW foo().
FIX:
Define a default constructor with no parameters to catch the condition and return an error when it is called.
e.g.
/* foo.cls */
CLASS foo:
CONSTRUCTOR PUBLIC foo ():
MESSAGE "Class foo must be called with a parameter" VIEW-AS ALERT-BOX.
END CONSTRUCTOR.
CONSTRUCTOR PUBLIC foo ( INPUT bar AS CHARACTER ):
END CONSTRUCTOR.
END CLASS.