unithuifu.pas

来自「信号机测试信号管理软件 其中含有文件上传及修改数据库数据的功能」· PAS 代码 · 共 83 行

PAS
83
字号
unit Unithuifu;

interface

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

type
  TFormhuifu = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Formhuifu: TFormhuifu;

implementation
uses unitmodule;
{$R *.dfm}

Function GetLastFIXED:char;
var
  Ch : Char;
  S  : string;
begin
  for Ch := 'C' to 'Z' do
  begin
    s := Ch + ':\';
    if GetDriveType(PChar(s)) = DRIVE_FIXED then
    Begin
      Result:=ch;
    End;
  end;
End;

procedure TFormhuifu.Button1Click(Sender: TObject);
var
filename,copyfile:string;
NewFileName: string;
Msg: string;
NewFile: TFileStream;
OldFile: TFileStream;
begin
    copyfile:=GetLastFIXED+':\'+'signal_2007-07-06.mdb'; //暂定将它放在最后一个硬盘的盘符下,若要将它放在某一文件夹下,需先创建该文件
    filename:=ExtractFiledir(Application.ExeName)+'\'+'database'+'\'+'signal_2007-07-06.mdb';
    if  FileExists(copyfile)  then
    begin
    NewFileName := copyfile;
    Msg := Format('Copy %s to %s?', [copyfile, filename]);
    if MessageDlg(Msg, mtCustom, mbOKCancel, 0) = mrOK then           //弹出对话框,提示是否要复制
    begin
        datamodule2.ADOConnection1.Connected:=false;
         datamodule2.ADOConnection1.Free;
        OldFile := TFileStream.Create(copyfile, fmOpenRead or fmShareDenyWrite);
        try
        NewFile := TFileStream.Create(filename, fmCreate or fmShareDenyRead); //不能覆盖,被进程占用

            try
                NewFile.CopyFrom(OldFile, OldFile.Size);
            finally
                FreeAndNil(NewFile);
                showmessage('备份成功,原文件已被覆盖');
            end;
        finally
        FreeAndNil(OldFile);
        end;
    end;
    end
    else showmessage('最后一个硬盘没有数据库文件!');
end;



end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?