Here we will show how to build a very simple database application using the embedded data module we just created.  In the Delphi IDE you will need to create a new project.

Hint

If you don't want to create this example on your own you can find the complete source in the Examples\Delphi\Manual\SimpleEmbedded subdirectory of your NexusDB installation. If you don't have this directory you download the examples from our webpage.

Step 1: Adding the data module

Select File/New/Other... from the Delphi main menu. This will popup the New Items dialog where you can find the NexusDB tab. Select it, focus the EmbeddedDM entry, make sure Copy is activated.

DelphiGuide_UseDM

Pressing OK will add a copy of the data module to your application.

Step 2: Adding a table

Locate and drop on a TnxTable on the data module. To connect to the database available in the data module, just connect the Database property via the drop down list  (the correct Session will be set for you). Finally select the table for this instance in the TableName property. Your nxTable1 component should now look as follows (after selecting a table).        

DelphiGuide_AddTable

DelphiGuide_AddTable_name

Now save the new data module as embeddeddm.pas to the new project directory.

Step 3: Creating a form

Create a new form and drop a TDatasource (Data Access tab in the component Palette) and a TDBGrid (Data Controls) on the form. Arrange them similar to this:

DelphiGuide_EmbExampleForm

Select the DBGrid and set its Anchors property to [akLeft,akTop,akRight,akBottom]; this makes sure that we can resize the grid with the form.

Step 4: Hooking up the data

Make sure you've saved the data module above, then add the data module to the uses clause in the interface, which will add the components on it to the drop down lists of the current form. Connect the Dataset property of the Datasource to the table

DelphiGuide_EmbExampleDataset

and set the Datasource property of the DBGrid to our datasource.

DelphiGuide_EmbExampleDatasource

The only thing left to do is to make sure the tables are opened when starting the app.

Step 5: Opening the table

For this purpose simply set the ActiveRuntime property of the table to true. That's it. Compile the app and run.

DelphiGuide_EmbExampleRunning

Congratulations. You've just created your first NexusDB database application!

Caveat 1

When using embedded mode always keep in mind that the IDE opens tables if you have ActiveDesignTime enabled. Trying to run your embedded application from the IDE/Debugger will fail to open the table at runtime, because it is using a different ServerEngine. Nexus only allows ONE server engine to access a file at a time. In general we recommend always using an external server while developing.

Caveat 2

Since we are relying on Delphi creating the datamodule make sure that the datamodule is automatically created before the form is created. Check the forms tab of the project options!

Home | Site Contents | Documentation | NexusDB Manual V4 | Delphi Guide | Code Examples & Fragments | Applications with the database embedded