How to get instantiating procedure of class

Posted by Blake Stanford on 12-Sep-2017 09:13

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.

All Replies

Posted by Mike Fechner on 12-Sep-2017 09:17

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.

Posted by Tim Kuehn on 12-Sep-2017 09:20

Why do you need this information?

Posted by Blake Stanford on 12-Sep-2017 09:28

I'll look into it, I need it for a call back.

Posted by Laura Stern on 12-Sep-2017 10:00

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.  

Posted by Blake Stanford on 12-Sep-2017 10:03

Yes, I've come to that conclusion.  Thanks everyone.

Posted by Torben on 12-Sep-2017 10:30

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.

Posted by marian.edu on 12-Sep-2017 10:40

Forget about callbacks and just use events ;) 


Marian Edu

Acorn IT 
+40 740 036 212

Posted by marian.edu on 12-Sep-2017 10:46

Well said Laura, that begs the question… what is the etiquette there, why was that even added in the first place? 


Time for a @deprecated annotation maybe? :)
 
Marian Edu

Acorn IT 
+40 740 036 212

Posted by Mike Fechner on 12-Sep-2017 10:50

I am sure Gilles could implement a SonarSource rule overnight ... Disallow SOURCE-PROCEDURE in Classes.

Sent from Nine

Von: "marian.edu" <bounce-marianedu@community.progress.com>
Gesendet: 12.09.2017 17:47
An: TU.OE.General@community.progress.com
Betreff: RE: [Technical Users - OE General] How to get instantiating procedure of class

Update from Progress Community
marian.edu

Well said Laura, that begs the question… what is the etiquette there, why was that even added in the first place? 


Time for a @deprecated annotation maybe? :)
 
Marian Edu

Acorn IT 
+40 740 036 212

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

Posted by Laura Stern on 12-Sep-2017 12:40

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.

Posted by marian.edu on 12-Sep-2017 13:02

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? :)


Marian Edu

Acorn IT 
+40 740 036 212

Posted by cverbiest on 30-Aug-2018 04:17

FYI a Sonarqube rssw-oe-main:source_procedure rule exists now and it links back to this discussion

This thread is closed