admin 管理员组

文章数量: 887021


2024年1月18日发(作者:程序设计语言怎么弄)

4.定义调整进度条位置的过程 (4. Define the procedure to adjust the progress bar position)This procedure will receive the messages from the progress thread.此过程将从进度线程接收消息。type

TForm1 = class(TForm) ProgressBar1: TProgressBar; private procedure UpdateProgressBar(aProgress: Integer); end;

procedure ProgressBar(aProgress: Integer);begin on := aProgress; ; // Make sure to repaint the progressbarend;5.从表单启动线程 (5. Start a thread from the form)This starts the progress thread这将启动进度线程type TForm1 = class(TForm) btnStart: TButton; procedure btnStartClick(Sender: TObject); private fMyThread: TMyThread; end;

procedure rtClick(Sender: TObject);begin if not Assigned(fMyThread) then

fMyThread := (UpdateProgressbar);end;6.完整的代码 (6. Complete code)Here is a copy of the complete unit这是完整单元的副本unit Unit1;

interface

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

type TProgressProc = procedure (aProgress: Integer) of object; // 0 to 100

TProgressThread = class(TThread) private FProgressProc: TProgressProc; FProgressValue: integer; procedure SynchedProgress; protected procedure Progress(aProgress: integer); virtual; public constructor Create(aProgressProc: TProgressProc; CreateSuspended: Boolean = False); reintroduce; virtual; end;

TMyThread = class(TProgressThread) protected

delphi 线程创建线程


本文标签: 线程 进度条 调整 位置 过程