实例介绍
【实例简介】
企业内部信息系统如果有升级版本时,需将相应的界面放在服务器端,客户端登录时会提示更新升级,点击升级会将服务器对应的模块拷贝至相应的本机目录。
【实例截图】
【核心代码】
procedure TFrmClientUpdate.updateClick(Sender:TObject);
var
i:integer;
k:word;
begin
try
screen.Cursor := crhourglass;
DataUpdatestr.Clear;
ClientUpdatestr.Clear;
rzmemo1.Clear;
aPath := ExtractFilePath(Application.Exename) 'WorkCenterSystem';
if aPath[Length(aPath)] <> '\' then aPath := aPath '\';
rzmemo1.Lines.Add('正在启动更新会话。');
rzmemo1.Lines.Add('正在检查更新版本信息...');
aCloseTime := 30;
Timer1.Enabled := false;
Label1.Visible := false;
Label3.Visible := false;
Label2.Visible := true;
ProgressBar1.Visible := true;
ProgressBar1.Percent := 8;
rzmemo1.Lines.Add('正在获取数据库上的更新信息。');
try
with query1 do
begin
if active then close;
sql.Text := 'Select FDllName,FVerison,FVerInt From V_AllDllVersion';
open;
first;
while not eof do
begin
if StrtoInt(query1['FVerInt']) > GetFileVersionInt(aPath query1['FDllName']) then
DataUpdatestr.Add(query1['FDllName'])
else if FileExists(aPath query1['FDllName']) = false then
DataUpdatestr.Add(query1['FDllName']);
next;
end;
close;
if DataUpdatestr.Count = 0 then
begin
ProgressBar1.Percent := 100;
Timer1.Enabled := true;
Label2.Visible := false;
Label1.Visible := true;
Label3.Visible := true;
rzmemo1.Lines.Add('更新结束。');
Application.MessageBox(PChar('系统已经是最新版本!'),PChar('提示'),MB_ICONERROR Or MB_OK);
application.Terminate;
end;
end;
except
on E:Exception do
begin
FrmClientUpdate.FormStyle := fsNormal;
Application.MessageBox(pchar('系统出错,请重新更新系统!' #13 '提示:' E.Message),'提示', MB_ICONERROR or MB_OK);
application.Terminate;
exit;
end;
end;
try
if DataUpdatestr.Count = 0 then
application.Terminate;
ProgressBar1.Percent := 10;
rzmemo1.Lines.Add('正在加载最新系统内容........');
rzmemo1.Lines.Add('复制远程文件覆盖到本地:');
try
K := (80 div DataUpdatestr.Count);
except
application.Terminate;
end;
for i := 0 to DataUpdatestr.Count - 1 do
begin
try
IdHTTP1.Head(ClientPath DataUpdatestr.Strings[i]);
except
Application.MessageBox(PChar('系统服务器上不存在此文件!' #13 ClientPath DataUpdatestr.Strings[i]),PChar('提示'),MB_ICONERROR Or MB_OK);
// raise Exception.Create('系统服务器上不存在此文件!' #13 ClientPath DataUpdatestr.Strings[i]);
application.Terminate;
exit;
end;
// if FileExists(aPath DataUpdatestr.Strings[i]) then Deletefile(aPath DataUpdatestr.Strings[i]);
Update(ClientPath DataUpdatestr.Strings[i],aPath DataUpdatestr.Strings[i]);
ProgressBar1.Percent := ProgressBar1.Percent k;
rzmemo1.Lines.Add(aPath DataUpdatestr.Strings[i]);
end;
ProgressBar1.Percent := 94;
// if FileExists(fpath 'ClientSystemInfo.ini') then Deletefile(fpath 'ClientSystemInfo.ini');
// Update(ClientPath 'ClientSystemInfo.ini',fpath 'ClientSystemInfo.ini');
ProgressBar1.Percent := 100;
//#ToDo1 :创建更新日志文件夹并写入更新日志 --tendy_tang
if not DirectoryExists(ExtractFilePath(paramstr(0)) 'UpdateLog') then
CreateDir(PChar(ExtractFilePath(paramstr(0)) 'UpdateLog'));
fpath := ExtractFilePath(paramstr(0)) 'UpdateLog';
if fpath[Length(fpath)] <> '\' then fpath := fpath '\';
sClientUpdateName := 'ClientUpdateInfo' FormatDateTime('yyyymmddhhmm',Now) '.ini';
ini := TiniFile.Create(fpath sClientUpdateName);
ini.WriteString('UpdateInfos', 'UpdateLog', sUpdateInfo);
// sUpdateLog := ini.ReadString(sClientUpdateName,'UpdateLog',sUpdateInfo);
// showmessage(sUpdateLog);
rzmemo1.Lines.Add('总共更新文件数: ' inttostr(DataUpdatestr.Count) ' 个');
rzmemo1.Lines.Add('系统更新成功!');
Timer1.Enabled := true;
Label2.Visible := false;
Label1.Visible := true;
Label3.Visible := true;
btnclose.SetFocus;
except
on E:Exception do
begin
rzmemo1.Lines.Add('更新失败:' aPath DataUpdatestr.Strings[i]);
rzmemo1.Lines.Add('出错原因:文件正在使用');
MessageBox(0, pchar('提示:' E.Message),
'提示', MB_ICONERROR or MB_OK);
application.Terminate;
exit;
end;
end;
finally
screen.Cursor := crdefault;
end;
end;
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论