# Dal_CA实现数据校验

在上篇文章学习到Dal_CA有个检测ALIAS属性中的表是否被修改,现在来学习如何定位到表修改的行,进行数据校验. 有一个需求,校验Employees表的LastName 字段不能为空. 在生成的DAL_ca类中,找到勾子方法FieldValid,添加如下代码

Procedure FieldValid
  if empty(Employees.LastName)
   this.msg="姓名不能为空"
   return .f.
endif 
Endpro
1
2
3
4
5
6

以下为测试代码.

oDALCA=Newobject("DAL_Employees","dal_employees_ca.prg")
oDALCA.CursorFill(.T.)
oDALCA.Add()
Browse
if !oDALCA.Save()
 ?oDALCA.Msg
endif
1
2
3
4
5
6
7

返回值为.T. ,输出为姓名不能为空.