Referencing controls from Globals.ps1 or Startup.pss

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
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.
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
gkhairallah
Posts: 44
Last visit: Thu Jun 15, 2023 12:55 pm
Has voted: 2 times

Referencing controls from Globals.ps1 or Startup.pss

Post by gkhairallah »

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!
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Referencing controls from Globals.ps1 or Startup.pss

Post by brittneyr »

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/
Brittney
SAPIEN Technologies, Inc.
User avatar
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

Post by gkhairallah »

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!
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.