Volk65 Posted February 14, 2019 Share Posted February 14, 2019 Is it possible to use a global variable declared as: threadvar SomeVar: ISomeInterface; From the description of Delphi it follows that for each thread the value will be different. Will it work in UniGui? Quote Link to comment Share on other sites More sharing options...
Mohammed Nasman Posted February 14, 2019 Share Posted February 14, 2019 Would like global variable per session or per server? I prefer to define your global variable as public member inside TMainModule Quote Link to comment Share on other sites More sharing options...
Volk65 Posted February 14, 2019 Author Share Posted February 14, 2019 I need a (thread)variable for each session. Now I have a variable in the MainModule. But I need to take it outside the project in common for all projects units. Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted February 15, 2019 Share Posted February 15, 2019 Hi, type T_FRM_ = class(TUniForm) ... private FMNU_Item: TUniMenuItem; .... published property MNU_Item: TUniMenuItem read FMNU_Item write FMNU_Item; FMNU_Item is form's variable and private, but access from other units. Ofcourse haveto add unit name to uses. Quote Link to comment Share on other sites More sharing options...
Volk65 Posted February 15, 2019 Author Share Posted February 15, 2019 As an instance of form where to store? In the global variable? in another form? I want to get away from storing a variable in MainForm. To create an instance of a class I need to store it somewhere but not in the form of a project. That's why I want to use ThreadVar. I need an answer to the question: Is it possible to use a global variable declared as Threadvar (so that each session sees its own variable) ? Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted February 15, 2019 Administrators Share Posted February 15, 2019 A Threadvar is bound to a specific thread, but not to a specific session. Each session can be served by different threads. There is no warranty that a session events will always be served by same thread. Quote Link to comment Share on other sites More sharing options...
Volk65 Posted February 15, 2019 Author Share Posted February 15, 2019 Thanks! that's what I wanted to hear. You can (in the future) create a custom property in the session object: "UserObj: TObject" (or something) that can be assigned by the developer. For example, as the Tag property. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted February 17, 2019 Share Posted February 17, 2019 @Volk65 Global variable per session. Here is my kitchen : Create an UniDataModule specially dedicated to these variables. for example name it Tmp (a temporary Unit) : unit Tmp; interface uses SysUtils, Classes; type TDM_tmp = class(TDataModule) //********* private // variables shared by all units example : // Periode fD1:TDate; fD2:TDate; // Printing fPrintLine:boolean; // somme set errors ferror:boolean; etc... //********* published // Periode property D1:TDate read fD1 write fD1; property D2:TDate read fD2 write fD2; // Printing property PrintLine:boolean read fPrintLine write fPrintLine; // somme set errors property error:boolean read ferror write ferror; end; function DM_tmp: TDM_tmp; implementation {$R *.dfm} uses UniGUIVars, uniGUIMainModule, MainModule; function DM_tmp: TDM_tmp; begin Result := TDM_tmp(UniMainModule.GetModuleInstance(TDM_tmp)); end; initialization RegisterModuleClass(TDM_tmp); end. And after, on your others Units, you can get them or set them like : tmp.DM_tmp.D1 :=dtpMyDateN.dateTime; if tmp.DM_tmp.error then .... if tmp.DM_tmp.PrintLine then... It is important to use properties to never have overlap variables on different sessions see : http://www.unigui.com/doc/online_help/general-design-concept.htm Regards. 1 Quote Link to comment Share on other sites More sharing options...
Volk65 Posted February 17, 2019 Author Share Posted February 17, 2019 Yeah, that's a good option. A few tweaks to get rid of the dependency in uses on a particular project. Be so: uses UniGUIVars, uniGUIMainModule, MainModule; function DM_tmp: TDM_tmp; begin Result := TDM_tmp(UniMainModule.GetModuleInstance(TDM_tmp)); end; Become so: uses UniGUIVars, uniGUIApplication; function DataModule1: TDataModule1; begin Result := TDM_tmp(UniApplication.UniMainModule.GetModuleInstance(TDM_tmp)); end; Thanks for the idea. 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.