To create a login page in Delphi, you can use a combination of visual components such as TEdit
for the username and password fields, TButton
for the login button, and TLabel
for the prompts and error messages.
Here is an example of how you might create a simple login form in Delphi:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Button1: TButton; Label1: TLabel; Label2: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var UserName, Password: String; begin UserName := Edit1.Text; Password := Edit2.Text; if (UserName = ‘admin’) and (Password = ‘password’) then begin // Login successful ShowMessage(‘Login successful’); end else begin // Login failed ShowMessage(‘Invalid username or password’); end; end; end. |
This code creates a form with two TEdit
components for the username and password, a TButton
component for the login button, and two TLabel
components for the prompts. When the user clicks the login button, the code retrieves the username and password from the TEdit
components and checks them against a hard-coded valid username and password. If the login is successful, it displays a message. If the login fails, it displays an error message.
You can customize the appearance and behavior of the login form by setting various properties of the visual components, such as the Caption
property of the TButton
component to change the text on the login button, the PasswordChar
property of the TEdit
component to obscure the password with asterisks, and the Color
property of the TLabel
component to change the text color.
In a real-world application, you would typically replace the hard-coded username and password with a database or authentication service to validate the user’s credentials. You might also add additional features such as a “Forgot password” link or a “Remember me” checkbox.
Leave a Reply