if ofextensiondifferent in Options then上面这句话能用不同的方式写吗?为什么莫名其妙多个in这是一个opendialog的组件中options的ofextensiondifferent源代码如下  with dlgOpen1 do
  begin
    Filter:='文本文件(*.txt)|*.txt';
    DefaultExt:='txt';
    FileName:='';
    if Execute then
     if ofextensiondifferent in Options then        MessageDlg('这不是文本文件!',mtError,mbOKCancel,0)
     else
        mmo1.Lines.LoadFromFile(FileName);
  end;

解决方案 »

  1.   

    TOpenDialog中的Options属性里,可以并存多个选择,好比一个班里有“张三”和“李四”一样,

    Options := [ofHideReadOnly, ofEnableSizing]; 
    那么,要判断选项中是否包含了“ofextensiondifferent” 就得
    “if ofextensiondifferent in Options then”这样判断了(好比判断张三是否在三班呢),
    而不能用
    “if Options =ofextensiondifferent then”这样的方式(好比判断三班是否等于李四),
    就算要判断选项是否仅一个“ofextensiondifferent”选择,也只能如此判断:
    “if OpenDialog1.Options=[ofextensiondifferent] then”(好比判断是否仅张三在三班里)。
      

  2.   

    当遇到序数类型或集合类型的场合,就有可能出现要使用“in”这种运算符,如:
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      //如果按键的值不在序数'0'..'9'及退格、回车时,消除输入:
      if not(key in ['0'..'9',#8,#13])then key:=#0;
    end;建议到万一老师的博客看看:http://www.cnblogs.com/del/archive/2007/12/10/989467.html,他的博客内容分类比较清晰,涉及范围比较全,分析也比较透切,是个学习的好地方。