Jump to content

Datamodule is destroyed without ending session time


Pablo

Recommended Posts

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

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

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

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

  • Administrators
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

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

  • Administrators
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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...