unit SystemRename;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: SystemRename
// Routine: System.Rename

// BeginCode
{
This example requires a button, an open dialog and a save
dialog.  Click the button to rename a file.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  f : file;
begin
  OpenDialog1.Title := 'Choose a file... ';
  if OpenDialog1.Execute then
  begin
    SaveDialog1.Title := 'Rename to...';
    if SaveDialog1.Execute then 
    begin 
      AssignFile(f, OpenDialog1.FileName);
      Canvas.TextOut(5, 10, 'Renaming ' + OpenDialog1.FileName + 
                     ' to ' + SaveDialog1.FileName);
      Rename(f, SaveDialog1.FileName);
    end;
  end;
end;
// EndCode
// EndExample: SystemRename
end.
