Para montarmos essa tela criamos uma form adicionando 2 label, 2 edits e um SpeedButton:
procedure Tlogin.SpeedButton1Click(Sender: TObject);
var
user : String;
cod : String;
Acesso : String;
begin
Query_Login.Close;
Query_Login.SQL.Clear;
Query_Login.SQL.Append('select * from login where usuario = '
+ #39 + usuario.text + #39);
Query_Login.Open;
user := Query_Loginusuario.AsString;
cod := Query_Loginsenha.AsString;
Acesso := Query_Loginnivel.AsString;
if (usuario.Text = '') and ( senha.Text = '') then
// Caso os campos usuário e senha estejam vazios
begin
ShowMessage('Por favor , preencha os campos usúario e senha');
end
else if (usuario.Text = user ) and ( senha.Text = cod) and ( Acesso = 'total')
then // Caso o usuário tenha acesso total
begin
principal.showmodal;
login.Close;
end
else if (usuario.Text = user ) and (senha.Text = cod) and ( Acesso = 'simples')
then // Caso o usuário tenha acesso simples
begin
principal.Cadastro1.Visible := false;
//Esse Cadastro1.visible refere-se a um menu no mainmenu
principal.ShowModal;
login.Close;
end
else if (usuario.Text <> user ) and ( senha.Text <> cod )then
// Casos o usuário ou senha não tenha no banco
begin
ShowMessage('Usúario ou senha incorreto , ou inexistente');
usuario.clear;
Senha.Clear;
usuario.SetFocus;
end
else if (usuario.Text <> user) then
begin
ShowMessage('Usúario ou senha incorreto , ou inexistente');
usuario.clear;
Senha.Clear;
usuario.SetFocus;
end
else if (senha.Text <> cod ) then
begin
ShowMessage('Usúario ou senha incorreto , ou inexistente');
usuario.clear;
Senha.Clear;
usuario.SetFocus;
end;