In this section we create an application that holds both embedded server and remote server engines.  A TRadioGroup is used to switch between tables associated with the 2 different engines.

Start the NexusDB Server on your workstation and ensure that the Winsock transport is started and an appropriate alias has been created. Find more information about the NexusDB Server in section 5.

By now you are an expert at whipping up NexusDB applications.  So create the application form as shown below:

DelphiGuide_mixEmbedded(1)

Please enter the following code.  Note that the top ListBox is ListBox1 and the lower (bigger) one is ListBox2.  The other components follow easily from their usage in the code.

procedure TMainformDialog.InitCommsEngine;

begin

 ListBox1.Clear;

 try

   nxSession1.Open;

   LoadAliases;

 except

   on E:Exception do

   begin

     MessageDlg(E.Message,mtError,[mbOk],0);

   end;

 end;

end;

procedure TMainformDialog.LoadAliases;

var

 Aliases:TStringList;

begin

 Aliases:=TStringList.Create;

 try

   nxSession1.GetAliasNames(Aliases);

   ListBox1.items.assign(aliases);

 finally

   Aliases.Free;

 end;

end;

procedure TMainformDialog.LoadTables;

var

 Tables:TStringList;

begin

 Tables:=TStringList.Create;

 try

   nxDatabase1.GetTableNames(Tables);

   ListBox2.items.assign(Tables);

 finally

   Tables.Free;

 end;

end;

procedure TMainformDialog.ListBox1DblClick(Sender: TObject);

begin

 nxDatabase1.Connected:=False;

 nxDatabase1.AliasName:=ListBox1.Items[ListBox1.ItemIndex];

 nxDatabase1.Connected:=True;

 LoadTables;

end;

procedure TMainformDialog.RadioGroup1Click(Sender: TObject);

begin

 nxSession1.Connected:=false;

 if RadioGroup1.ItemIndex=0 then

 begin

   Button1.Hide;

   Label3.Hide;

   Label4.Hide;

   nxSession1.ServerEngine:=nxRemoteServerEngine1;

   InitCommsEngine;

   ListBox1.Show;

   Label2.Show;

 end else

 begin

   ListBox1.Hide;

   Label2.Hide;

   nxSession1.ServerEngine:=nxServerEngine1;

   Button1.Show;

   Label3.Show;

   Label4.Hide;

   Label4.Caption:='';

 end;

 nxSession1.Connected:=True;

end;

procedure TMainformDialog.Button1Click(Sender: TObject);

var

 aPath:String;

begin

 aPath:=ExtractFilePath(paramStr(0));

 if SelectDirectory(aPath,[sdAllowCreate,sdPerformCreate,sdPrompt],SELDIRHELP) then

 begin

   with nxDataBase1 do

   begin

     Connected:=false;

     AliasPath:=aPath;

     Connected:=true;

   end;

   LoadTables;

 end;

end;

procedure TMainformDialog.ListBox2DblClick(Sender: TObject);

begin

 With nxTable1 do

 begin

   Close;

   TableName:=ListBox2.Items[ListBox2.ItemIndex];

   Open;

 end;

end;

Once the application starts up, select the mode you want by pressing the correct radio button. Depending on your selection you will end up with either

clip0027

or

clip0028

The technique shown above gives you full control over where to store data. You can for example cache data on client side to avoid slow lookups over the network or you can divide the data into private and public parts.  A good use of this is to copy lookup tables from a remote server into a local server engine (and usually as in-memory tables for extra speed) on the assumption that the data in the lookup tables change rarely if at all.

Home | Site Contents | Documentation | NexusDB Manual V4 | Delphi Guide | Code Examples & Fragments