Board index » delphi » Copying a record from one Ttable to another

Copying a record from one Ttable to another

Hi,

I've got a program that does a lot of data manipulation on a table
that may have upwards of 10,000+ records and at many stages during the
process I copy the records from the original table to another table to
split records off depending on their contents.

However - currently to do this, I'm probably doing it the hard way.
I'm copying the records from one Ttable to the other field by field.
I'm sure it's possible using a batchcopy or something but I couldn't
work it out for just one record.

Another factor that may get in the way is that the Ttables don't
normally have the same field order or number of fields.

Suggestions, please email me.

Cheers,

  - Bob -

(remove "nospam" in email address to reply)

---
Bob Brown, Computer Programmer/Tutor/Guru etc etc.
Email: bo...@clear.net.nz, BBS: +646-843-2435
http://home.clear.net.nz/pages/bob.b

 

Re:Copying a record from one Ttable to another


In article <3531ce73.7902...@news.xtra.co.nz>,

Quote
Bob Brown <bo...@nospam.clear.net.nz> wrote:
>Hi,

>I've got a program that does a lot of data manipulation on a table
>that may have upwards of 10,000+ records and at many stages during the
>process I copy the records from the original table to another table to
>split records off depending on their contents.

>However - currently to do this, I'm probably doing it the hard way.
>I'm copying the records from one Ttable to the other field by field.
>I'm sure it's possible using a batchcopy or something but I couldn't
>work it out for just one record.

>Another factor that may get in the way is that the Ttables don't
>normally have the same field order or number of fields.

>Suggestions, please email me.

>Cheers,

>  - Bob -

>(remove "nospam" in email address to reply)

>---
>Bob Brown, Computer Programmer/Tutor/Guru etc etc.
>Email: bo...@clear.net.nz, BBS: +646-843-2435
>http://home.clear.net.nz/pages/bob.b

Try this.  It copies the fields one by one, but it doesn't care
about order or if the "To" table has the same fields or not.
It assume the "To" table is in an Edit state.

- David

{------------------------------------------------------------------------------}
procedure CopyCurrentRecord( FromTable, ToTable: TTable );
var
  FieldNameList: TStringList;
  FieldName: string;
  AField: TField;
  I: integer;
begin
  FieldNameList := TStringList.Create;
  try { finally }
    ToTable.GetFieldNames(FieldNameList);
    try { except }
      for I := 0 to FieldNameList.Count - 1 do
      begin
        FieldName := FieldNameList.Strings[I];
        AField := FromTable.FindField(FieldName);
        if AField <> nil then
          ToTable.FieldByName(FieldName).Assign(AField);
      end;
    except
      MessageDlg('Could not copy record from ' +
        FromTable.Name + ' to ' + ToTable.Name + '.', mtError, [mbOK], 0);
    end; { try }
  finally
    FieldNameList.Free;
  end;
end; { CopyCurrentRecord }

Re:Copying a record from one Ttable to another


You can probably use BatchMove.  There is a property called RecordCount that
allows you to tell it how many records to copy.  There is also a Mappings
property that allows you to "Map" fields.

Quote
Bob Brown wrote in message <3531ce73.7902...@news.xtra.co.nz>...
>Hi,

>I've got a program that does a lot of data manipulation on a table
>that may have upwards of 10,000+ records and at many stages during the
>process I copy the records from the original table to another table to
>split records off depending on their contents.

>However - currently to do this, I'm probably doing it the hard way.
>I'm copying the records from one Ttable to the other field by field.
>I'm sure it's possible using a batchcopy or something but I couldn't
>work it out for just one record.

>Another factor that may get in the way is that the Ttables don't
>normally have the same field order or number of fields.

>Suggestions, please email me.

>Cheers,

>  - Bob -

>(remove "nospam" in email address to reply)

>---
>Bob Brown, Computer Programmer/Tutor/Guru etc etc.
>Email: bo...@clear.net.nz, BBS: +646-843-2435
>http://home.clear.net.nz/pages/bob.b

Re:Copying a record from one Ttable to another


Bob:

Your application is a perfect case to use batchmove.  You can set up
the parameters for the move, loop through your source database, and if
you decide you want to move that record, use batch move to do it.

Drop me a note if you would like some example code.

Dave Draffin
Software Innovations Technical Support
Maple Valley, WA USA
avg...@earthlink.net

On 13 Apr 1998 10:56:24 -0500, dhar...@Starbase.NeoSoft.COM (David

Quote
Harper) wrote:
>In article <3531ce73.7902...@news.xtra.co.nz>,
>Bob Brown <bo...@nospam.clear.net.nz> wrote:
>>Hi,

>>I've got a program that does a lot of data manipulation on a table
>>that may have upwards of 10,000+ records and at many stages during the
>>process I copy the records from the original table to another table to
>>split records off depending on their contents.

>>However - currently to do this, I'm probably doing it the hard way.
>>I'm copying the records from one Ttable to the other field by field.
>>I'm sure it's possible using a batchcopy or something but I couldn't
>>work it out for just one record.

>>Another factor that may get in the way is that the Ttables don't
>>normally have the same field order or number of fields.

>>Suggestions, please email me.

>>Cheers,

>>  - Bob -

>>(remove "nospam" in email address to reply)

>>---
>>Bob Brown, Computer Programmer/Tutor/Guru etc etc.
>>Email: bo...@clear.net.nz, BBS: +646-843-2435
>>http://home.clear.net.nz/pages/bob.b

>Try this.  It copies the fields one by one, but it doesn't care
>about order or if the "To" table has the same fields or not.
>It assume the "To" table is in an Edit state.

>- David

>{------------------------------------------------------------------------------}
>procedure CopyCurrentRecord( FromTable, ToTable: TTable );
>var
>  FieldNameList: TStringList;
>  FieldName: string;
>  AField: TField;
>  I: integer;
>begin
>  FieldNameList := TStringList.Create;
>  try { finally }
>    ToTable.GetFieldNames(FieldNameList);
>    try { except }
>      for I := 0 to FieldNameList.Count - 1 do
>      begin
>        FieldName := FieldNameList.Strings[I];
>        AField := FromTable.FindField(FieldName);
>        if AField <> nil then
>          ToTable.FieldByName(FieldName).Assign(AField);
>      end;
>    except
>      MessageDlg('Could not copy record from ' +
>        FromTable.Name + ' to ' + ToTable.Name + '.', mtError, [mbOK], 0);
>    end; { try }
>  finally
>    FieldNameList.Free;
>  end;
>end; { CopyCurrentRecord }

Dave Draffin
Software Innovations Technical Support
Maple Valley, WA USA
avg...@earthlink.net

Other Threads