All,
I need to know from within a class what procedure instantiated it, similar to this-procedure:instantiating-procedure. Is there a way of doing this from within a class?
Thx.
There is no solution that does not smell buggy ... you can refer to the SOURCE-PROCEDURE handle in the constructor.
But if you need that for callback reasons, I'd rather pass the handle of the procedure to the Constructor.
Why do you need this information?
I'll look into it, I need it for a call back.
Using SOURCE-PROCEDURE from within a class is not really "sanctioned" behavior. It was never intended to work and the ability to do this may some day go away! As Mike said, you should have a method/property in the class that the caller can use to set the handle to the caller if that is necessary.
Yes, I've come to that conclusion. Thanks everyone.
You can maybe use call stack
METHOD PUBLIC STATIC CHARACTER GetCallStack():
DEFINE VARIABLE cCallStack AS CHARACTER NO-UNDO.
DEFINE VARIABLE orgStackTrace AS LOGICAL {&API-LOGICAL-FORMAT} NO-UNDO.
orgStackTrace = SESSION:ERROR-STACK-TRACE.
SESSION:ERROR-STACK-TRACE = TRUE.
UNDO, THROW NEW AppError("Throw to get error":U, 0).
CATCH e AS Progress.Lang.Error:
RETURN e:CallStack.
END CATCH.
FINALLY:
SESSION:ERROR-STACK-TRACE = orgStackTrace.
END FINALLY.
END METHOD.
Forget about callbacks and just use events ;)
Well said Laura, that begs the question… what is the etiquette there, why was that even added in the first place?
|
It was never "added". It is a non-intentional result of the implementation and it was an oversight that we did not disallow it when we introduced OO.
That is when used with OO but even in procedural the whole SOURCE-PROCEDURE thing is equally bad probably… the same rationale do apply just fine there as well, why do you care who is calling you? :)
FYI a Sonarqube rssw-oe-main:source_procedure rule exists now and it links back to this discussion