Board index » delphi » Duplicating a TTable record

Duplicating a TTable record

On Fri, 30 Jul 1999 07:56:26 +1000, "Scott Muller"

Quote
<smul...@netconnect.com.au> wrote:
>I didn't explain this very well.  I have a Table with 50 fields in it and I
>need to copy the last record and append it to the end of the table.  I can
>assign each field to a variable one at a time the append a record and feed
>the values back in but there must be a better way.

One way would be to use a separate dataset component. Synchronize the
second one to point to the same record as is current in the first. Then, in
a loop, traverse the fields in the dataset (such as by iterating through
the Fields property or the TFieldDef objects in the FieldDefs property).
For each field, call the TField.Assign method to assign the value for the
field in the first dataset to the same field in the target dataset. For
example:

  for i := 0 to (Table1.FieldCount - 1) do
    Table2.Fields[i].Assign(Table1.Fields[i]);

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

 

Re:Duplicating a TTable record


There used to be a Delphi TI that gave
the delphi code to use BDE calls to copy
a record.  I suspect it's still there.  I found it
while using D1.  If you can't find it email me.
I'm not sure if it  copied memo fields. But you
can do that before the post.

Quote
Scott Muller <smul...@netconnect.com.au> wrote in message

news:7nqhts$aoe14@forums.borland.com...
Quote
> I didn't explain this very well.  I have a Table with 50 fields in it and
I
> need to copy the last record and append it to the end of the table.  I can
> assign each field to a variable one at a time the append a record and feed
> the values back in but there must be a better way.

> ?????

> Scott Muller

Re:Duplicating a TTable record


Use two TTables, one pointing to the new record and one pointing to the one
to copy from. Then:

for I := 0 to Table1.FieldCount - 1 do
  Table1.Fields[I].Assign(Table2.Fields[I]);

If you really want to copy to memory use a for loop and a variant array
instead of indiviual variables.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to questions received via email)

Other Threads