UniGUI’s forms and modules

Each uniGUI application is composed of a dedicated main form (MainForm) and two dedicated modules (MainModule) and a service module (ServerModule) and is automatically created. The login form (LoginForm) also has a special meaning in uniGUI. It is mainly used to complete the login transaction of the session user, which can be selected or added as appropriate.
he above mentioned are some of the main or indispensable forms and modules, which do not include the data modules (DataModules), pages (Frames) and forms (Form) created by users themselves according to their needs. The main categories are as follows:
1) Data Modules: Application Data Module, Free Data Module
2) Form (Form): Login Form (LoginForm), Main Form (MainForm), Application Form (Application Form), Free Form (Free Form)
3) Page (Frames)
PS: I will describe the above parts in detail in the relevant learning chapters later. Here is only one outline, so that everyone can understand it in general.
(1) Service module (ServerModule):
Every uniGUI application contains a service module named ServerModule, which is the core module of the application. It is singleton, which means that each application is created only once. It is mainly used to configure various server settings. The design interface is as follows:

(2) Main Module (MainModule):
The main module (MainModule) can be considered as the core of the session. It is a special-purpose module that is automatically created and added to the project every time a new project is created. MainModule has many important roles in uniGUI applications. Some of these roles are not visible to developers. The interface diagram during design is as follows:

For developers, MainModule can be used to place resources shared by the session, such as database connections, shared variables, etc. For example, you can declare public variables in the public section of MainModule and then access them from other forms in the session.
The following example demonstrates the common practice of sharing data between different forms in a session in uniGUI. Since each session has its private copy of MainModule, it will ensure that each form accesses its private data set in its session.
TUniMainModule = class(TUniGUIMainModule)
private
{ Private declarations }
public
{ Public declarations }
aUserName, aPassword: string;
end;
You can then access these variables from other forms in the application:
procedure TMainForm.UniButton1Click(Sender: TObject);
begin
UniLabel1.Caption :=UniMainModule.aUserName + ' ' + UniMainModule.aPassword;
end;
(3) Login form (LoginForm):
LoginForm is another special form type, used only for login purposes. If the application contains LoginForm (it inherits from the TUniLoginForm form class), it will generally be the first form displayed when the Web session is started. You can use the uniGUI wizard to create a LoginForm through the following path:
File->New->Other->Delphi->uniGUI for Delphi->Form
The main steps to create a LoginForm with uniGUI wizard are as follows:


This action will create a blank LoginForm, which looks the same as a regular form:

Developers can design the login interface according to their needs and implementation. For example, they can design the following picture (sample):

LoginForm is a descendant of a built-in class called TUniLoginForm. There can only be one LoginForm per application. After adding LoginForm, the application will display this form when a new session starts. You need to add controls, event handlers, and everything you need to achieve the required login functionality. Use the ModalResult of the form to control the login behavior. If LoginForm returns mrOK, it means successful login, and a new MainForm will be created and activated. When ModalResult returns mrCancel, it will terminate the session. If we use a form with only two buttons (one for successful login and the other for failure), please see the code below for details:
/Enter
procedure TUniLoginForm1.UniButton1Click(Sender: TObject);
begin
ModalResult := mrOK; // After valid login, it will jump to the MainForm form
end;
//Cancel
procedure TUniLoginForm1.UniButton2Click(Sender: TObject);
begin
ModalResult := mrCancel; // Exit the program after invalid login or give up
end;
Once the user logs in and displays the MainForm, there are two ways to terminate the session. You can terminate the session by returning mrOK as ModalResult and return to LoginForm, or terminate the session by returning mrCancel. For security reasons, existing sessions are always terminated before the LoginForm is displayed, that is, each new login starts a new session.
(4), The main form (MainForm):
MainForm is a single form that implements SPA. It is created and displayed after successful login (LoginForm) (if there is no LoginForm, it will be created and displayed directly). Generally, MainForm is the main form of an application that uses menus or other navigation tools to navigate to other forms. The MainForm is automatically created when a new project is created. Each Web session has its own private copy of MainForm, independent of each other, closing MainForm will terminate the current session. The following figure is a blank main form (MainForm):

MainForm is registered in the initialization of the unit so that uniGUI can separate it from other forms. The implementation code is as follows.
initialization
RegisterAppFormClass(TMainForm);
end.