I have a .p that defines some functions:
lib.p:
FUNCTION foo RETURNS INTEGER (INPUT ip-num AS INTEGER):
/* code here */
END FUNCTION.
in a separate file I have a CLASS defined that contains a private HANDLE variable and runs the .p with the PERSISTENT SET option.
CLASS blah INHERITS Form :
DEF PRIVATE VAR hLib AS HANDLE NO-UNDO.
CONSTRUCTOR PUBLIC blah( ):
RUN lib.p PERSISTENT SET hLib.
END CONSTRUCTOR.
METHOD PUBLIC INTEGER doFunc(INPUT ip-num as INTEGER):
RETURN foo(ip-num).
END METHOD.
END CLASS.
The problem is I get this error:
** Unable to understand after -- "foo". (247)
if I try "RETURN foo(ip-num) in hLib", I get this:
** Unable to understand after -- "ip-num)". (247)
if I try "RETURN foo in hLib (ip-num)", I get this again:
** Unable to understand after -- "foo". (247)
How do I do this?
|
You need to declare the function locally within the class. Like this:
FUNCTION foo RETURNS INTEGER IN hLib.
This does not have the body of the function. It just tells the compiler about it. This has to be above the call to foo(). In a Class this has to be outside any method. Put it at the top - under the declaration of hLib.
|
And, since you have your answer, let me throw in a piece of bonus advice ... which no doubt someone will argue with. My inclination is to avoid doing things in a constructor which might fail ... like RUN ... since they can leave you with a non-instantiated class to handle. Better, to my taste, is to do such things in an initialize method so that one already has a valid class reference and it can then be more obvious and cleaner to handle possible errors.
|
Providing error handling on a method invocation is natural, but doing so on a new is odd.
Thank you for all your replies. Since I initially wrote this I decided to put these functions into a new CLASS as STATIC methods.
The methods will allow me to take advantage of some newer features such as void return type (without making a PROCEDURE) and function overloading.
I'll keep this in mind if it ever comes up in the future.