⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm_thread.pas

📁 多线程应用调试过程
💻 PAS
字号:
unit Frm_Thread;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, XPMan, Buttons;

type
  TPlayThread = class(TThread)
  private
    FWight:integer;
    FControl:TGraphicControl;
    { Private declarations }
  protected
    Procedure SetControl(value:TGraphicControl);
    procedure SetWight(value:Integer);
    { protected declarations }
  public
    procedure Execute;override;
    { Public declarations }
  published
    property SControl:TGraphicControl Write SetControl;
    property Wight:integer read FWight Write SetWight;
  end;


  TFrmmutil = class(TForm)
    BtnStartPaint: TButton;
    BtnClose: TButton;
    GroupBox1: TGroupBox;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnStartPaintClick(Sender: TObject);
    procedure BtnCloseClick(Sender: TObject);
  private
     Pt,pt1,pt2:TPlayThread;
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Frmmutil: TFrmmutil;

implementation

{$R *.dfm}
procedure TPlayThread.SetControl(value:TGraphicControl);
begin
  if assigned(value) then
  begin
    FControl:=Value;
  end;
end;

procedure TPlayThread.Execute;
begin
  Randomize;
  if assigned(FControl) then
  begin
    while FControl.Left<FWight do
    begin
      FControl.Left:=FControl.Left+Random(2);
      sleep(Random(80));
    end;
  end;
end;
procedure TPlayThread.SetWight(value:integer);
begin
  if value > FControl.Left then
  begin
    FWight:=Value;
  end;
end;

procedure TFrmmutil.FormCreate(Sender: TObject);
begin
  pt:=TPlayThread.Create(true);
  pt1:=TPlayThread.Create(true);
  pt2:=TPlayThread.Create(true);

  pt.SControl:=image1;
  pt1.SControl:=image2;
  pt2.SControl:=image3;

  pt.Wight:=self.Width-image1.Width;
  pt1.Wight:=self.Width-image2.Width;
  pt2.Wight:=self.Width-image3.Width;

  pt.Priority:=tpHigher;
  pt1.Priority:=tpHigher;
  pt2.Priority:=tpHigher;

end;

procedure TFrmmutil.FormDestroy(Sender: TObject);
begin
  pt.Terminate;
  pt1.Terminate;
  pt2.Terminate;
  freeandnil(pt);
  freeandnil(pt1);
  freeandnil(pt2);
end;

procedure TFrmmutil.BtnStartPaintClick(Sender: TObject);
begin
  pt.Resume;
  pt2.Resume;
  pt1.Resume;
end;

procedure TFrmmutil.BtnCloseClick(Sender: TObject);
begin
  Close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -