
Announcement
Collapse
No announcement yet.
macro
Collapse
X
-
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.
Easier to just type it twice, ainna?
MCM
Leave a comment:
-
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:
-
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
Leave a comment:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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)
I don't think partial name uses are permitted with MACROs.
Leave a comment:
-
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 '------------------------------------------------------------------
Code:IF (lControlId=%IDC_BN1) AND (lmsg=%WM_COMMAND) THEN GOSUB IDC_BN1_WM_COMMAND
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
Tags: None
Leave a comment: