donlego Posted August 9, 2018 Posted August 9, 2018 is it safe for the user session if put a variable in the unimainmodulelike this Quote
Administrators Farshad Mohajeri Posted August 9, 2018 Administrators 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. Quote
donlego Posted August 9, 2018 Author Posted August 9, 2018 its read and write variable , so which place i put for diffrent user session for beter Quote
Oliver Morsch Posted August 9, 2018 Posted August 9, 2018 Make a Field / Property in TUniMainModule class. 1 Quote
Roberto Nicchi Posted August 3, 2021 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 Quote
Abaksoft Posted August 3, 2021 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. Quote
Roberto Nicchi Posted August 3, 2021 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. Quote
Abaksoft Posted August 3, 2021 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 Quote
Roberto Nicchi Posted August 3, 2021 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 Quote
irigsoft Posted August 30, 2021 Posted August 30, 2021 Hello, can anyone tell me how to use a variable in unimainmodule like TuniTreeView using property? Same as TStringList? Quote
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.