有一主窗体FORM1.在此窗体上有一个DBGRID,当我双击DBGRID上的某一条记录时,弹出另外一个窗体FORM2以便修改,在FORM2上显示此记录的各字段.这个过程我是这样写的,双击完DBGRID后调用FORM2,在FORM2的ONSHOW事件中再调用FORM1.QUERY1(EDIT1.TEXT:=FORM1.QUERY1.FIELDBYNAME('员工姓名').ASSTRING;),这样调用可以.修改完记录后当我单击FORM2上的保存,就提示:QUERY1是什么只读的,详细的堤示如下:project rs1.exe raised exception class edatabaseerror with message'query1:cannot modify aread-only dataset'.process stopped.use step or run to continue.我在FORM1上还有一个QUERY2都用的是同一个数据库,是不是这个原因呀,请大仙多多指教.

解决方案 »

  1.   

    保存之前加一个query1.sql.clear
    或者干脆另用一个query
      

  2.   

    procedure TForm3.Button1Click(Sender: TObject);
    begin
      if form1.query2.status in [dsinsert,dsedit]  then
      form1.query2.post;
    end;
      

  3.   

    楼上的老大,能解释下:FORM2.STATUS IN [DSINSERT,DSEDIT] THEN是什么意思吗?
    怎么用呀?
      

  4.   

    这是俺的你试试:
    procedure TForm3.Button1Click(Sender: TObject);
    begin
      with table1 do
       begin
          open;
          while not eof do
          begin
             if (edit3.Text=fieldByName('员工姓名').AsString) then
             begin
                edit;
                fieldValues['现任职务']:=edit68.Text;
                //fieldValues['拨款日期']:=dt.Date;
                //fieldValues['用途']:=note.Text;
                post;
                showMessage('修改数据成功!');
                //refreshDbGrid;
                close;
                exit;
             end;
             next;
          end;//end of while
          close;
          showMessage('数据修改失败!');
       end;//end of with
    end;