Jump to content

Several User and Bug


Recommended Posts

  • Administrators


I run the server program. Each user has their own login and password.

But when they work at the same time, they can see each other's data. Why? And how to fix it?


Please give more details. How they can "see" each other's data? Where your data is stored? Which data aware components are you using? Where your data components is placed?

Link to comment
Share on other sites

I'm in the main form of writing:

if (uniEditlogin.Text ="Client1") and (uniEditPass="pass1") then



if (uniEditlogin.Text ="Client2") and (uniEditPass="pass2") then



if (uniEditlogin.Text ="Client3") and (uniEditPass="pass3") then



In another form, there is a DBGrid and a Button that saves data from the DBGrid in *.txt. For Example, the Client saves the data in a (PCName+"\data1.txt"). Client2 saves the data in a (PCName+"\data1.txt") , etc..

But if Client1 reviews the data (loads them in the form of (PCName+"\data1.txt")) he sees the contents of Client2.

Link to comment
Share on other sites

All data that needs to be unique to a particular user session needs to be instanced for that session. The easiest way to accomplish this is to put variables that need to be unique for a particular user inside the Main module (UniMainModule). UniMainModule is instanced once for each user that logs on and only that user can see the data in his UniMainModule.


In your case you could make PCName a public field in UniMainModule.

Link to comment
Share on other sites

  • Administrators

What is the relationship between the order in which the module declares a variable? Why in the UniMainModule?


You can declare PCName in MainForm or any other Form as well, but never use a global variable. A global variable has only one instance and it is overwritten when a user assigns a new value.

Link to comment
Share on other sites

You should think of an unigui application as a multithreaded program. Each users session is a thread in one single program and just like in a multithreaded application, global variables are shared between threads.


When a user launches a session in a browser, your application is not completely cloned. There is only one physical version of your application running at all times. Each user just has a bit of reserved space inside your application that he has access to. That reserved space is the main form, the main module and all application forms that you launch subsequently. Each user gets his own fresh version of these forms when he starts a new session. Pretty much everything else is shared, unless you specifically instantiate it for a that user.




unit Main;


 Windows, Messages, SysUtils, Variants, Classes, Graphics,
 Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
 uniGUIClasses, uniGUIForm;

 TMainForm = class(TUniForm)
   { Private declarations }
   UserLocalString: string; // Each session has its own main form
                            // so each user can only see and change
                            // his own UserLocalString field.

function MainForm: TMainForm;

 MyGlobalString: string;  // This is a typical per unit global
                          // All users will see the same string.
                          // If one user changes it, it changes
                          // for all users.  


{$R *.dfm}

 uniGUIVars, MainModule;

function MainForm: TMainForm;
 Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));




By the way, strings are not thread safe, so should never be shared between threads without proper locking mechanisms in place the make sure only one thread can access it at a time.

  • Upvote 1
Link to comment
Share on other sites

A side note:


Notice the difference between the unigui version of the Main form reference:


function MainForm: TMainForm;


Here is the regular VCL version:


 Form1: TForm1;


The unigui MainForm function is there to make sure the user gets his own main form and not some other users form.


If the VCL version was used, there could only every be one main form on the entire server. So when a new user logged on, the previous user would have his main form replaced with the new users main form. That would not work very well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...