关于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;
.....
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); //这里