donlego Posted August 9, 2018 Share Posted August 9, 2018 is it safe for the user session if put a variable in the unimainmodulelike this Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted August 9, 2018 Administrators Share Posted August 9, 2018 is it safe for the user session if put a variable in the unimainmodule like this If they are constants (Readonly), yes it is safe. Link to comment Share on other sites More sharing options...
Wicket Posted August 9, 2018 Share Posted August 9, 2018 Edit - didn't see farshads post Link to comment Share on other sites More sharing options...
donlego Posted August 9, 2018 Author Share Posted August 9, 2018 its read and write variable , so which place i put for diffrent user session for beter Link to comment Share on other sites More sharing options...
Oliver Morsch Posted August 9, 2018 Share Posted August 9, 2018 Make a Field / Property in TUniMainModule class. 1 Link to comment Share on other sites More sharing options...
donlego Posted August 9, 2018 Author Share Posted August 9, 2018 like this ? Link to comment Share on other sites More sharing options...
Oliver Morsch Posted August 9, 2018 Share Posted August 9, 2018 Yes. Link to comment Share on other sites More sharing options...
donlego Posted August 9, 2018 Author Share Posted August 9, 2018 ok thanks all i will try it Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted August 3, 2021 Share Posted August 3, 2021 I have found this thread and don't understand the problem. I know that for each session a TuniMainModule instance is created. So if i create some variables in the unimainmodule, isn't it safe to read /write these variables ? example TUniMainModule = class(TUniGUIMainModule) private { Private declarations } Fthevar:integer; published property thevar:integer read Fthevar write Fthevar; ... If somewhere in the app the code below is execute UniMainModule.thevar:=newvalue; Isn't it safe ? thanks Link to comment Share on other sites More sharing options...
Abaksoft Posted August 3, 2021 Share Posted August 3, 2021 28 minutes ago, Roberto Nicchi said: I have found this thread and don't understand the problem. I know that for each session a TuniMainModule instance is created. So if i create some variables in the unimainmodule, isn't it safe to read /write these variables ? example TUniMainModule = class(TUniGUIMainModule) private { Private declarations } Fthevar:integer; published property thevar:integer read Fthevar write Fthevar; ... If somewhere in the app the code below is execute UniMainModule.thevar:=newvalue; Isn't it safe ? thanks Hello, Your Code is Safe. There is no problem when using properties. in your example, thevar is visible for only the current session. (Read / Write) = No problem. Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted August 3, 2021 Share Posted August 3, 2021 3 minutes ago, Abaksoft said: Hello, Your Code is Safe. There is no problem when using properties. in your example, thevar is visible for only the current session. (Read / Write) = No problem. If i had created the variable as public and didn't use the property, it wasn't correct ? thanks a lot. Link to comment Share on other sites More sharing options...
Abaksoft Posted August 3, 2021 Share Posted August 3, 2021 2 hours ago, Roberto Nicchi said: If i had created the variable as public and didn't use the property, it wasn't correct ? thanks a lot. As public (without property) = Not Safe ! You can read this from Online Documentation : "For example, one could define TUserInfo as a global variable in MainModule: unit MainModule; interface ... var UserInfo: TUserInfo; And access it in MainForm: procedure TMainForm.UniFormCreate(Sender: TObject); begin UniLabel1.Caption := UserInfo.Name + ' ' + UserInfo.Surname; end; Above code actually works during initial tests because, as long as there is only one active session, UserInfo will not be shared, and the application seems to behave correctly! However, as soon as multiple sessions logs in, the application starts to behave in a strange way." From : http://www.unigui.com/doc/online_help/index.html?general-design-concept.htm I never use public variable. Always properties to share variables beween Forms /Frames (on the current session). And to do best, i create a dedicated UniDataModule, only to put shared properties. http://forums.unigui.com/index.php?/topic/11974-global-variable/&do=findComment&comment=63879 Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted August 3, 2021 Share Posted August 3, 2021 1 hour ago, Abaksoft said: As public (without property) = Not Safe ! You can read this from Online Documentation : "For example, one could define TUserInfo as a global variable in MainModule: unit MainModule; interface ... var UserInfo: TUserInfo; And access it in MainForm: procedure TMainForm.UniFormCreate(Sender: TObject); begin UniLabel1.Caption := UserInfo.Name + ' ' + UserInfo.Surname; end; Above code actually works during initial tests because, as long as there is only one active session, UserInfo will not be shared, and the application seems to behave correctly! However, as soon as multiple sessions logs in, the application starts to behave in a strange way." From : http://www.unigui.com/doc/online_help/index.html?general-design-concept.htm I never use public variable. Always properties to share variables beween Forms /Frames (on the current session). And to do best, i create a dedicated UniDataModule, only to put shared properties. http://forums.unigui.com/index.php?/topic/11974-global-variable/&do=findComment&comment=63879 In the example i see that the variable UserInfo is created inside the unit but OUTSIDE the class definition. That way for sure can't work in a UNIGUI application because the variable is common to all session. But creating the variables (public) inside the mainmodule should be in my mind the same than using a property and a private variable. Probably there's a tecnical thing that i miss. Anyway i'll do as suggested and use properties. I guess it works also if the variable is a complex object. For example if i need a Tstringlist. The only thing i have to do more is create it in the oncreate event of the unimainmodule. TUniMainModule = class(TUniGUIMainModule) private { Private declarations } Fsl:TStringList; published property sl:TStringList read Fsl write Fsl; ... thanks Link to comment Share on other sites More sharing options...
irigsoft Posted August 30, 2021 Share Posted August 30, 2021 Hello, can anyone tell me how to use a variable in unimainmodule like TuniTreeView using property? Same as TStringList? Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now