Student Of Fortune

[Dephi] Creating a Login Form With Delphi and Microsoft Access Database

Share on :
Many of the novice Delphi programmers, the difficulty to create a login form within the application. For that I will try to make a simple tutorial on how to create a login form for the administrator, nor any other operator.
Follow the Instructions Below:
1. Run the program Delphi.
2. Add 2 Labels, 2 TEdit, and 1 Button
3. Set properties for each component.


4. File -> New -> Form, to add a form  
5. Save Project, for the FrmLogin give the name "Ulogin units", while to form has made, you can give       
    unit's name UHasilLogin.
6. Set looks like in the picture.
 
7. Now create a database to store their login data. Use the Microsoft Access database.
8. Run Microsoft Access
9. File New Blank Database
10. Give the name file with data, then Click Create,
  
If you simply want to create a new DB without opening Ms.Access, my friend can use this VBS script, save with the name script.vbs in a text editor like notepad
Dim DBFileName
Dim objConnection,FSO
Dim objDBFile

Set objConnection = CreateObject("ADOX.Catalog")
Set FSO=CreateObject("Scripting.FileSystemObject")

DBFileName=Trim(InputBox("Enter Filename With Location  " _
 & "Database Will be Created", "JET Database Generator","C:\DB_Baru.mdb"))
 
If DBFileName <> Empty Then
  ' make new Database 
 objConnection.Create "Provider = Microsoft.Jet.OLEDB.4.0; " & _
         "Data Source = " & DBFileName
         
 If FSO.FileExists(DBFileName) Then
  MsgBox "Database has been created",vbInformation,"Success"
 End If
 
End if
11. Open a new databse and create a single table, with the name of the login table. Use the Create table in      design view to create tables
12. Make 2 Field as shown below. Set Field Size as desired.

17. And below the code for login form
ULogin unit;
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;
   
Button1Click procedure (Sender: TObject);
   
FormCreate procedure (Sender: TObject);
  
private
   
{Private Declarations}
  
public
   
{Public Declarations} end;
var FrmLogin: TFrmLogin;
implementation uses  
/ / XPMan for display form such as the button following the theme on windows
/ / Add to ULogin UHasilLogin unit by pressing Alt + F11, or with
/ / typed it

XPMan, UHasilLogin;

{$ R *. DFM}

TFrmLogin.FormCreate procedure (Sender: TObject);
var
s: Char;
alamatdb: WideString;
begin

/ / Manipulation cursors crSQLWait order not to appear
Screen.Cursors [crSQLWait]: = Screen.Cursors [crDefault];

/ / set the display form
s: = '*';
edusername.Text: ='';
edpassword.PasswordChar: = s;
edpassword.Text: ='';

/ / set the connection on ADOConnection
/ / This script allows you to manage database connections in applications
/ / in order to application can process
database that has been selected in a computer 
/ / anywhere without the need to have a path / address the same database.

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;

TFrmLogin.Button1Click procedure (Sender: TObject);
begin
    with ADOQuery1 do begin
      Close;
      SQL.Clear; / / clear
command sql if there is.
      SQL.Add ('SELECT * FROM login WHERE username =' +
      QuotedStr (edusername.Text));
      Open;
    end; / / end with

    / / if not found then the data sought
    / / display message
    if ADOQuery1.RecordCount = 0 then
      Application.MessageBox ('Sorry, your username does not exist', 'Information',
      MB_OK or MB_ICONINFORMATION)
    else begin
      if ADOQuery1.FieldByName ('password'). AsString <> edpassword.Text then
        Application.MessageBox ('Make sure the correct username or password',
        'Error', MB_OK or MB_ICONERROR)
      else begin
         Hide;
         Form1.Show;
      end
    end;
end;

end.
 
18. Add code Application.Terminate to button located on the unit uHasilLogin.
19. Compile the program and See the results

20. Finish 

2 comments on [Dephi] Creating a Login Form With Delphi and Microsoft Access Database :

Do789 said... October 25, 2011 at 11:13 AM

hey can u help me i have to make an offline social network with profiles and what not. i need help with this

Anonymous said... December 4, 2011 at 1:31 PM

legend

Post a Comment and Don't Spam!

Dont Spam please

 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank