码迷,mamicode.com
首页 > 编程语言 > 详细

BMDThread多线程控件

时间:2020-01-26 20:42:31      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:其他   send   fda   stop   sse   data   top   ado   sys   

最新版本应该是2.1   11/10/2015      Delphi XE7, XE8 and 10 Seattle Add,后面要支持其他版本需要自行修改

官网:www.mitov.com        www.openwire.org

1、将路径添加搜索路径下

2、BMThreadDsnD7.dpk先编译后安装

安装后两个控件

技术图片

 

 

 

unit BMDThread;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, Forms, Syncobjs, ExtCtrls;

type
  { Forward class declarations }
  TBMDThread = class;
  TBMDExecuteThread = class;
  TBMDThreadGroup = class;

  { Thread events }
  TBMDThreadNotifyEvent = procedure(Sender: TObject; Thread: TBMDExecuteThread) of object;
  TBMDThreadDataNotifyEvent = procedure(Sender: TObject; Thread: TBMDExecuteThread; var Data: Pointer) of object;
  TBMDThreadUpdateNotifyEvent = procedure(Sender: TObject; Thread: TBMDExecuteThread; var Data: Pointer; Percent: Integer) of object;
  TBMDThreadSynchroNotifyEvent = procedure(Sender: TBMDThread; Thread: TBMDExecuteThread) of object;
  TBMDThreadSynchroDataNotifyEvent = procedure(Sender: TBMDThread; Thread: TBMDExecuteThread; var Data: Pointer) of object;

  { TBMDExecuteThread class }
  TBMDExecuteThread = class(TThread)
  private
    { Private declarations }
  protected
    { Protected declarations }
    ThreadOwner: TBMDThread;
    FData: Pointer;
    FNotifyEvent: TNotifyEvent;
    FThreadNotifyEvent: TBMDThreadSynchroNotifyEvent;
    FThreadDataNotifyEvent: TBMDThreadSynchroDataNotifyEvent;
    UpdateData: Pointer;
    procedure Execute(); override;
  public
    { Public declarations }
    PercentProgress: Integer;
    constructor Create(AThreadOwner: TBMDThread; AUpdateData: Pointer); virtual;
    procedure DoNotifySynchro;
    procedure DoThreadNotifySynchro;
    procedure DoThreadNotifySynchroData;
    procedure Synchronize(SynchroEvent: TNotifyEvent); overload;
    procedure Synchronize(SynchroEvent: TBMDThreadSynchroNotifyEvent); overload;
    procedure Synchronize(SynchroEvent: TBMDThreadSynchroDataNotifyEvent; Data: Pointer); overload;
    // The folowing two functions are obsolete and should not be used in future !!!
    // Obsolete !!! Don‘t use any more !!! >>>>
    procedure Synchronize(SynchroEvent: TBMDThreadNotifyEvent); overload;
    procedure Synchronize(SynchroEvent: TBMDThreadDataNotifyEvent; Data: Pointer); overload;
    // <<< Obsolete !!! Don‘t use any more !!!
    property Terminated;
  end;

  { TBMDThread class }
  TBMDThreadBase = class(TComponent)
  private
    FOnUpdate: TBMDThreadUpdateNotifyEvent;
    FOnStart: TBMDThreadDataNotifyEvent;
    FOnTerminate: TBMDThreadDataNotifyEvent;
    FThreadGroup: TBMDThreadGroup;
    FUpdatePriority: Integer;
  protected
    UpdateCriticalSection: TCriticalSection;
    function GetRuning(): Boolean; virtual; abstract;
    procedure SetThreadGroup(AThreadGroup: TBMDThreadGroup);
    procedure ReportStarted(ThreadGroup: TBMDThreadGroup); virtual; abstract;
    procedure ReportTerminated(ThreadGroup: TBMDThreadGroup); virtual; abstract;
    function  AddMe(AThreadGroup: TBMDThreadGroup) : Boolean; virtual; abstract;
    procedure RemoveMe(AThreadGroup: TBMDThreadGroup); virtual; abstract;
  public
    constructor Create(Owner: TComponent); override;
    destructor Destroy; override;
    procedure Start(); overload; virtual; abstract;
    procedure Start(Data: Pointer); overload; virtual; abstract;
    procedure Stop(); virtual; abstract;
    procedure Suspend(); virtual; abstract;
    procedure Resume(); virtual; abstract;
  public
    property Runing: Boolean read GetRuning;
    property ThreadGroup: TBMDThreadGroup read FThreadGroup write SetThreadGroup;
    property UpdatePriority: Integer read FUpdatePriority write FUpdatePriority default 0;
    property OnUpdate: TBMDThreadUpdateNotifyEvent read FOnUpdate write FOnUpdate;
    property OnStart: TBMDThreadDataNotifyEvent read FOnStart write FOnStart;
    property OnTerminate: TBMDThreadDataNotifyEvent read FOnTerminate write FOnTerminate;
  end;

  { TBMDThread class }
  TBMDThread = class(TBMDThreadBase)
  protected
    FUpdateTimer: TTimer;
    FOnExecute: TBMDThreadDataNotifyEvent;
    FExecuteThread: TBMDExecuteThread;
    FPriority: TThreadPriority;
    FUpdateEnabled: Boolean;
    FInterrupted: Boolean;
    procedure OnUpdateTimer(Sender: TObject); virtual;
    procedure Execute(); virtual;
    procedure OnThreadTerminate(Sender: TObject); virtual;
    procedure OnThreadTerminateClose(Sender: TObject); virtual;
    procedure ReportStarted(ThreadGroup: TBMDThreadGroup); override;
    procedure ReportTerminated(ThreadGroup: TBMDThreadGroup); override;
    function  AddMe(AThreadGroup: TBMDThreadGroup) : Boolean; override;
    procedure RemoveMe(AThreadGroup: TBMDThreadGroup); override;
    procedure SetTimeInterval(TimeInterval: Cardinal);
    function GetTimeInterval(): Cardinal;
    procedure SetPriority(Value: TThreadPriority);
    function GetPriority(): TThreadPriority;
    function GetRuning(): Boolean; override;
    function GetEmptyEntry(): TPersistent;
    procedure SetUpdateEnabled(Value: Boolean);
  public
    constructor Create(Owner: TComponent); override;
    destructor Destroy; override;
    procedure Start(); overload; override;
    procedure Start(Data: Pointer); overload; override;
    procedure Stop(); override;
    procedure Suspend(); override;
    procedure Resume(); override;
    property Runing;
    property Interrupted: Boolean read FInterrupted;
    property Thread: TBMDExecuteThread read FExecuteThread;
  published
    property RefreshInterval: Cardinal read GetTimeInterval write SetTimeInterval default 100;
    property Priority: TThreadPriority read GetPriority write SetPriority default tpNormal;
    property ThreadGroup;
    property UpdatePriority;
    property UpdateEnabled : Boolean read FUpdateEnabled write SetUpdateEnabled; 
    property SynchroMethods: TPersistent read GetEmptyEntry;
    property OnExecute: TBMDThreadDataNotifyEvent read FOnExecute write FOnExecute;
    property OnUpdate;
    property OnStart;
    property OnTerminate;
  end;

  TBMDThreadGroup = class(TBMDThreadBase)
  protected
    ThreadItemsList: TList;
    ThreadsList: TList;
    FOnThreadUpdate: TBMDThreadUpdateNotifyEvent;
    FOnThreadStart: TBMDThreadDataNotifyEvent;
    FOnThreadTerminate: TBMDThreadDataNotifyEvent;
    // Protected by CriticalSection
    FCountRuning: Integer;
    function GetRuning(): Boolean; override;
    function GetCountRuning(): Integer; virtual;
    function GetThreadItemsCount(): Integer;
    function GetThreadItems(Index: Integer): TBMDThreadBase;
    function GetThreadsCount(): Integer;
    function GetThreads(Index: Integer): TBMDThread;
    procedure ReportStarted(ThreadGroup: TBMDThreadGroup); override;
    procedure ReportTerminated(ThreadGroup: TBMDThreadGroup); override;
    function  AddMe(AThreadGroup: TBMDThreadGroup) : Boolean; override;
    procedure RemoveMe(AThreadGroup: TBMDThreadGroup); override;
    function LinkedToMe( ThreadBase : TBMDThreadBase ) : Boolean;
  public
    constructor Create(Owner: TComponent); override;
    destructor Destroy; override;
    procedure Start(); overload; override;
    procedure Start(Data: Pointer); overload; override;
    procedure Stop(); override;
    procedure Suspend(); override;
    procedure Resume(); override;
    function  AddThread(AThread: TBMDThread) : Boolean;
    procedure RemoveThread(AThread: TBMDThread);
    function  AddThreadGroup(AThreadGroup: TBMDThreadGroup) : Boolean;
    procedure RemoveThreadGroup(AThreadGroup: TBMDThreadGroup);
    procedure ThreadStarted(Sender: TObject; Thread: TBMDExecuteThread; var Data: Pointer);
    procedure ThreadUpdate(Sender: TObject; Thread: TBMDExecuteThread; var Data: Pointer; AUpdatePriority: Integer; PercentProgres: Integer);
    procedure ThreadTerminated(Sender: TObject; Thread: TBMDExecuteThread; var Data: Pointer);
    
  public
    property Runing;
    property CountRuning: Integer read GetCountRuning;
    property ThreadItemsCount: Integer read GetThreadItemsCount;
    property ThreadItems[Index: Integer]: TBMDThreadBase read GetThreadItems;
    property ThreadsCount: Integer read GetThreadsCount;
    property Threads[Index: Integer]: TBMDThread read GetThreads;

  published
    property ThreadGroup;
    property UpdatePriority;
    property OnUpdate;
    property OnStart;
    property OnTerminate;
    property OnThreadUpdate: TBMDThreadUpdateNotifyEvent read FOnThreadUpdate write FOnThreadUpdate;
    property OnThreadStart: TBMDThreadDataNotifyEvent read FOnThreadStart write FOnThreadStart;
    property OnThreadTerminate: TBMDThreadDataNotifyEvent read FOnThreadTerminate write FOnThreadTerminate;
  end;

implementation

  

技术图片

 

BMDThread多线程控件

标签:其他   send   fda   stop   sse   data   top   ado   sys   

原文地址:https://www.cnblogs.com/epinn/p/12234605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!