Hi, I have a newbie question:
Is it by design that I cannot auto-complete form controls (from a psf file) within the project, from within the Globals.ps1 or Startup.pss?
I know that those get merged on run, so theoretically, they should be able to see and reference the controls. I was hoping that I could use the auto-complete for controls/properties/methods from within those files.
I wanted to ask just in case there is something wrong with my IDE that I need to address.
Thanks!
Referencing controls from Globals.ps1 or Startup.pss
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- gkhairallah
- Posts: 44
- Last visit: Thu Jun 15, 2023 12:55 pm
- Has voted: 2 times
Re: Referencing controls from Globals.ps1 or Startup.pss
This is correct. You should not be able to directly reference form controls from Globals.ps1 or Startup.pss and this is because of the scope of the controls. Yes, at the when a project runs or is exported, all project files with a Build settings of Include will be combined into one script, but forms are merged into a function such as Show-MainForm_psf. All form related code exists in this function.
As a result, from Globals.ps1 or Startup.pss, the controls defined in a form do not exist because the controls themselves are only defined in that forms corresponding function. I recommend exporting your project to see how files are merged.
I also recommend reading the following blogs to better understand how scoping works:
https://www.sapien.com/blog/2015/09/09/ ... l-gui-app/
https://www.sapien.com/blog/2013/03/06/ ... ing-rules/
https://adamtheautomator.com/powershell-scopes/
As a result, from Globals.ps1 or Startup.pss, the controls defined in a form do not exist because the controls themselves are only defined in that forms corresponding function. I recommend exporting your project to see how files are merged.
I also recommend reading the following blogs to better understand how scoping works:
https://www.sapien.com/blog/2015/09/09/ ... l-gui-app/
https://www.sapien.com/blog/2013/03/06/ ... ing-rules/
https://adamtheautomator.com/powershell-scopes/
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- gkhairallah
- Posts: 44
- Last visit: Thu Jun 15, 2023 12:55 pm
- Has voted: 2 times
Re: Referencing controls from Globals.ps1 or Startup.pss
Thanks for the explanation Brittney. That makes sense, I just wanted to be 100% sure so that I don't end up unnecessarily torturing myself
Will take a look at the blog posts as well.
Cheers!
Will take a look at the blog posts as well.
Cheers!