Let's add a run-time enhancement to our data module so that the resulting exe is not restricted to the path coded into the AliasPath property of the database component.  That is, let's make the application automatically change this to point to the same path as the exe itself (here we are assuming that the data tables will reside in the same directory as the exe).

Please note that for this to work you need to set the ActiveRuntime properties of the database and tables to false.

To have the tables created in the same directory as where the exe resides, plus to activate the NexusDB component chain, add the following code to the OnCreate event handler of the form (or data module if you used one) as follows:

procedure TMainformDialog.FormCreate(Sender: TObject);

begin

 EmbeddedDM.nxDataBase1.AliasPath:=ExtractFilePath(paramStr(0));

 EmbeddedDM.nxTable1.Active:=True;

end;

That's it. When the program starts, the engine will look for the tables in the same directory as the executable.

Recommendation

We recommend to keep your data in a separate subdirectory of the application which can easily be achieved by modifying the above to, for example,

EmbeddedDM.nxDataBase1.AliasPath:=extractFilePath(paramStr(0))+'\data';

In the same way you can set all properties of the database components at start-up. Just make sure that the components have the ActiveRuntime property set to false, if you want to use code changes.

Caveat

For the application to start successfully the data directory and the table must exist!

Hint

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

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