有一个dbgrid中有一个‘审核’字段,当一条记录被审核后就不允许对这条记录做任何修改
后一种解决方法是:
procedure Tpartno_add.ADOTable1AfterScroll(DataSet: TDataSet);
begin
if adotable1.FieldByName('审核').AsBoolean=true then
adotable1.ReadOnly:=true
else adotable1.ReadOnly:=false;
end;
设置AfterScroll事件,但是这个事件好像只有当记录移动后才会发生,当我们开始打窗口时adotbale的记录是在第一条,也就是说当第一个条记录被审核了,但依然可以修改,而被审核的第二条记录起才不能修改,
我想原因是adotbale打开后,记录停在第一条记录,不触发AfterScroll事件
不知道还有什么更完美的解决方法?
后一种解决方法是:
procedure Tpartno_add.ADOTable1AfterScroll(DataSet: TDataSet);
begin
if adotable1.FieldByName('审核').AsBoolean=true then
adotable1.ReadOnly:=true
else adotable1.ReadOnly:=false;
end;
设置AfterScroll事件,但是这个事件好像只有当记录移动后才会发生,当我们开始打窗口时adotbale的记录是在第一条,也就是说当第一个条记录被审核了,但依然可以修改,而被审核的第二条记录起才不能修改,
我想原因是adotbale打开后,记录停在第一条记录,不触发AfterScroll事件
不知道还有什么更完美的解决方法?
因为我在所有数据库组放入一个DataModule,而我又在DataModule中判断formA用户的权限有多大,用户权限在formA中是一个全局公共变量,但在DataModule中不能访问这个变量,这是为什么呢?
这种事情怎么能在滚动里写(滚动里检测思路就是不对的)
应该在 BeforePost ,BeforeEdit 里写不行就 Abort;procedure Tpartno_add.ADOTable1BeforePost(DataSet: TDataSet);
begin
if adotable1.FieldByName('审核').AsBoolean=true then
begin
ADOQuery1.Cancel;
Abort;
end;
end;
//看下面!
procedure Tpartno_add.ADOTable1BeforeEdit(DataSet: TDataSet);
begin
if adotable1.FieldByName('审核').AsBoolean=true then
begin
ADOTable1.Cancel;
Abort;
end;
end;
//行这个
“新连接”掉用事物
执行行下面的语句绑定到什么DB 控件上都行
select * from tablename with (rowlock) where 审核=True
这样数据库中在事物结束前
符合条件的记录就都被锁定了
可以用下面的方法
{
Fielid 对象有个 OnSetText 事件 可以单独处理你的哪个 '审核' 字段
TForm1.ADOTable1[字段名]SetText(Sender: TField;
const Text: String);Text是新的值(就是用户输入的)
这时Sender里的数据还是原来的;
如果 Sender.Value:= Text; 就可以写入了。
只要启用OnSetText 事件 不处理就写不进去。}
//比如这是审核字段
TForm1.ADOTable1[字段名]SetText(Sender: TField;
const Text: String);
Begin
if sender.AsBoolean<> true
Sender.Value:= Text;
end;//BeforeEdit 事件可以处理其他字段
procedure Tpartno_add.ADOTable1BeforeEdit(DataSet: TDataSet);
begin
if adotable1.FieldByName('审核').AsBoolean=true then
begin
ADOTable1.Cancel;
Abort;
end;
end;
//这样就应该没问题了!
Sender.Value:= Text;
XXXXX
if sender.AsBoolean<> true then
Sender.Value:= Text;
procedure TField.SetEditText(const Value: string);
begin
if Assigned(FOnSetText) then FOnSetText(Self, Value) else SetText(Value);
end;