fil Posted October 30, 2020 Share Posted October 30, 2020 Why is a globally declared variable in the Main Form publicly available for all sessions? I am declaring a variable in the main form. And this variable is publicly available for all sessions. It is not right. how to avoid this? I need a separate variable for each session. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted October 30, 2020 Share Posted October 30, 2020 Hi, You must declare it on MainSession and the variable will only be visible in this session Quote Link to comment Share on other sites More sharing options...
alfr Posted October 30, 2020 Share Posted October 30, 2020 Here are some more info how and where to declaring different types of variables http://www.unigui.com/doc/online_help/index.html?general-design-concept.htm and http://www.unigui.com/doc/online_help/handling-concurrency.htm Quote Link to comment Share on other sites More sharing options...
x11 Posted October 30, 2020 Share Posted October 30, 2020 9 hours ago, fil said: Why is a globally declared variable in the Main Form publicly available for all sessions? Not only in the main form. Probably in any form. And in the unimainmodule including. You need to declare global variables in the public section of the main module. Quote Link to comment Share on other sites More sharing options...
x11 Posted October 30, 2020 Share Posted October 30, 2020 3 hours ago, irigsoft said: You must declare it on MainSession and the variable will only be visible in this session what is mainsession? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted October 30, 2020 Share Posted October 30, 2020 13 minutes ago, x11 said: what is mainsession? Corect, MainModule. Sorry. Quote Link to comment Share on other sites More sharing options...
x11 Posted October 30, 2020 Share Posted October 30, 2020 2 minutes ago, irigsoft said: MainModule. in the public section of the main module 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted October 30, 2020 Share Posted October 30, 2020 10 hours ago, fil said: Why is a globally declared variable in the Main Form publicly available for all sessions? Quote When implementing the functionality of this form, it is important to remember that it can only use the ServerModule, DataModule, and any other temporary form using them, but not the MainForm. In fact, no form should ever access the MainForm, but the MainModule. Quote Link to comment Share on other sites More sharing options...
Frederick Posted November 1, 2020 Share Posted November 1, 2020 On 10/30/2020 at 9:57 AM, fil said: Why is a globally declared variable in the Main Form publicly available for all sessions? I am declaring a variable in the main form. And this variable is publicly available for all sessions. It is not right. how to avoid this? I need a separate variable for each session. How do I repeat this behaviour? I run two instances of the app in two tabs of the same browser or one instance each of the app in two different browsers and I am not seeing this. I declare a variable in the public section of the MainForm: public { Public declarations } cVar : String; and add a button in the MainForm to change the variable to something in the OnClick event: cVar:='Changed'; and show the variable in the MainForm's OnShow event: showmessage(cVar); After clicking the button in the first instance of the app, I run the second app but do not see the "Changed" message. -- Frederick (UniGUI Complete - Professional Edition 1.90.0.1539) Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted November 1, 2020 Share Posted November 1, 2020 On 10/30/2020 at 2:57 AM, fil said: Why is a globally declared variable in the Main Form publicly available for all sessions? Hello Fil, You will understand with these two examples atached Global_Variable_Bad_Practice.7z Global_Variable_Good_Practice.7z 2 Quote Link to comment Share on other sites More sharing options...
Frederick Posted November 1, 2020 Share Posted November 1, 2020 Thank you for the examples. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.