TPath を利用する - Delphi 2010

Delphi2010では TPathクラスが新しくできました。
以下のコードでは、ファイルパスから拡張子を取り出す例です。
以前は、SysUtils.ExtractFileNameを使いましたが、TPath.GetExtensionでも同じことができます。
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IoUtils, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Caption:=TPath.GetExtension('C:\dev\info.xml');
end;

end.
著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
掲載日: 2009-09-02
iPentec all rights reserverd.