【真的很奇怪!请大家帮忙看看】从一数据表复制数据到另一表,其他字段都正常,只有:“names”字段无法复制,要么就是干脆没有数据,要么就是偶尔有几个英文字母和乱码。而且将几个可以看清楚的字母连起来竟然是“table2”,正好是该表的数据组件的名字,谁能告诉我这是为什么?procedure TForm1.Button3Click(Sender: TObject);
var
I,n,m:integer;
number,names,sex,brithday,address,hphone,business,mobile,party:array of string;
begin
n:=table1.RecordCount;
SetLength(number,n);
SetLength(names,n);
SetLength(sex,n);
SetLength(brithday,n);
SetLength(address,n);
SetLength(hphone,n);
SetLength(business,n);
SetLength(mobile,n);
SetLength(party,n);
Query1.First;
For I:=1 to n do
begin
number[I-1]:=Query1.FieldByName('number').AsString;
names[I-1]:=Query1.FieldByName('name').AsString;
sex[I-1]:=Query1.FieldByName('sex').AsString;
brithday[I-1]:=Query1.FieldByName('brithday').AsString;
address[I-1]:=Query1.FieldByName('address').AsString;
hphone[I-1]:=Query1.FieldByName('hphone').AsString;
business[I-1]:=Query1.FieldByName('business').AsString;
mobile[I-1]:=Query1.FieldByName('mobile').AsString;
party[I-1]:=Query1.FieldByName('party').AsString;
Query1.next;
end;
With table2 do
begin
Active:=False; DatabaseName := 'mydata';
TableType := ttParadox;
TableName := 'dataprn.db';
Emptytable;
Active:=False;
Active:=True; For I:=1 to n do
begin
Append;
fieldByName('number').AsString:=number[I-1];
fieldByName('names').AsString:=name[I-1];
fieldByName('sex').AsString:=sex[I-1];
fieldByName('brithday').AsString:=brithday[I-1];
fieldByName('address').AsString:=address[I-1];
fieldByName('hphone').AsString:=hphone[I-1];
fieldByName('business').AsString:=business[I-1];
fieldByName('mobile').AsString:=mobile[I-1];
fieldByName('party').AsString:=party[I-1];
post;
end;
m:=n mod 58;
If m<>0 then
m:=58-m;
For I:=1 to m do
begin
Append;
Post;
end;
First; end;
end;
var
I,n,m:integer;
number,names,sex,brithday,address,hphone,business,mobile,party:array of string;
begin
n:=table1.RecordCount;
SetLength(number,n);
SetLength(names,n);
SetLength(sex,n);
SetLength(brithday,n);
SetLength(address,n);
SetLength(hphone,n);
SetLength(business,n);
SetLength(mobile,n);
SetLength(party,n);
Query1.First;
For I:=1 to n do
begin
number[I-1]:=Query1.FieldByName('number').AsString;
names[I-1]:=Query1.FieldByName('name').AsString;
sex[I-1]:=Query1.FieldByName('sex').AsString;
brithday[I-1]:=Query1.FieldByName('brithday').AsString;
address[I-1]:=Query1.FieldByName('address').AsString;
hphone[I-1]:=Query1.FieldByName('hphone').AsString;
business[I-1]:=Query1.FieldByName('business').AsString;
mobile[I-1]:=Query1.FieldByName('mobile').AsString;
party[I-1]:=Query1.FieldByName('party').AsString;
Query1.next;
end;
With table2 do
begin
Active:=False; DatabaseName := 'mydata';
TableType := ttParadox;
TableName := 'dataprn.db';
Emptytable;
Active:=False;
Active:=True; For I:=1 to n do
begin
Append;
fieldByName('number').AsString:=number[I-1];
fieldByName('names').AsString:=name[I-1];
fieldByName('sex').AsString:=sex[I-1];
fieldByName('brithday').AsString:=brithday[I-1];
fieldByName('address').AsString:=address[I-1];
fieldByName('hphone').AsString:=hphone[I-1];
fieldByName('business').AsString:=business[I-1];
fieldByName('mobile').AsString:=mobile[I-1];
fieldByName('party').AsString:=party[I-1];
post;
end;
m:=n mod 58;
If m<>0 then
m:=58-m;
For I:=1 to m do
begin
Append;
Post;
end;
First; end;
end;
....
fieldByName('names').AsString:=name[I-1];
是不是写错了,前面是names[I-1],后面变成了name[I-1]:=
建议定义变量的时候,最好不要使用
单个或单个单词的数作为变量
如:names->MyNames或者AName