首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于TopenDialog组件的有关问题

2013-09-28 
关于TopenDialog组件的问题我放了一个opendialog组件,写了同样一段程序,在xp环境下会起作用,会有提示‘不是

关于TopenDialog组件的问题
我放了一个opendialog组件,写了同样一段程序,在xp环境下会起作用,会有提示‘不是文本文件’,在win7下就不会提示。

procedure TForm10.ToolButton1Click(Sender: TObject);
var
  fname:string;
begin
  with OpenDialog1 do
  begin
    Filter:='文本文件 .txt';
    DefaultExt:= 'ini';
    FileName:= '';
    Options:= [ofHideReadOnly,ofFileMustExist,ofPathMustExist] ;
    if Execute then
    begin
      if ofExtensionDifferent in Options then
        MessageDlg('这不是文本文件',mtWarning,[mbYes],0)
      else
      begin
        RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);
        fname:= OpenDialog1.FileName;
        StatusBar1.Panels[3].Text:= fname;
      end;
    end;
  end;
end;


1、问题是ofExtensionDifferent in Options不可能为true,因为前面options已经赋值了,不包含ofExtensionDifferent这个枚举,无法理解。

2、为什么在win7这个条件ofExtensionDifferent in Options就始终是false,求教育。
[解决办法]

    .....
    TOpenDialog.Execute里的代码,后面修改了FOptions的值,
    Result := TaskModalDialog(Func, OpenFileName);
    if Result then
    begin
      GetFileNames(OpenFilename);
      if (Flags and OFN_EXTENSIONDIFFERENT) <> 0 then
        Include(FOptions, ofExtensionDifferent) else  //这里
        Exclude(FOptions, ofExtensionDifferent); //这里

热点排行