procedure TForm1.Button1Click(Sender: TObject); begin OpenDialog1.Filter := 'Text files (*.txt)|*.txt|Delphi Source files (*.pas)|*.pas|All files (*.*)|*.*'; if not OpenDialog1.Execute then Exit; case OpenDialog1.FilterIndex of 1: ShowMessage('*.txt'); 2: ShowMessage('*.pas'); 3: ShowMessage('*.*'); end; end;
begin
OpenDialog1.Filter := 'Text files (*.txt)|*.txt|Delphi Source files (*.pas)|*.pas|All files (*.*)|*.*';
if not OpenDialog1.Execute then Exit;
case OpenDialog1.FilterIndex of
1: ShowMessage('*.txt');
2: ShowMessage('*.pas');
3: ShowMessage('*.*');
end;
end;
所以你可以用
s:=copy(opendialog1.filename,length(opendialog1.filename)-2,3);
s:='*.'+s;