Page 1 of 1

Multiple Forrm project

Posted: Thu Feb 09, 2012 6:50 am
by bmclain
I've just now gotten started with using a project instead of just a file. I'm having issues figuring out the order of how it all flows together. My main issue right now is that I created a help form separate from my main form. I can't seem to perform the Call-Help_Dialog_pff to be defined before I call it. I try to call the form from the Globals.ps1 file, but it doesn't appear to be defined yet. At what point is this defined/how can I make sure that it's defined before I call it?Is there any doc to describe how primalforms will flow through the Startup.pfs, Globals.ps1, and the defined forms?

Multiple Forrm project

Posted: Thu Feb 09, 2012 7:44 am
by davidc
The Startup's Main Function is considered the entry point.You should never call a form directly from Globals.ps1 unless it is in a function that is called by another form or the Main function. Only use the Globals.ps1 to define variables or functions. I don't recommend to using it to execute scripts directly. If you like a better idea what is happening behind the scenes I recommend exporting the project into a ps1. You will see the files are combined into a larger script. Essentially the contents of the Global.ps1 are appended to a larger script and if you try to call a form, it is possible that the form's function has not been defined until later in the script. David

Multiple Forrm project

Posted: Tue Feb 14, 2012 3:12 am
by kghammonddc
I like this thread...

A few programming style questions.

1) We have been putting our functions in the mainform.pff. Could we place them in global.ps1 instead or is the scope different. I think it would be different. We totally missing startup.pfs. I assume functions / variables in startup.pfs will also be in a different scope that mainform.pff. Maybe that is better...

2) Is it possible to add parameters to the Main function for parameter passing from the command line, or do we have to manually parse them out of $Commandline or from $args?

Thank You,
Kevin

Multiple Forrm project

Posted: Tue Feb 14, 2012 5:27 am
by bmclain
Parameters should be defined in the Startup.pfs at the top. their packager will look for it there and make sure it's at the top of the script when it's compiled.Functions in Startup get put in first, then functions in the global. The it appears that the commands in global get executed. I find it difficult to see this in primalforms since the functions I put in other scripts don't show up as callable in the other scripts. So, I've essentially been putting all functions in startup.pfs and any commands in the Main function. that way it knows about the functions. I then just make sure that if the variable is needed outside of the main function that I set it to a script variable.

Multiple Forrm project

Posted: Tue Feb 14, 2012 5:28 am
by bmclain
Oh, and also you will find that the parameters are only valid if you export to a .ps1 file. If you need command line options you have to use the $commandline. Or if you have something that might be both (like mine), then you need to make sure to code for both.

Multiple Forrm project

Posted: Tue Feb 14, 2012 5:48 am
by davidc
1)
Yes
you can place the functions in the Global.ps1 file and they will be accessible
to any script in the project. The file is there for your convenience. 2) If you define a parameter block at beginning of the startup.pfs file, you will be prompted for the parameters when you run the script. If you are using a packaged exe and are passing parameters to the executable, then you will need to use either $args or $commandline. David