Pablo Posted March 26, 2021 Share Posted March 26, 2021 Good morning, i am using unigui and normal vcl datamodule started as any unigui datamodule does, creation works correctly. I have global variables that are initialized with the datamodule and I use them to filter data from tables, the problem is that the destroy of the datamodule is executed without having finished the session, they release my global variables and when I try to use them they give me access violation. How can I solve this issue, I thank you in advance for your help Link to comment Share on other sites More sharing options...
Pep Posted March 26, 2021 Share Posted March 26, 2021 Hi Pablo, uniGUI Web application is heavily multithreaded, and multiple sessions execute in different threads, so must avoid global variables. For more information look in this chapter of developers manual: http://www.unigui.com/doc/online_help/general-design-concept.htm Extract: Quote At this point, it is good to mention that one should avoid using shared global objects in uniGUI. 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. http://www.unigui.com/resources/online-documentation/developer-manual Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted March 26, 2021 Administrators Share Posted March 26, 2021 VCL datamodules should not be used. You should use DMs created by uniGUI Wizard. Link to comment Share on other sites More sharing options...
Pablo Posted March 26, 2021 Author Share Posted March 26, 2021 Sorry I'm using datamodule type {%CLASSGROUP 'System.Classes.TPersistent'} I need an example of creating datamodule that ends along with the session, that does not make it the same unigui, please example Link to comment Share on other sites More sharing options...
DonaldShimoda Posted March 27, 2021 Share Posted March 27, 2021 4 hours ago, Farshad Mohajeri said: VCL datamodules should not be used. You should use DMs created by uniGUI Wizard. Farshad, i believe he want to control when a datamodule is created and when is destroyed, and need to create this when a new session start and destroy this when a session is closed. Not automamaged. Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted March 28, 2021 Administrators Share Posted March 28, 2021 On 3/27/2021 at 3:13 AM, DonaldShimoda said: Farshad, i believe he want to control when a datamodule is created and when is destroyed, and need to create this when a new session start and destroy this when a session is closed. Not automamaged. Datamodules are created and destroyed along with the session. Link to comment Share on other sites More sharing options...
Pablo Posted March 30, 2021 Author Share Posted March 30, 2021 On 3/28/2021 at 9:30 AM, Farshad Mohajeri said: Datamodules are created and destroyed along with the session. Hi Farshad, in my case it doesn't happen that way. I have a datamodule A that uses a datamodule B, are created when you start the session but during the session B is destroyed, I don't know why that happens, finally I get an access violation when trying to access a table. Is there a way to control the destruction of the datamodule? or know why one of them is destroyed? Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted March 30, 2021 Administrators Share Posted March 30, 2021 5 hours ago, Pablo said: Hi Farshad, in my case it doesn't happen that way. I have a datamodule A that uses a datamodule B, are created when you start the session but during the session B is destroyed, I don't know why that happens, finally I get an access violation when trying to access a table. Is there a way to control the destruction of the datamodule? or know why one of them is destroyed? Hi Pablo, Are these Datamodules created using uniGUI wizard? Link to comment Share on other sites More sharing options...
Pablo Posted March 31, 2021 Author Share Posted March 31, 2021 15 hours ago, Farshad Mohajeri said: Hi Pablo, Are these Datamodules created using uniGUI wizard? Hi Farshad, I am reusing datamodules that were created in other projects and using directives to create them in my unigui project, example {$IFDEF UNIGUI} function DataModule1: TDataModule1; {$ELSE} for other applications {$ENDIF} {$IFDEF UNIGUI} initialization RegisterModuleClass(TDataModule1); {$ENDIF} because I need to reuse what I already have an not duplicate it. What is the solution to the questions asked above? Link to comment Share on other sites More sharing options...
DonaldShimoda Posted April 1, 2021 Share Posted April 1, 2021 9 hours ago, Pablo said: Hi Farshad, I am reusing datamodules that were created in other projects and using directives to create them in my unigui project, example {$IFDEF UNIGUI} function DataModule1: TDataModule1; {$ELSE} for other applications {$ENDIF} {$IFDEF UNIGUI} initialization RegisterModuleClass(TDataModule1); {$ENDIF} because I need to reuse what I already have an not duplicate it. What is the solution to the questions asked above? So, seems the same code the unigui datamodule produce... weird. Maybe as datatables in A use datatables in B Unigui don´t see closing b will be a problem... Again i believe the better solution is to create and destroy your datamodules BY HAND on every init and destroy session. Im sur Farjad will explain how to do this manually, not automatic. Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted April 1, 2021 Administrators Share Posted April 1, 2021 Hello I attached a simple project. Project1x.zip Link to comment Share on other sites More sharing options...
Pablo Posted April 1, 2021 Author Share Posted April 1, 2021 55 minutes ago, Farshad Mohajeri said: Hello I attached a simple project. Project1x.zipUnavailable Hi Farshad, the zip file Is not available. Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted April 1, 2021 Administrators Share Posted April 1, 2021 1 hour ago, Pablo said: Hi Farshad, the zip file Is not available. It is only available to subscribers. 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