Let's add a run-time enhancement to our application 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 the ServerName point to the one given as the first command line parameter (here we are assuming that the data tables will reside in the alias we use on this server).

Please note that for this to work you need to set the ActiveRuntime properties of the transport, 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

 if ParamCount>0 then

 begin

   // make sure the transport is inactive

   RemoteDM.nxWinsockTransport1.Active:=false;

   // set the server name

   RemoteDM.nxWinsockTransport1.ServerNameRuntime:=paramStr(1);

 end;

 RemoteDM.nxTable1.Active:=True;

end;

That's it. When the program starts, the engine will connect to the server given as first command line parameter. If none it will connect to the one given at compile time.

Recommendation

We recommend to extend above method a bit to optionally read the AliasName too, or alternatively read the configuration from an inifile or the registration.

if ParamCount>1 then

 RemoteDM.nxDataBase1.AliasName:=paramStr(2);

This will later allow your application to be used on different servers and aliases without the need to change the database.

Caveat

For the application to start successfully the data alias and the table must exist on the connected server!

Hint

If you don't want to create this example on your own you can find the complete source in the Examples\Delphi\Manual\RunEmbedded 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 | Client/Server Applications - Client App Separate from the Server