某网站开发项目成本估计,杭州百度seo优化,深圳市启创网络科技有限公司,揭阳网站制作建设lazarus开发界面程序用线程显示进度条#xff0c;效果更好#xff0c;以前没有另外显示线程#xff0c;遇到上传文件或其他较长时间操作#xff0c;界面就卡在那里#xff0c;体验不好#xff0c;现在另外启动线程操作#xff0c;主界面就不至于卡在那里。
首先在主界面…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 doesnt start automaticallyif Assigned(MyBackupThread.FatalException) thenraise MyBackupThread.FatalException;// Here the code initialises anything required before the threads starts executingif Form3nil thenbeginForm3:TForm3.Create(application);WriteLn(TForm3.Create);end;Form3.Show;//Test_DummyMyBackupThread.Start;Form3.FormProgress;
end;
from3是做了一个动画进度条也可不要至少主界面不会卡在那里不动了
lazarus要展示gif动画图片需要安装gifanim组件只需要把文件名赋值即可