function TForm1.MyRecordScatTo(DataSet0:TDataSet;var MyDynamic_Record0:Variant):boolean; //正确 返回TRUE,否则为FALSE //功能:读取(当前记录)字段值存入动态数组中 var i:integer; begin try i:=DataSet0.FieldCount; //取字段数 MyDynamic_Record0:=VarArrayCreate([0,i],varVariant); //MyVariant if (not DataSet0.Active) //or(DataSet0.eof) then begin MessageBeep(MB_OK); MessageDlg('当前为空记录,无法使用"携带"!',mtError, [mbOk], 0); Result:=false; Exit; end; with DataSet0 do //DBGrid0 begin for i:=0 to FieldCount-1 do begin if Fields[i].DataType<>ftMemo //非"备注"型数据 then MyDynamic_Record0[i]:=Fields[i].Value; end; //for i: end; Result:=true; except Result:=false end //try end; // MyRecordScatTo
function TForm1.MyRecordGatherFrom(DataSet0:TDataSet;var MyDynamic_Record0:Variant):boolean; // 正确返回TRUE,否则为FALSE //功能:从动态数组中获取相应值,来更改(当前记录)字段值 var i:integer; begin Result:=true; with DataSet0 do // begin try for i:=0 to FieldCount-1 do begin //Edit; if (Fields[i].DataType<>ftMemo) //非"备注"型数据 then Fields[i].Value:=MyDynamic_Record0[i]; end; //for i except Result:=false; end //try end; end; // MyRecordGatherFrom
procedure TForm1.My_TablePostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction;sFieldName:string); //功能:保存时数据错误信息捕捉 var sMes:string; begin MessageBeep(0); //以下捕捉"错误信息" sMes:='当前记录非法!更正后再保存。'; if Pos(UpperCase('key violation'),UpperCase(e.Message))<>0 then sMes:='"'+sFieldName+'"内容重复,请更改后再保存!'; if Pos(UpperCase('must have a value'),UpperCase(e.Message))<>0 then sMes:='当前栏目必须输入值!';// '"'+sFieldName+'"字段必须输入值!'; sMes:=sMes+Chr(13)+Chr(10)+'(Esc键取消操作)'; MessageDlg(sMes,mtError, [mbOk], 0); Action:=daAbort; //放弃编辑且不显示错误信息 end; //调用通用表数据处理模块 |