我在网上找到的一段sql备份带进度条代码,编译通过。备份成功后出错??? ( 积分: 100 )

  • 主题发起人 主题发起人 ecoming
  • 开始时间 开始时间
E

ecoming

Unregistered / Unconfirmed
GUEST, unregistred user!
我在网上找到的一段sql备份带进度条代码,编译通过。备份成功后出错?运行编译后的程序。备份成功后程序自动关闭了,为什么。谢谢各位高手大哥。谢谢。帮我看一看,代码如下:
unit Unit1;

interface

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

type
TForm3 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public

{ Public declarations }
end;

type
TBackupSink=class(TInterfacedobject,backupsink)//实现接口
function PercentComplete(const Message: WideString; Percent: Integer): HResult; stdcall;
function NextMedia(const Message: WideString): HResult; stdcall;
function Complete(const Message: WideString): HResult; stdcall;
end;

var
Form3: TForm3;
implementation

{$R *.dfm}

function TBackupSink.PercentComplete(const Message: WideString; Percent: Integer):HResult;
begin
Form3.ProgressBar1.Position:=percent;
result:=0;
end;

function TBackupSink.NextMedia(const Message: WideString):HResult;
begin
result:=-1;
end;

function TBackupSink.Complete(const Message: WideString):HResult;
begin
result:=1;
end;


procedure TForm3.Button1Click(Sender: TObject);
var
MySQLServer:SQLServer;
MyBackUp:BackUp2;
MyBackSink:TBackupSink;
FInterfaceConnection:integer;
BS:TBackupSink;
begin
BS:=TBackupSink.Create;
MySQLServer:=coSQLServer.Create;
MyBackUp:=coBackUp2.Create;
MySQLServer.Connect('HONGBIN','sa','');;
MyBackUp.Database:='hotelerp';
MyBackUp.Initialize:=true;
MyBackUp.PercentCompleteNotification:=1;
MyBackUp.Action:=0;//0完整备份,1差异备份,2文件组备份,3日志备份
MyBackUp.Files:='c:/hotelerp.bak';
InterfaceConnect(MyBackUp, IID_BackupSink, BS, FInterfaceConnection);//关键是这里
MyBackUp.SQLBackup (MySQLServer);
InterfaceDisconnect(MyBackUp, IID_BackupSink,FInterfaceConnection);//
BS.free;
ShowMessage('pass');
end;
[8D][8D][8D][8D][8D]
 
问题已经ok,谢谢。
 
OK了就发分
 
后退
顶部