More specifically: when I first copy a table with e.g. 4 columns, then one with 3 columns, I get an error on tblTarget.Post that a field from the first table can't be found.
The code:
Code: Select all
procedure TfrmMain.CopyTabel(const TableName: String);
var
tblSource, tblTarget: TDataSet;
i: Integer;
ifield: Integer;
fieldname: string;
fldTarget: TField;
fldSource: TField;
begin
tblSource := sfmDCBron.GetTable(TableName); // see below
if Assigned(tblSource) then
begin
try
tblTarget := sfmDCDoel.GetTable(TableName);
if Assigned(tblTarget) then
begin
try
tblSource.First;
for i := 0 to tblSource.RecordCount - 1 do
begin
tblTarget.Append;
for ifield := 0 to tblSource.FieldCount - 1 do
begin
fieldname := tblSource.Fields[ifield].fieldname;
fldSource := tblSource.Fields[ifield];
if not fldSource.IsNull then
begin
fldTarget := nil;
try
fldTarget := tblTarget.FieldByName(fieldname);
except
if LowerCase(fieldname) <> 'rowid' then
raise;
end;
if fldTarget <> nil then
begin
if (fldTarget.DataType = ftDate) OR (fldTarget.DataType = ftDateTime) OR (fldTarget.DataType = ftTime) then
fldTarget.AsDateTime := fldSource.AsDateTime
else
fldTarget.AsString := fldSource.AsString;
end;
end;
end;
tblTarget.Post;
tblSource.Next;
end;
finally
tblTarget.Close;
end;
end;
finally
tblSource.Close;
end;
end;
end;
Code: Select all
try
oratable.TableName := TableName; // of type TOraTable
oratable.Open;
Result := oratable;
except
Result := nil;
end;
Code: Select all
create table a ( a integer not null, b integer, c integer );
alter table a add constraint pk_a primary key ( a );
create table x ( x integer not null, y integer );
alter table x add constraint pk_x primary key ( x );
insert into a ( a, b, c ) values ( 1, 2, 3 );
insert into a ( a, b, c ) values ( 2, 3, 4 );
insert into a ( a, b, c ) values ( 3, 4, 5 );
insert into x ( x, y ) values ( 1, 2 );
Is this expected? That seems unlikely since it used to work fine. Any suggestions?
Thanks, regards, Miel.