sintak untuk form 1
===================
unit ULogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TFrmLogin = class(TForm)
Label1: TLabel;
edusername: TEdit;
Label2: TLabel;
edpassword: TEdit;
Button1: TButton;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLogin: TFrmLogin;
implementation
uses
// XPMan agar tampilan form seperti button mengikuti theme pada windows
// Tambahkan unit UHasilLogin ke ULogin dengan menekan Alt + F11, atau dengan mengetiknya saja
XPMan, UHasilLogin;
{$R *.dfm}
procedure TFrmLogin.FormCreate(Sender: TObject);
var
s : Char;
alamatdb : WideString;
begin
// Manipulasi cursors crSQLWait agar tidak tampil
Screen.Cursors[crSQLWait] := Screen.Cursors[crDefault];
// atur tampilan form
s := '*';
edusername.Text := '';
edpassword.PasswordChar := s;
edpassword.Text := '';
// atur koneksi pada ADOConnection
// script ini berguna untuk mengatur koneksi database pada aplikasi
// agar aplikasi dapat memproses database yang dipilih di komputer
// manapun tanpa harus mempunyai path/alamat database yang sama.
alamatdb := ExtractFilePath(Application.ExeName) + 'data.mdb';
with ADOConnection1 do begin
Connected := False;
LoginPrompt := False;
Mode := cmShareDenyNone;
ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' +
alamatdb + ';Persist Security Info=False';
end;
ADOConnection1.Connected := True;
end;
procedure TFrmLogin.Button1Click(Sender: TObject);
begin
with ADOQuery1 do begin
Close;
SQL.Clear; // bersihkan perintah sql jika ada
SQL.Add('select * from login where username='+
QuotedStr(edusername.Text));
Open;
end; // end with
// jika tidak ditemukan data yang dicari maka
// tampilkan pesan
if ADOQuery1.RecordCount = 0 then
Application.MessageBox('Maap, username tersebut tidak ada', 'Informasi',
MB_OK or MB_ICONINFORMATION)
else begin
if ADOQuery1.FieldByName('password').AsString <> edpassword.Text
then Application.MessageBox('Pastikan username atau password benar', 'Error',
MB_OK or MB_ICONERROR)
else begin
Hide;
Form1.Show;
end
end;
end;
end.
sintak untuk form 2
===================
unit UHasilLogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.
SOURCE CODE DOWNLOAD : http://www.4shared.com/file/PJ6eNMeJ/Form_Login.html
Tidak ada komentar:
Posting Komentar