Board index » delphi » copying data from one record to the next when inserting a new record

copying data from one record to the next when inserting a new record

hello,

        I would like to know if there is a way to copy one field of a
record to a newly created record.  I am using Interbase 3.3 server
version.  I have an OnNewRecord event for one of my tables and would
the data from the previous records VarChar field of length 32000
to be copied to the newly created field.  Is there an easy way to key
the varchar field in a temp variable or something so when the new record
is created it can just copy the data there.  Any help is appreciated.

Thanx in advance

Chad lind
Cal...@cacd.rockwell.com

 

Re:copying data from one record to the next when inserting a new record


CHAD A LIND (cal...@cacd.rockwell.com) wrote:
:       I would like to know if there is a way to copy one field of a
: record to a newly created record.  I am using Interbase 3.3 server
: version.  I have an OnNewRecord event for one of my tables and would
: the data from the previous records VarChar field of length 32000
: to be copied to the newly created field.  Is there an easy way to key
: the varchar field in a temp variable or something so when the new record
: is created it can just copy the data there.  Any help is appreciated.

The difficult aspect of this is the fact that only one record out of a
table is accessible at any one time. That means that once you move the
record pointer to another record, that data from the original record is
no longer available. So if this new record is the one into which you want
to carry data forward into, you would not have the other record's data at
hand.

If you could be sure that the "other" record would always be the preceding
one, this might be simple: just use another TTable pointing to the same
table, move to the current record, move back one record, and extract the
data. But moving through a table is almost always multi-directional. Worse
would be the case of data displayed in a TDBGrid, where you could arrive
at a new record from any number of other records, contiguous or 1,000
records away.

So how to "remember" needed values from the last record accessed? One way
might be to use a Pascal record with fields of names and types to corre-
spond to the fields in a table record. Then, on arriving at a new record,
the field values would be stored into the record. Actually, this would
require two such records, one to store the new record's data and one to
store the last accessed record. Before each new record is stored into the
Pascal record, the current one would be copied to the secondary Pascal
record so as not to be displaced by the new, incoming table record. This
storing process could be effected in the OnDataChange event procedure of
the TDataSource component.

Once at the new record, a keystroke might be provided the end-user to
trigger the copying of "remembered" data into the current table record.
On the occurrence of that keystroke, the program would copy the data
from the Pascal record into the fields of the table record.

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ Steve Koterski               _/   The opinions expressed here are    _/
_/ koter...@borland.com         _/         exclusively my own           _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Re:copying data from one record to the next when inserting a new record


Quote
koterski@genghis (Steve Koterski) wrote:
>CHAD A LIND (cal...@cacd.rockwell.com) wrote:
>:   I would like to know if there is a way to copy one field of a
>: record to a newly created record.  I am using Interbase 3.3 server
>: version.  I have an OnNewRecord event for one of my tables and would
>: the data from the previous records VarChar field of length 32000
>: to be copied to the newly created field.  Is there an easy way to key
>: the varchar field in a temp variable or something so when the new record
>: is created it can just copy the data there.  Any help is appreciated.
>The difficult aspect of this is the fact that only one record out of a
>table is accessible at any one time. That means that once you move the
>record pointer to another record, that data from the original record is
>no longer available. So if this new record is the one into which you want
>to carry data forward into, you would not have the other record's data at
>hand.
>If you could be sure that the "other" record would always be the preceding
>one, this might be simple: just use another TTable pointing to the same
>table, move to the current record, move back one record, and extract the
>data. But moving through a table is almost always multi-directional. Worse
>would be the case of data displayed in a TDBGrid, where you could arrive
>at a new record from any number of other records, contiguous or 1,000
>records away.
>So how to "remember" needed values from the last record accessed? One way
>might be to use a Pascal record with fields of names and types to corre-
>spond to the fields in a table record. Then, on arriving at a new record,
>the field values would be stored into the record. Actually, this would
>require two such records, one to store the new record's data and one to
>store the last accessed record. Before each new record is stored into the
>Pascal record, the current one would be copied to the secondary Pascal
>record so as not to be displaced by the new, incoming table record. This
>storing process could be effected in the OnDataChange event procedure of
>the TDataSource component.
>Once at the new record, a keystroke might be provided the end-user to
>trigger the copying of "remembered" data into the current table record.
>On the occurrence of that keystroke, the program would copy the data
>from the Pascal record into the fields of the table record.

Steve, could you not use two TTable components and keep the 'old' data attached
to one via a bookmark and just transfer from one set of field arrays to the
other?

- Show quoted text -

Quote
>--
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>_/ Steve Koterski               _/   The opinions expressed here are    _/
>_/ koter...@borland.com         _/         exclusively my own           _/
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Re:copying data from one record to the next when inserting a new record


Quote
Steve Koterski wrote:
>Before each new record is stored into the
>Pascal record, the current one would be copied to the secondary Pascal
>record so as not to be displaced by the new, incoming table record. This
>storing process could be effected in the OnDataChange event procedure of
>the TDataSource component.

>Once at the new record, a keystroke might be provided the end-user to
>trigger the copying of "remembered" data into the current table record.
>On the occurrence of that keystroke, the program would copy the data
>from the Pascal record into the fields of the table record.

Would there be a way to set up an array based on reading the structure of
the table?  Then copying the contents of a selected record to this array,
asking the user for the new index value(s), then inserting a record with
the new index values and the selected record's field values?

Thanks,
Paul Rice

Re:copying data from one record to the next when inserting a new record


Quote
koterski@genghis (Steve Koterski) wrote:
>CHAD A LIND (cal...@cacd.rockwell.com) wrote:
>:   I would like to know if there is a way to copy one field of a
>: record to a newly created record.  I am using Interbase 3.3 server
>: version.  I have an OnNewRecord event for one of my tables and would
>: the data from the previous records VarChar field of length 32000
>: to be copied to the newly created field.  Is there an easy way to key
>: the varchar field in a temp variable or something so when the new record
>: is created it can just copy the data there.  Any help is appreciated.
>The difficult aspect of this is the fact that only one record out of a
>table is accessible at any one time. That means that once you move the
>record pointer to another record, that data from the original record is
>no longer available. So if this new record is the one into which you want
>to carry data forward into, you would not have the other record's data at
>hand.
>If you could be sure that the "other" record would always be the preceding
>one, this might be simple: just use another TTable pointing to the same
>table, move to the current record, move back one record, and extract the
>data. But moving through a table is almost always multi-directional. Worse
>would be the case of data displayed in a TDBGrid, where you could arrive
>at a new record from any number of other records, contiguous or 1,000
>records away.
>So how to "remember" needed values from the last record accessed? One way
>might be to use a Pascal record with fields of names and types to corre-
>spond to the fields in a table record. Then, on arriving at a new record,
>the field values would be stored into the record. Actually, this would
>require two such records, one to store the new record's data and one to
>store the last accessed record. Before each new record is stored into the
>Pascal record, the current one would be copied to the secondary Pascal
>record so as not to be displaced by the new, incoming table record. This
>storing process could be effected in the OnDataChange event procedure of
>the TDataSource component.
>Once at the new record, a keystroke might be provided the end-user to
>trigger the copying of "remembered" data into the current table record.
>On the occurrence of that keystroke, the program would copy the data
>from the Pascal record into the fields of the table record.

Steve, could you not use two TTable components and keep the 'old' data attached
to one via a bookmark and just transfer from one set of field arrays to the
other?

- Show quoted text -

Quote
>--
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>_/ Steve Koterski               _/   The opinions expressed here are    _/
>_/ koter...@borland.com         _/         exclusively my own           _/
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Other Threads