这个事件 对每个字段都处理,在窗体退出时,因关闭了数据集,所以这个事件也要执行一次。这样就会造成,内存地址错误。
procedure TFrmYaoKYPCKBL.DataSource1DataChange(Sender: TObject; Field: TField);
begin inherited; ShowMessage('ds');if Query1YiJSZ.Value = 1 then
begin TB_Save.Enabled := False; TB_ShangZ.Enabled := False; TB_Delete.Enabled := False; btnSave.Enabled := False; btnShangZ.Enabled := False;DBComboBox2.Enabled := False;
DBEdit3.Enabled := False;DBGrideh1.readonly := True;
btnErase.Enabled := False; end else begin TB_Save.Enabled := True; TB_ShangZ.Enabled := True; TB_Delete.Enabled := True; btnSave.Enabled := True; if not _ChuKMXModified then begin btnShangZ.Enabled := True; end else begin btnShangZ.Enabled := False; end;end;
而表的滚动事件,则不会在窗体关闭时执行。只是有数据时才执行。 所处程序除非必要检查特定字段,不要在datasource事件内写东西。
procedure TFrmYaoKYPCKBL.Query1AfterScroll(DataSet: TDataSet);
begin inherited;if Query1YiJSZ.Value = 1 then
begin TB_Save.Enabled := False; TB_ShangZ.Enabled := False; TB_Delete.Enabled := False; btnSave.Enabled := False; btnShangZ.Enabled := False;DBComboBox2.Enabled := False;
DBEdit3.Enabled := False;DBGrideh1.readonly := True;
btnErase.Enabled := False; end else begin TB_Save.Enabled := True; TB_ShangZ.Enabled := True; TB_Delete.Enabled := True; btnSave.Enabled := True; if not _ChuKMXModified then begin btnShangZ.Enabled := True; end else begin btnShangZ.Enabled := False; end;DBComboBox2.Enabled := False;
DBEdit3.Enabled := True;DBGrideh1.readonly := False;
btnErase.Enabled := True; end;end;