
The code following will discuss about how to build login system based on MySQL database using Delphi.
1. Create the log in form.
2. Add TDatabase and TQuery component available on BDE tab.
3. Insert this code.
Edit1 = username.
Edit2 = password.
procedure TFormLogin.btnLoginClick(Sender: TObject);
begin
if (Edit1.Text = '') or (Edit2.Text = '') then
Application.MessageBox('Username dan Password tidak boleh kosong', 'INFORMASI', mb_OK);
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM admin WHERE username ='+QuotedStr(Edit1.Text));
Open;
end;
if Query1.RecordCount = 0 then
Application.MessageBox('Username tidak terdaftar, silahkan coba lagi', 'INFORMASI', mb_OK)
else
begin
if Query1.FieldByName('password').AsString <> Edit2.Text then
Application.MessageBox('Password anda salah, silahkan coba lagi', 'INFORMASI', mb_OK)
else
Hide;
FormUtama.Show;
end;
end;
4. Press Run or F9.Hopefully this article is helpful.
hay thnx man..
ReplyDeletegak paham
ReplyDelete