来一段delphi的登录代码
时间: 2024-05-31 07:08:07 浏览: 9
下面是一个简单的Delphi登录代码:
unit LoginForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TLoginForm = class(TForm)
UsernameEdit: TEdit;
PasswordEdit: TEdit;
LoginButton: TButton;
CancelButton: TButton;
procedure LoginButtonClick(Sender: TObject);
procedure CancelButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LoginForm: TLoginForm;
implementation
{$R *.dfm}
procedure TLoginForm.CancelButtonClick(Sender: TObject);
begin
Close;
end;
procedure TLoginForm.LoginButtonClick(Sender: TObject);
begin
if (UsernameEdit.Text = 'admin') and (PasswordEdit.Text = 'password') then
ShowMessage('Login successful!')
else
ShowMessage('Invalid username or password.');
end;
end.
在这个代码中,我们创建了一个登录窗口,包含一个用户名和密码的文本框、一个登录按钮和一个取消按钮。当用户输入用户名和密码后,点击登录按钮,程序会判断用户名和密码是否正确,如果正确则弹出一个提示框显示登录成功,否则弹出提示框显示用户名或密码错误。当用户点击取消按钮时,程序会关闭登录窗口。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)