Mega Code Archive

 
Categories / Delphi / System
 

Copy Record with Error Log

Title: Copy Record with Error Log Question: This article shows how to copy a data record from one table to another while catching all errors. Answer: This procedure will copy all destination table fields that are found in the source table. Source table fields that do not exists in the destination table will not be copied. A log of all problems (when an exception is thrown) is accumulated. The example below places an error message into a TListBox. The Source and Destination tables do not have to be the same Brand of table. This can be used to convert from one database to another. Source Code: procedure CopyRecord(aSource : TTable; aDestination : TDBISAMTable); var nCount : integer; begin for nCount := 0 to aDestination.FieldCount - 1 do begin try aDestination.FindField(aSource.Fields[nCount].FieldName).Assign(aSource.FieldByName(aSource.Fields[nCount].FieldName)); except on E: Exception do listboxStatus.Items.Add(aDestination.TableName + '- ' + E.Message); end; end; end;