两段代码就差一个操作符 一个报错 一个正常
报错 <list index out of bounds (-1)>
for I := FAdataSet.Fields.Count - 1 downto 0 do
begin
fldname := LowerCase(FAdataSet.Fields[i].FieldName);
FAdataSet.Fields[i].Visible := (not (Pos(fldname+';',LowerCase(FInvisibleFields))>0))
and (Pos(fldname+';',LowerCase(FvisibleFields))>0);
end; 正常
for I := FAdataSet.Fields.Count - 1 downto 0 do
begin
fldname := LowerCase(FAdataSet.Fields[i].FieldName);
FAdataSet.Fields[i].Visible := (not (Pos(fldname+';',LowerCase(FInvisibleFields))>0))
or (Pos(fldname+';',LowerCase(FvisibleFields))>0);
end;
报错 <list index out of bounds (-1)>
for I := FAdataSet.Fields.Count - 1 downto 0 do
begin
fldname := LowerCase(FAdataSet.Fields[i].FieldName);
FAdataSet.Fields[i].Visible := (not (Pos(fldname+';',LowerCase(FInvisibleFields))>0))
and (Pos(fldname+';',LowerCase(FvisibleFields))>0);
end; 正常
for I := FAdataSet.Fields.Count - 1 downto 0 do
begin
fldname := LowerCase(FAdataSet.Fields[i].FieldName);
FAdataSet.Fields[i].Visible := (not (Pos(fldname+';',LowerCase(FInvisibleFields))>0))
or (Pos(fldname+';',LowerCase(FvisibleFields))>0);
end;
条件1 or 条件2区别大了,前者判断条件1的时候如果为假这个时候估计条件2就不用判别了。 也就是说在and的情况下,从左往右检查条件是否满足,如果不满足则后面不用检测了。但是or的情况不一样,应该是都检测了。估计是这样的、