Announcement

Collapse
No announcement yet.

macro

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

  • Kev Peel
    replied
    Different strokes for Wisconsin folks, I guess!

    Leave a comment:


  • Michael Mattias
    replied
    Also, I use the equate method in case you want to use a certain function in a DLL but not export it. The exports are defined per-#include file using an equate for each.
    Whoa, that's way too complex for a kid from the South Side of Milwaukee. This kid, anyway.

    Easier to just type it twice, ainna?


    MCM

    Leave a comment:


  • Kev Peel
    replied
    The downside to that approach is that you need two declarations for each function as I mentioned. Also, I use the equate method in case you want to use a certain function in a DLL but not export it. The exports are defined per-#include file using an equate for each.

    Leave a comment:


  • Michael Mattias
    replied
    Not directly on macro, but for the Export/No Export thing, I do that depending if I am compiling to an EXE or DLL, and the compiler supplies the equate...

    Code:
    #IF %PB_EXE
      FUNCTION TSEDI_MakeIEASegment(XC AS INTERCHANGETYPE) AS STRING
    #ELSE
      FUNCTION TSEDI_MakeIEASegment ALIAS "TSEDI_MakeIEASegment" (XC AS INTERCHANGETYPE) EXPORT AS STRING
    #ENDIF
    MCM

    Leave a comment:


  • Kev Peel
    replied
    Yes, it would be handy for many uses to cut down code size. That was just a snippet but you get the general idea.

    Another thing I toyed with (this time with success) was to get functions EXPORTed depending on a flag and without having to make the declaraton twice in an #IF / #ENDIF block.

    This is one demonstration which shows the usefulness of MACRO text substitution:

    Code:
    #If %Def(%EXPORTED)
        Macro FUNC_MODE(r) = Export As r
    #Else
        Macro FUNC_MODE(r) = As r
    #EndIf
     
    FUNCTION Abc FUNC_MODE(LONG)
    END FUNCTION

    Leave a comment:


  • Michael Mattias
    replied
    My sort example creates the 'actual' variable name from the UDT variable name plus "." plus the member name.

    Your demo code .. passing "var" and "num" as arguments one and . should be producing "var_num = 10" which is a perfectly valid statement. But somehow I don't think it's what you wanted.

    One thing you have to watch out for when concatenating .. spaces are significant. I remember dinking around a lot with the spaces to get that to work correctly.

    I'll take a pass on commenting about the utility of using a MACRO to make a simple assignment like this; but I'm sure this example is not a complete statement of the challenge since it would be totally silly to bother with a MACRO for a simple assignment statement.





    MCM

    Leave a comment:


  • Kev Peel
    replied
    I read your code. That's member names not variable names, which is what I was talking about. AFAIK, it's simply not possible to concatenate one or more MACRO substitutions to reference an actual variable. If you have code to do this, please show it.

    Demonstration code:

    Code:
    #Compile Exe
     
    Macro VAR_ASSIGN(var, num, value)
      var_num = value
    End Macro
     
    Function PBMain
      Local var_1 As Long
      Local var_2 As Long
      Local var_3 As Long
      VAR_ASSIGN(var, num, 10)
    End Function

    Leave a comment:


  • Michael Mattias
    replied
    MACROs are not "evaluated" at all; they are simple text substitution at compile time.

    If the resulting text is compilable it compiles; otherwise it returns an error.

    >I don't think partial name uses are permitted with MACROs

    I do...
    CC3/Win7: ARRAY SORT UDT array on member name September 04, 2002

    ....because this uses text substitution to complete partial variable names.

    MCM

    Leave a comment:


  • Chris Holbrook
    replied
    I see. So it's evaluation followed by text substitution.

    In this case, I want to use the % in the condition but not in the label. Can't see a way around it.

    Leave a comment:


  • Kev Peel
    replied
    PB is translating %A and %B literally, so it expects to have those constants defined. The working code should look like this:

    Code:
    MACRO mjump(a,b)=IF (lControlId=a) AND (lmsg=b) THEN GOSUB a_b
     
    [..]
     
    mjump(%IDOK,%WM_COMMAND)
    ...that way you can also use variable names (or numeric values) for the mjump() parameters.

    I don't think partial name uses are permitted with MACROs.

    Leave a comment:


  • Chris Holbrook
    started a topic macro

    macro

    I'm posting this here assuming that macro expansion is common to PBWin & PBCC. Any problems - sue me.

    Just out of curiosity I tried this macro which fails because parameter substitution does not occur:

    Code:
    '------------------------------------------------------------------
    ' Are macros expanded before or after .inc files are included?
    #IF NOT %DEF(%WM_COMMAND)
        %WM_COMMAND=&H111
    #ENDIF
    MACRO mjump(a,b)=IF (lControlId=%a) AND (lmsg=%b) THEN GOSUB a_b
    '------------------------------------------------------------------
    I'm expecting it to expand mjump(IDC_BN1,WM_COMMAND) to:
    Code:
        IF (lControlId=%IDC_BN1) AND (lmsg=%WM_COMMAND) THEN GOSUB IDC_BN1_WM_COMMAND
    instead this happens:
    Code:
    Error 460 in C:\chris\mcodegen\event_code_dispatcher.bas(92:009):  Undefined equate
    Line 92:         mjump(IDOK,WMCOMMAND)
    Macro Expansion(16):  IF (LCONTROLID=%A) AND (LMSG=%B) THEN GOSUB A_B
    ==============================
    Compile failed at 23:37:22 on 15/01/2008
    Clearly I'm missing something!
Working...
X