This small project is designed to give you a quick method for converting Paradox tables to NexusDB tables. This will be useful if you need to do some special processing during conversion (e.g., delete or process records on during the conversion process) which you wish to keep separate from the Converter Utility that comes with the full NexusDB install system.
Create a new project with a single form as shown below. Note that the DB components at the top are all from the BDE tab of the VCL. Connect up the components: the NexusDB components as per Section 6 above and the BDE components as per the Delphi help (if you need a reference).
Connect up the following code to the appropriate button click events:
Ancillary Code:
procedure TMainformDialog.pxLoadTables;
var
Tables:TStringList;
begin
Tables:=TStringList.Create;
try
Database1.GetTableNames(Tables);
ListBox2.Items.Assign(Tables);
finally
Tables.Free;
end;
end;
procedure TMainformDialog.nxLoadTables;
var
Tables:TStringList;
begin
Tables:=TStringList.Create;
try
nxDatabase1.GetTableNames(Tables);
ListBox1.Items.Assign(Tables);
finally
Tables.Free;
end;
end;
procedure TMainformDialog.FormCreate(Sender: TObject);
begin
DataBase1.Connected:=True;
nxDataBase1.AliasPath:=ExtractFilePath(ParamStr(0));
nxDataBase1.Connected:=True;
pxLoadTables;
nxLoadTables;
end;
Top Button (Display PX):
procedure TMainformDialog.Button4Click(Sender: TObject);
begin
If ListBox2.ItemIndex<0 then ShowMessage('No Table Selected') else
begin
Table1.Close;
Table1.TableName:=ListBox2.Items[ListBox2.ItemIndex]+'.DB';
if Table1.Exists then Table1.Open else ShowMessage('Sorry - that is not a Paradox table!');
end;
Middle Button (Convert):
procedure TMainformDialog.Button3Click(Sender: TObject);
var
i:integer;
ok:Boolean;
begin
If Not Table1.Active then ShowMessage('No table is open') else
begin
with nxTable1 do
begin
Close;
FieldDefs.Clear;
FieldDefs.Assign(Table1.FieldDefs);
IndexDefs.Clear;
IndexDefs.Assign(Table1.IndexDefs);
TableName:=System.Copy(Table1.TableName,1,System.Pos('.DB',Table1.TableName)-1);
if Exists then OK:=MessageDlg('Table already exists. Replace?',mtConfirmation,[mbYes,mbNo],0)=mrYes else OK:=True;
if ok then
begin
CreateTable;
Open;
with Table1 do
begin
first;
while not eof do
begin
nxTable1.Insert;
for i:=0 to Pred(FieldCount) do
nxTable1.Fields[i].Assign(Fields[i]);
nxTable1.Post;
next;
end;
end;
end;
end;
nxLoadTables;
end;
Bottom Button (Display NX):
procedure TMainformDialog.Button2Click(Sender: TObject);
begin
If ListBox1.ItemIndex<0 then ShowMessage('No Table Selected') else
begin
nxTable1.Close;
nxTable1.TableName:=ListBox1.Items[ListBox1.ItemIndex];
nxTable1.Open;
end;
When you compile and run this button and then double-click, for example, the biolife table, you should see the following on your screen:
If you now click the Convert button the following screen will be displayed.
This example has shown you, in a very quick way, how to read all the tables from a particular directory (or alias) into a list box as well as how to create a NexusDB copy of an existing Paradox table, including transferring the data across.
Correction
CreateTable will fail in the above code as the paradox primary index name will be null and thus not a valid Nexus index name.
I can't remember whether the primary index is always first, so I fixed with
after IndexDefs.Assign(Table1.IndexDefs);
for I := 0 to Indexdefs.Count-1 do
if Indexdefs.Items[i].Name='' then
Indexdefs.Items[i].Name:='ndxPrimary';