1. Computing

Creating flat (non-relational) databases with no (Delphi) database components

Create your own *flat* database and store any kind of data


Welcome to the sixteenth chapter of the FREE online programming course:
A Beginner’s Guide to Delphi Programming.
Delphi Personal edition does not offer database support. In this chapter, you will find out how to create your own *flat* database and store any kind of data - all without a single data aware component.

No DB support in Delphi Personal edition

As you probably know, Delphi Personal edition comes with no database support, in terms of data-aware components. Hopefully, "data world" isn't only about Paradox, Access, Interbase or MySQL.

The data your application needs to operate on may not always be stored in a relational database. It may be stored in an ASCII text file or a structured binary file. It may even be stored in an XML file.

As you will learn from this chapter, your application can read data from a file (of *any* structure), update "fields", add new "records", and write data back to the file as if the data were stored in a *real* database.

NOTE: flat-file databases are not as scaleable (and safe) as the relational model databases (MySQL, MS SQL Server, Interbase, etc). If you are only working with a small amount of data that is rarely updated then a flat-file database could be your choice.
However, if you are looking for a database for more frequent and heavy use then a relational database is probably more suitable. Be sure to check our "Beginner's Guide to Delphi Database Programming"!

Files from Delphi perspective

Simply put a file is a binary sequence of some type. In Delphi, there a three classes of file: typed, text, and untyped. Typed files are files that contain data of a particular type, such as Double, Integer or previously defined custom Record type. Text files contain readable ASCII characters (organized into lines). Untyped files are used when we want to impose the least possible structure on a file.

Building your own database system

The next series of articles shows you how to use Delphi to create a simple "database" application that interacts with data in text (ASCII) or binary files:
  • Handling ASCII (text) files from Object Pascal code
    Simply put, text files contain readable ASCII characters. Although it is possible to make changes within text file, jump around when processing information or add some data to the file other than at the end, it is advisable to use a text file only when we know that we are working with ordinary text and no such operations are necessary.

  • Your own database
    Working with binary files from Delphi. Use Delphi to manage writing, reading and updating your own types of files. Writing and reading. Seeking and positioning. Changing and updating.

  • Files with no structure (untyped files)
    Using Delphi to manage operations on untyped files - direct access to disk files regardless of type and structuring.

  • Various File IO articles and tutorials
    Including: Understanding what files are and choosing a Delphi file type. What is a File? How are they stored? What format is best for my project (text, files of record or untyped)?

  • Accessing 'Configuration Settings' files (.INI) with Delphi
    How a simple text file can beat Registry in storing a few pieces of application specific configuration data.

  • File Management Routines
    A list of Delphi's RTL functions designed to ease file management.

Some exercises for you...

Make a plan, create a simple Delphi project, let's say some kind of database (with typed files) to store all your CD's, DVD's...

   To the next chapter: A Beginner's Guide to Delphi Programming
This is the end of the sixteenth chapter, in the next chapter, I'll show you how to build your own code units.

If you need any kind of help at this point, please post to the Delphi Programming Forum where all the questions are answered and beginners are treated as experts.

A Beginner's Guide to Delphi Programming: Next Chapter >>
>> Working with units

©2014 About.com. All rights reserved.