rpnfan
14th December 2004 17:04 UTC
function does not work in section? (ReplaceOnLine)
I want to use some of the sample scripts/functions and tried to use the function ReplaceOnLine to change text in a specific line of a text file. But when I try that I get the following error message:
Call "ReplaceOnLine"
Error: command Function not valid in section
Error in macro ReplaceOnLine on macroline 7
Error in script "F:\Programme\NSIS\Examples\mini.nsi" on line 113 -- aborting creation process
I have created a mini example (see attached files) to show the problem.
Short overlook:
1) definition of the function (padded in a macro for easier usage)
2) using the function in a section
results in the error message above
Looking forward for any pointers. I guess I'm using the function wrong, but don't have a clue what goes wrong. Other functions show the same problem.
Best regards
Peter
Comm@nder21
14th December 2004 17:38 UTC
exclude the Function ReplaceOnLine from your macro.
rpnfan
14th December 2004 21:36 UTC
Thank you very much for your answer. That was an easy error - "Wald vor lauter Bäumen und so..." ;-)
Then my next question arises: What's the difference between a macro and a user function? When should I use which type?
Thank you for your help.
Grüße
Peter
Afrow UK
15th December 2004 11:20 UTC
A Function is like a routine or procedure that you can call multiple times. The Function code is only stored in your install once.
A macro is compile-time. It can contain anything from run-time commands (like StrCpy) to compile-time commands (like !define) When you insert a macro using !insertmacro, it simply creates a copy of the code in your macro and places it where you have inserted the macro. This allows us to insert multiple copies of complicated code with a few lines of !insermacro.
E.g.
!macro StrCpy Var
StrCpy ${Var} "blah"
!macroend
Function UseBlah
!insermacro StrCpy $R0
!insermacro StrCpy $R1
FunctionEnd
Would be the same as:
Function UseBlah
StrCpy $R0 "blah"
StrCpy $R1 "blah"
FunctionEnd
-Stu