Board index » delphi » Copying exact fields from one Table to another

Copying exact fields from one Table to another

Hi All,

I might have a few tables which has exactly the same structure, ie the same
name and number of TFields.  Some of these may be calculated or lookup
fields.  Rather than having to manually go through all the tables and add
any newly created fields, is there a way to programatically copy all of the
fields from one table to another.  I have tried (clutching at straws) things
like Table1 := Table2 but violation errors inevitably occur.

So as an example:

Table1 has Surname, FirstName, Initials and CalcName    where CalcName is a
combination of all

Table2 is blank - task to copy all four field definitions to table1

Any help will be appreciated as always

Thanks

Alex

 

Re:Copying exact fields from one Table to another


Hi

Take a look at the TBatchMove component.
Regards.
Elio - Rio de Janeiro - Brasil

Re:Copying exact fields from one Table to another


Quote
>I might have a few tables which has exactly the same structure, ie the same
>name and number of TFields.  Some of these may be calculated or lookup
>fields.  Rather than having to manually go through all the tables and add
>any newly created fields

if your calculated fields in the source table will be added into regular fields
in the target table then you would have to do this opperation one record at a
time itterating through the source tables records.   You can use a generic
record copy routine that itterates through the fields array and uses Asign which
will handle any field type.

if the sourec and target fields are all of the same type then you can us a
batchMove component.

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:Copying exact fields from one Table to another


Brian,

I think I may have not explained properly.  I do not want to copy records
from one table to another but field definitions.  Both tables look at the
same physical table.  If I expand, by saying why I'm doing this.

I have a TTable which with many defined fields; both physical and logical.
It is used for screen display and other processes etc.  Because there is
alot of code behind this table I do not want to use this table for reports.
So I have created another table which shares the OnCalcFields code.

So far so good.  During development the TTable is modified quite frequently,
fields added etc.  So to keep both tables synchronised I have to add the
same fields to the second TTable ie reports.  Therefore I would just like to
copy the field definitions at run-time from the first table to the second
table.  How can I do this?  Is it possible maybe to create a new instance at
run-time from this first table?

By the way thanks for your continued help,  I certainly appreciate it!

Regards

Alex

Quote
Brian Bushay TeamB wrote in message

<35a4cfa4.46917...@forums.borland.com>...
Quote

>>I might have a few tables which has exactly the same structure, ie the
same
>>name and number of TFields.  Some of these may be calculated or lookup
>>fields.  Rather than having to manually go through all the tables and add
>>any newly created fields

>if your calculated fields in the source table will be added into regular
fields
>in the target table then you would have to do this opperation one record at
a
>time itterating through the source tables records.   You can use a generic
>record copy routine that itterates through the fields array and uses Asign
which
>will handle any field type.

>if the sourec and target fields are all of the same type then you can us a
>batchMove component.

>--
>Brian Bushay (TeamB)
>Bbus...@DataGuidance.com

Re:Copying exact fields from one Table to another


Quote
>Therefore I would just like to
>copy the field definitions at run-time from the first table to the second
>table.  How can I do this?  Is it possible maybe to create a new instance at
>run-time from this first table?

I haven't tried it but I belive you can write code like this

TargetTbl.fieldDefs.clear;
TargetTbl.fieldDefs.assign(sourceTbl.FieldDefs)

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Other Threads