Libraria, an application for Libraries
Let's build a small program with "Delphi Community" for entering data in our Books table.
- Open Delphi and start a new project: menu File > New > VCL Forms Application
- Drop the following components on the form:
TClientDataSet (Tool Palette, category Data Access)
TDataSource (Tool Palette, category Data Access)
TDBGrid (Tool Palette, category Data Controls)
TDBNavigator (Tool Palette, category Data Controls)
- Let's customize some of the properties of the
components. In the Object Inspector, change a few properties of the
- Save your project, e.g. in a folder \Libraria
Setting up the fields of the ClientDataSet
You can set up your ClientDataSet in the Object Inspector, but I prefer
to do this in the source code. This gives us more control over the process. Proceed as follows:
- Add an OnCreate event handler to formBooks: in the
Object Inspector, go to the Events tab of formBooks and double click next to OnCreate.
- In the code editor, complete the event handler as follows:
procedure TformBooks.FormCreate(Sender: TObject);
cdsBooks.FieldDefs.Add('TITLE', ftString, 30, False);
cdsBooks.FieldDefs.Add('AUTHOR', ftString, 30, False);
cdsBooks.FieldDefs.Add('ISBN', ftString, 13, False);
cdsBooks.FieldDefs.Add('ID', ftString, 4, False);
- Run the project (press key F9).
Don't forget to save your project!
Note that you can add/edit/delete records in the grid. However, the contents of cdsBooks
is not saved in a file when you stop the program. That's for our next tutorial.
Database Tutorials -
Part 1 Database
Tutorials - Part 3