从网上找到了以下一段获取文件扩展名的代码,试了一下只能获取后缀为3个字母的文件扩展名。 
var
sun:string;
moon:string;
begin
if (opendialog1.execute) then
moon:=opendialog1.filename;
sun:=GetFileExtension(moon);
end;
function TForm1.GetFileExtension(const moon:string):string;
begin
result:=copy(fnOle,Length(moon)-2,3);
end;

解决方案 »

  1.   

    这函数写的,要自己写至少也应该用pos查找'.'吧用ExtractFileExt试试吧
      

  2.   


    ExtractFileExt(文件名),返回后缀,带'.'
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        OpenDialog1: TOpenDialog;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    function ExtractFileExt(const FileName: string): string;  //问题在这里
    var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    moon:string;
    begin
    if (opendialog1.execute) then
    moon:=opendialog1.filename;
    Edit1.Text:=ExtractFileExt(moon);
    end;end.
    编译通不过,显示下列信息:
    [Error] Unit1.pas(20): Unsatisfied forward or external declaration: 'ExtractFileExt'
    [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
      

  4.   


    function ExtractFileExt(const FileName: string): string;  //问题在这里 
    这句去掉就好了,因为ExtractFileExt在SysUtils单元里有了