从网上找到了以下一段获取文件扩展名的代码,试了一下只能获取后缀为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;
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;
ExtractFileExt(文件名),返回后缀,带'.'
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'
function ExtractFileExt(const FileName: string): string; //问题在这里
这句去掉就好了,因为ExtractFileExt在SysUtils单元里有了