Mega Code Archive

 
Categories / Delphi / ADO Database
 

How to duplicate a TTable

Title: How to duplicate a TTable type TForm1 = class(TForm) tbSource: TTable; tbTarget: TTable; // ... end; implementation procedure TForm1.Button1Click(Sender: TObject); begin tbSource.TableName := 'Source.DB'; // The name of your tables which you want to copy from tbTarget.TableName := 'Target.DB'; // The name of your tables which you will to copy to // You Can set the tbSource.DataBaseName to an existing path/Alias // where you store your DB // You Can set the tbTarget.DataBaseName to an existing path/Alias // where you want to store the duplicate DB tbSource.StoreDefs := True; tbTarget.StoreDefs := True; tbSource.FieldDefs.Update; tbSource.IndexDefs.Update; tbTarget.FieldDefs := tbSource.FieldDefs; tbTarget.IndexDefs := tbSource.IndexDefs; tbTarget.CreateTable; //Actually you can set these code up to only 5 lines :) end; End.