Before:
Code: Select all
NewList MyList.i()
AddElement(MyList())
MyList()=123456
Code: Select all
NewList MyList.i()
AddElement(MyList(),123456)
Code: Select all
NewList MyList.i()
AddElement(MyList())
MyList()=123456
Code: Select all
NewList MyList.i()
AddElement(MyList(),123456)
Code: Select all
Macro AddInteger(_lst_,_int_)
AddElement(_lst_):_lst_ = _int_
EndMacro
Code: Select all
Procedure.i AddInteger(List MyList(),Value.i)
If AddElement(MyList())
MyList() = Value
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Code: Select all
AddElement(MyList(), 1)
AddElement(MyList(), 2)
AddElement(MyList(), 3)
; simplifies to
AddElement(MyList(), 1, 2, 3)
Code: Select all
AddElement(MyList()) : MyList() = ""
Can you explain why this is unsafe. Because I'm using such macro for the last 10 years at least without any problem at all.Mijikai wrote: ↑Thu Aug 04, 2022 4:04 pm Hmm...
Unsafe Macro (dont do this!):Code: Select all
Macro AddInteger(_lst_,_int_) AddElement(_lst_):_lst_ = _int_ EndMacro
What about compiling a Resident file with your macros ?jacdelad wrote: ↑Thu Aug 04, 2022 5:33 pm @STARGATE: Sure, but it is often used in loops where it is called only once.
I have no problem with using macros and such, but I find it a bit annoying to always include them at the beginning of a code and not having them autoinserted when they are placed in a certain folder or file (this was discussed somewhere else too).
I don't know how that works. Is there a good introduction other than the helpfile?StarBootics wrote: ↑Thu Aug 04, 2022 5:58 pmWhat about compiling a Resident file with your macros ?jacdelad wrote: ↑Thu Aug 04, 2022 5:33 pm @STARGATE: Sure, but it is often used in loops where it is called only once.
I have no problem with using macros and such, but I find it a bit annoying to always include them at the beginning of a code and not having them autoinserted when they are placed in a certain folder or file (this was discussed somewhere else too).
Best regards
StarBootics
Code: Select all
;Procedure to add a string to a linked string list ... example without error checking
Procedure ListAdd( List temp$(), value$)
AddElement( temp$() )
temp$() = value$
endprocedure
Will this be optimized to run in a loop? You increase the number of events. If you make it a macro, then it will be expanded during compilation, without adding extra events.DeanH wrote: ↑Mon Aug 08, 2022 3:38 amCode: Select all
;Procedure to add a string to a linked string list ... example without error checking Procedure ListAdd( List temp$(), value$) AddElement( temp$() ) temp$() = value$ endprocedure
This is some kind of permanent include file. (took from here)
Code: Select all
IncludePath #PB_Compiler_Home+"Include\"
XIncludeFile "File1.pb"
XIncludeFile "File2.pb"