Photo by Jeff Stapleton from Pexels

Getting started with mORMot and Delphi

This article describes steps for setting up Delphi with mORMot and, as with most of my articles, exists largely as a reminder for my future self.

You can find the Lazarus/Free Pascal version here.

The first step is to install Delphi. In my case, this means going to the Free Delphi Community download page on the Embarcadero website. Sign in, download and run the installer, and enter your serial number when prompted by the wizard.

Next, acquire the mORMot library. At the time of writing, Synopse claims on their download page that the “unstable” 1.18 trunk version is more stable than the latest “stable” 1.17 version. Therefore, it makes sense to download the latest build.

A warning from mORMot

The simplest way to do this is to visit the Delphi Installation section of their online documentation. Following the steps there, download the nightly build using the link provided and extract this wherever you keep your third party libraries.

Once again according to the Synopse download page, this package does not include the requisite SQLite3 object files. You need to download these separately using the link provided. When I extracted this archive, it contained exactly one file — sqlite3.obj. Put this file in the SQLite3 sub-directory of your mORMot source directory. Failing to do this will result in an error when compiling SynSQLite3Static.pas.

Now the Delphi IDE must be configured to use mORMot.

From the “Tools” menu, open the “Options” dialogue. In the tree, navigate to “Language”, “Delphi Options” and “Library”. On this page, you will amend the “Library path” and the “Browsing path” (also known as the “Search path”).

Finding the Delphi library settings in 10.3

Assuming that you extracted the mORMot library into D:\Dev\mORMot, add the following paths to both the “Library path” and the “Browsing path”:

D:\Dev\mORMot
D:\Dev\mORMot\SQLite3
D:\Dev\mORMot\SynDBDataset

As usual for Delphi, invalid paths turn grey, so use this cue to confirm that the path is correct.

The easiest way to test that Delphi picks up mORMot is to open one of the samples. Load the following project from the extracted mORMot source:

SQLite3\Samples\01 - In Memory ORM\Project01.dproj

Run the project. If your paths are correctly configured, the project will compile successfully and you will be presented with the following somewhat minimalistic UI:

Sample 01 — In Memory ORM

To be thorough, enter a name and a message and click “Add the message”. This adds a record to an in-memory SQLite3 database. To search the database for your record, enter the same name again and click “Find a previous message”. You should see the same message again. Et voila!

You may also be interested in one of my other articles on the framework:

  • Delphi 10.3 Starter
  • mORMot 1.18
  • Windows 10 Pro

Software developer walking the edge between legacy systems and modern technology. I also make music: https://soundcloud.com/stephanbester