procedure TForm1.Button1Click(Sender: TObject); begin if(trim(edit1.Text)<>'') and (trim(edit2.Text)<>'') and (trim(edit3.Text)<>'') then begin with form1.table1 do begin first; while not eof do begin if(edit3.Text=fieldbyname('账号').AsString) then showmessage('该账号已经存在!') else begin edit; append; fieldbyname('账号').AsString:=edit3.Text; fieldbyname('姓名').AsString:=edit1.Text; fieldbyname('密码').AsString:=edit2.Text; post; Refresh; showmessage('注册成功!'); break; end; end; end; ss:=form1.Table1.FieldByName('学号').AsString; form3.Table1.Edit; form3.Table1.FieldByName('学号').AsString:=ss; form3.table1.Post; form4.Table1.Edit; form4.Table1.FieldByName('学号').AsString:=ss; form4.table1.Post; form5.Table1.Edit; form5.Table1.FieldByName('学号').asstring:=ss; form5.table1.Post; form6.Table1.Edit; form6.Table1.FieldByName('学号').asstring:=ss; form6.table1.Post;
while not eof do begin if(edit3.Text=fieldbyname('账号').AsString) then showmessage('该账号已经存在!') else begin edit; append; fieldbyname('账号').AsString:=edit3.Text; fieldbyname('姓名').AsString:=edit1.Text; fieldbyname('密码').AsString:=edit2.Text; post; Refresh; showmessage('注册成功!'); break; end; next;//若第一个不同,那你难道一直比较第一个? end; 况这段本身就不严谨 var f:boolean; f:=false; whil not table1.eof and not f do//当表没结束或者没找到相同的时候循环 begin if fieldbyname('账号').asstring=edit3.text then f:=true;//相同记录了,那就赋真值,退出循环 next;//逐条对比 end; if not f then begin //append 进 table1中。