当前位置: 首页 > news >正文

lazarus开发界面程序用线程显示进度条

lazarus开发界面程序用线程显示进度条,效果更好,以前没有另外显示线程,遇到上传文件或其他较长时间操作,界面就卡在那里,体验不好,现在另外启动线程操作,主界面就不至于卡在那里。

首先在主界面上定义线程 

type{ TMyBackupThread }TMyBackupThread = class(TThread)privatefStatusText: string;procedure ShowStatus;protectedprocedure Execute; override;publicconstructor Create(CreateSuspended: boolean);end;{ TForm1 }TForm1 = class(TForm) 

然后在实现线程内容


{TBackupThread}procedure TMyBackupThread.ShowStatus;
// this method is only called by Synchronize(@ShowStatus) and therefore
// executed by the main thread
// The main thread can access GUI elements, for example Form1.Caption.
beginwriteln( fStatusText);form1.Memo1.Append(fStatusText);
end;procedure TMyBackupThread.Execute;
varRespo: TStringStream;S: string;
beginfStatusText := 'Backup Starting ...';Synchronize(@Showstatus);  //If I remark this, it causes "access violation" errorwith TFPHttpClient.Create(nil) dotryRespo := TStringStream.Create('');WriteLn(form1.Memo1.Lines.Strings[0]);WriteLn(Formatdatetime('yyyy-mm-dd hh:nn:ss.zzz',now));     FileFormPost(requrl + 'downFile', 'file', form1.Memo1.Lines.Strings[0], Respo);S := Respo.DataString;WriteLn(s);WriteLn(Formatdatetime('yyyy-mm-dd hh:nn:ss.zzz',now));form1.Memo1.Append(S);Respo.Destroy;     finallyFree;end;fStatusText := 'Backup Completed';Synchronize(@Showstatus);MyShowThread.active:=false;Form3.hide;
end;constructor TMyBackupThread.Create(CreateSuspended: boolean);
beginFreeOnTerminate := True;inherited Create(CreateSuspended);
end;                  

然后就可以在主界面里需要的地方调用了

procedure TForm1.btnUpClick(Sender: TObject);
varMyBackupThread : TMyBackupThread;
beginMyBackupThread := TMyBackupThread.Create(True); // With the True parameter it doesn't start automaticallyif Assigned(MyBackupThread.FatalException) thenraise MyBackupThread.FatalException;// Here the code initialises anything required before the threads starts executingif Form3=nil thenbeginForm3:=TForm3.Create(application);WriteLn('TForm3.Create');end;Form3.Show;//Test_DummyMyBackupThread.Start;Form3.FormProgress;
end;   

from3是做了一个动画进度条,也可不要,至少主界面不会卡在那里不动了

lazarus要展示gif动画图片,需要安装gifanim组件,只需要把文件名赋值即可

http://www.lryc.cn/news/158515.html

相关文章:

  • 解决VSCode下载速度特别慢的问题
  • 国家矿山安全监察局关于露天矿山边坡监测系统建设及预警响应要求
  • 前端使用elementui开发后台管理系统的常用功能(持续更新)
  • 中东 Shopify 如何使用 Bytebase 构建一站式数据库开发工作流
  • 谷歌Chrome庆祝15周年,推出全新设计!了解最新信息!
  • 解决Oracle SQL语句性能问题——SQL语句改写(分析函数、with as、union及or)
  • Linux之SELinux
  • Acwing算法心得——街灯(差分)
  • streamlit执行报错WARNING,重新安装碰到问题如何解决
  • 《C++设计模式》——行为型
  • 什么是原生IP?原生IP与住宅IP有何区别?
  • element-plus 表格-自定义样式实现
  • MVCC
  • 你不知道的JavaScript---对象
  • C++项目实战——基于多设计模式下的同步异步日志系统-①-项目介绍
  • 解决Oracle数据库中日期格式不识别的问题
  • 一生一芯13——linux设置环境变量
  • CSS笔记(黑马程序员pink老师前端)定位
  • C高级Linux指令和shell脚本
  • 449. 序列化和反序列化二叉搜索树
  • DockerCompose部署es和kibana
  • windows系统docker中将vue项目网站部署在nginx上
  • LabVIEW利用纳米结构干电极控制神经肌肉活动
  • 使用PHPStudy在本地快速建立网站并实现局域网外访问(无公网IP)
  • Java工具类--http请求-post
  • HTTP【总结】
  • 统计子岛屿
  • docker介绍、安装及卸载
  • 【EI/SCOPUS会议征稿】第二届环境遥感与地理信息技术国际学术会议(ERSGIT 2023)
  • LabVIEW应用开发——LabVIEW2019保姆级介绍、安装、第一个程序