Archive: outsourcing functions to own "units" ?


outsourcing functions to own "units" ?
Hi!
is there any documentation about outsourcing my own functions to external "units"?
i would like to use some functions in different projects, so it would be nice to write them in one "unit" and include it to the different projects. possible? didn't find anything about that in this forum or help / readmes.


If you mean parts of code writen in NSIS then you can use .nsh -file (NSIS header file). Put your functions in it and add this file to your script with !include command.


yes, that's what i mean. sounds easy. i'll try.


today i continued to work on my script and i got a strange error, when i try to work with functions in external nsh files:

!include: closed: "C:\Programme\NSIS\Include\CustFunctions.nsh"

Processed 1 file, writing output:
Error: invalid script: never had OutFile command
Error - aborting creation process

...i copied a function from my mainscript and saved it in a nsh-file (included Function/FunctionEnd. - nothing else above or below). when i comment the line
!include "CustFunctions.nsh" and the function i copied is still in my mainscript everything works fine. But when i comment the function and activate the !include-line, i got that outfile-error.
my include line follows the !include "mui.nsh" - line.
What am i doing wrong? Anybody got an idea?


this should not work:

!include: closed: "C:\Programme\NSIS\Include\CustFunctions.nsh"


try this instead:
!include "C:\Programme\NSIS\Include\CustFunctions.nsh"


The call to the functions on the included file can be done as ordinary.

And review the documentation this is explained there.

regards.

Originally posted by rasermar
this should not work:
!include: closed: "C:\Programme\NSIS\Include\CustFunctions.nsh"


try this instead:
!include "C:\Programme\NSIS\Include\CustFunctions.nsh"


The call to the functions on the included file can be done as ordinary.

And review the documentation this is explained there.

regards.
rasermar, he copied that from the compiler window (it's compiler output) where it's closed his !include after reading it.

The error is there... You're missing the OutFile command.

-Stu

you got it afrow =) it's the error-message, not my sourcecode

but the error-message doesn't make any sense imho. i got the outfile command in my mainscript....and if i don't use that function of my nsh-file, but exactly the same of my mainscript, it works.

i am not sure, but i think it already worked with the outsourced code on last friday and i didn't change any code since that day. could it be caused by some changes in preferences or something like that? tomorrow i will look into it more exactly.


the out file command should be close to the beginning of the script.
any function should be after it i think.


well, i'm a bit confused, but now it works again. i just set the outfile-command to some different places. the order was var-lines, !include-lines, outfile-line. then i set the outfile-line above the !include-lines and compiled the script. i just got a few zeroing-code-warnings (why? no idea). then i saved both scripts and opened them again. suddenly they were working. after that i set the lines to their old positions and it still works...

sounds like a nsis-bug...but i'm not sure...maybe i overlooked something...

(sry, if my english is kinda bad - just overlook ;) )


i found out the cause of that problem. i try to subcribe. last week i tried to add another function (not that one i'm talkin about above) from my mainscript (there it was working correct) to my secondary-script. apparently i got an error (maybe the same) that day, deleted the function, added it back to my mainsript and stopped working. with the second function in the secondary-script i must have temporary made some chaos in nsis and nothing worked, though the function was in my main-script again. the second function is:

Function "FillLbl" ;keine Rückgabe
FindWindow $2 "#32770" "" $HWNDPARENT
GetDlgItem $2 $2 $1
CreateFont $3 "Arial" 8 0
SendMessage $2 ${WM_SETFONT} $3 0
SendMessage $2 ${WM_SETTEXT} 0 "STR:$0"
FunctionEnd

i think the exchange of the variables could be the problem....no idea...