Beruflich Dokumente
Kultur Dokumente
Contents
1. Software requirements
2. Database Example Program
1 Software requirements
You will need to make sure you have the following software before continuing with the example program:
1. Microsoft Windows 7 (32-bit / 64-bit) http://www.microsoft.com
2. Microsoft Access Database Engine 2010 Redistributable (32-bit) - http://www.microsoft.com/enza/download/details.aspx?id=13255
3. Your Microsoft Access Database file.
4. Lazarus 1.2.0 or newer - http://www.lazarus.freepascal.org/
The above steps will all be highlighted in screen dumps for you below:
2.1.2 Left click on the right arrow of Computer, and then left click on your C: drive
N.B. The name of our C: drive is called Local Disk (C:) as shown in the diagram.
2.1.3 Left click on the New Folder option from the file menu, rename the New Folder to
Lazarus_MSAccess and press the Enter key on your keyboard.
Left click on the Start ( ) button on of Windows 7, navigate to All Programs, navigate to and left click
once on Microsoft Office, left click on Microsoft Access 2010.
2.2.2 A screen similar to the one shown below should now appear, left click on the New button, left click on
Blank database option and then left click on the
2.2.3 A screen similar to the one shown below should now appear:
2.2.4 Rename the columns and activate the relevant database restrictions.
N.B. Below is our final changes.
2.2.5 Left click on the Close button to have the below prompt appear, left click on Yes to accept the changes:
2.2.6 The below prompt will now appear, rename the table to Student and then left click on OK to accept
the changes:
2.2.7 Your screen should now look similar to the one shown below, left click on the Student table and you
should see the results as shown above.
2.2.8 Left click on File, navigate and left click on Save Database As, locate the Lazarus_MSAccess folder and
save the database file as MyAccess.
2.3.2 Simply fill in the required information for column as you require.
2.3.3 Repeat the above steps to add more rows of data.
2.3.4 Left click on the Save button, when complete, close the database. This now concludes the creation of
the SQLite database sqlite1.db
Left click on the Start ( ) button on of Windows 7, navigate to All Programs, navigate to and left click
once on Lazarus, left click on Lazarus.
2.4.2 A screen similar to the one shown below should now appear, left click on the + button.
TSQLQuery
TSQLTransaction
SQLdb tab
Use these
arrows to
expand your tabs
TODBCConnection
2.4.3 Your screen should now look similar to the one shown below after adding all the above controls.
2.4.4 Add a button and a label to your form, remember to rename all your components. I have only
renamed the Form, Button and Label in my example.
2.4.5 Add the following code to your button click event and test the program:
//Required specification for MS Access Connection
ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb, *.accdb);
ODBCConnection1.params.add(DBQ=+ExtractFilePath(Application.ExeName) + MyAccess.accdb);
ODBCConnection1.Connected := True;
ODBCConnection1.KeepConnection := True;
//Transaction Part for MS Access Connection
SQLTransaction1.Database:= ODBCConnection1;
//Create the Query for MS Access Connection
SQLQuery1.Database:=ODBCConnection1;
SQLQuery1.UsePrimaryKeyAsKey:=False;
SQLQuery1.SQL.Text:='SELECT * FROM Student';
//Assign the DataSource for MS Access Connection
Datasource1.DataSet:=SQLQuery1;
DBGrid1.DataSource:=DataSource1;
// End of connection string
//This lets you know via the label if you are connected or not
If ODBCConnection1.Connected then
begin
lblStatus.caption:='Connected';
end;
// End of label notification
//This starts the query which was created in the connection string
// This will also pass the information through to the Grid
SQLQuery1.open;
2.4.6 If the above steps have been followed, then you should see the results of the information in your
database displayed in Lazarus. Enjoy.