if (RecordCount>=2) or (RecordCount=1) and (fieldvalues['RS_id']<>datasource1.DataSet.FieldValues['RS_id']) then
begin
showmessage('工号有重复,请更换工号!');
dbediteh1.SetFocus;
abort;
exit;
end;
1.这是做了一个临时的ADO访问数据库数据集,当输入一个ADO访问控件时有重复工号就会报对话框出来,但是if那几个语句我想不明白,为什么在这个情况下就会重复。procedure TFrmPersonEdit.DBComboBoxEh3Change(Sender: TObject);
begin
inherited;
if not (datasource1.DataSet.State in [dsInsert,dsEdit]) then exit;
if dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.text)<>-1 then
if dbcomboboxeh4.Items.Count>dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text) then
dbcomboboxeh4.Text:=dbcomboboxeh4.Items[dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text)];
end;
2.这是一个当改变一个COMBOBOXEH的ITEMS时另一个也跟着改变.但也是if的那几个语句我想不明白。注:IF语句用法我知道,我想知道为什么在这种情况下加每一句IF语句中的作用是什么?
begin
showmessage('工号有重复,请更换工号!');
dbediteh1.SetFocus;
abort;
exit;
end;
1.这是做了一个临时的ADO访问数据库数据集,当输入一个ADO访问控件时有重复工号就会报对话框出来,但是if那几个语句我想不明白,为什么在这个情况下就会重复。procedure TFrmPersonEdit.DBComboBoxEh3Change(Sender: TObject);
begin
inherited;
if not (datasource1.DataSet.State in [dsInsert,dsEdit]) then exit;
if dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.text)<>-1 then
if dbcomboboxeh4.Items.Count>dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text) then
dbcomboboxeh4.Text:=dbcomboboxeh4.Items[dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text)];
end;
2.这是一个当改变一个COMBOBOXEH的ITEMS时另一个也跟着改变.但也是if的那几个语句我想不明白。注:IF语句用法我知道,我想知道为什么在这种情况下加每一句IF语句中的作用是什么?
(RecordCount>=2) or (RecordCount=1)
如何不写成 RecordCount>=1)呢?
if (RecordCount>=2) or
( (RecordCount=1) and (fieldvalues['RS_id']<>datasource1.DataSet.FieldValues['RS_id']) ) then //注意多加了一对括号 if not (datasource1.DataSet.State in [dsInsert,dsEdit]) then exit;
表示如果这个数据集处于编辑或者插入状态,则不能操作,退出子程序;if dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.text)<>-1 表示dbcomboboxeh3的文本在dbcomboboxeh3的下拉列表中,因为你可能用键盘输入改变了dbcomboboxeh3.text,而它不是一个有效值,
dbcomboboxeh4.Items.Count>dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text)
保证下标不越界,如你定义一个:
MyValue:array[1..10] of integer;
你用MyValue[13]:=0;肯定会出错,
所以有这种写法 if (idx>0) and (idx<=10) then MyValue[idx]:=100;
应为
if ((RecordCount>=2) or (RecordCount=1)) and (fieldvalues['RS_id']<>datasource1.DataSet.FieldValues['RS_id']) then
-----------------------------------------------------------------------------
if dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.text)<>-1 then
if dbcomboboxeh4.Items.Count>dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text) then
dbcomboboxeh4.Text:=dbcomboboxeh4.Items[dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text)];
中 if dbcomboboxeh4.Items.Count>dbcomboboxeh3.Items.IndexOf(dbcomboboxeh3.Text) then
有问题
你还这样写呀?不就等价于if (RecordCount>=1)吗?