Announcement

Collapse
No announcement yet.

Who am I? Sub, Function, Method, Property

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    I am still trying to figure out why I'd even care if FUNCNAME$ was a sub or function or method
    But FWIW, when I was debugging Generic 'ADO' Connection and Query Tester (CC 5+/Win 9+) 11-02-08 , I would just pass "Method <methodname> " or "Property <propertyname>" to a 'common' error handler, and the error log I was creating then included that literal.

    No reason you could not set up something like ..

    Code:
    FUNCTION | SUB  foo... 
      LOCAL dProcTypeName AS STRING 
      dProcTypeName  = " FUNCTION|SUB|METHOD|PROPERTY  "  + FUNCNAME$ 
    
      ....
      code here 
     .. oops need error
      CALL FooError (dProcTypeName, other params) 
    
    ...
    If Funcname$ does in fact return the name of the current method or property , you could do the same kind of thing.

    That is, any procedure receiving FUNCNAME$ would be able to distinguish the "source type" in its own code.



    MCM

    Leave a comment:


  • Michael Mattias
    replied
    >what about using a prefix when you name your SUB or FUNCTION..
    >You can even use:
    >"FL_" (for LONG...

    Why not go whole hog, and suffix "@" plus the size on the stack of the parameters, like a bunch of c compilers do when EXPORTing...

    Other than I don't think "@" is allowed in a procedure name, but I'm sure there's a workaround for that.

    (This is not a serious proposal. I am still trying to figure out why I'd even care if FUNCNAME$ was a sub or function or method.... if I can't find a procedure/method name in my source code when debugging I have bigger problems).

    Leave a comment:


  • Patrice Terrier
    replied
    what about using a prefix when you name your SUB or FUNCTION

    SUB MySubroutine ALIAS "S_MySubroutine" ()

    FUNCTION MyFunction ALIAS "F_MyFunction" ()

    You can even use:
    "FL_" (for LONG)
    "FD_" (for DOUBLE)
    "FS_" (for SINGLE)
    "FI_" (for INTEGER)
    "FW_" (for WORD)
    "FDW_" (for DOUBLEWORD)
    etc.

    ...

    Leave a comment:


  • Walt Thompson
    replied
    Hi Cliff;

    The description of FUNCNAME$ suggests that it wiil return the the name of the current Sub/Function/Method/Property:

    FUNCNAME$ function
    Purpose
    Return the name of the current Sub/Function/Method/Property.

    Syntax
    f$ = FUNCNAME$

    Remarks
    FUNCNAME$ returns the name of the procedure in which it is located. If an is specified, FUNCNAME$ returns the ALIAS name; otherwise, it returns the primary name capitalized. Returning the ALIAS name provides a mechanism to disguise sensitive internal procedure names even when reporting error conditions to a user.

    FUNCNAME$ can be useful as a debugging tool, or in situations where an error handler in a procedure passes error information on to a "central" procedure for logging and handling. FUNCNAME$ does not require #TOOLS ON.

    See also
    #TOOLS, CALLSTK, CALLSTK$, CALLSTKCOUNT, FILENAME$, FUNCTION, METHOD, PROFILE, PROPERTY, SUB, TRACE

    Example
    SUB SecretEncryptionSub ALIAS "MySub" (sData$)

    x$ = FUNCNAME$ ' Returns "MySub"

    END SUB

    ...

    SUB SecretDecryptionSub (sData$)

    x$ = FUNCNAME$ ' Returns "SECRETDECRYPTIONSUB"

    END SUB

    Leave a comment:


  • Michael Mattias
    replied
    I know there is no way to tell the difference between a SUB and a FUNCTION.

    In subject sample, it's "MyFunction".

    Don't know about methods and properties. What did FUNCNAME$() return when you tried it from a METHOD or PROPERTY call?

    MCM

    Leave a comment:


  • Cliff Nichols
    started a topic Who am I? Sub, Function, Method, Property

    Who am I? Sub, Function, Method, Property

    I know I can use FUNCNAME$ and a myriad of other things like callstack. But is there a way for my code to know that the code that is currently running is in a Sub? Function? Method? Property?

    Any PB or API way to do it? or will I need to set some sort of flag to indicate what it is running in?

    Sort of like
    Code:
    Function MyFunction() As Long
         Local CodeType As Whatever
         CodeType = DetermineCodeType(FUNCNAME$)     '<--- Returns value indicating if Sub/Function/Method/Property
    End Function
    Probably I will have to use a flag, but thought I would ask
Working...
X