Class tcommthread

Unit

Declaration

type tcommthread = class(teventthread)

Description

This item has no description. Showing description inherited from tmsethread.

Runs a method or a global function in a separate thread, so that a long operation does not block the application while it runs. The following example starts a three second simulated operation in a thread while a paint box blinks to show that the user interface stays responsive, and properly terminates the thread when the form is destroyed.

uses
  main_mfm;

{ ttestthreadcontainer }

destructor ttestthreadcontainer.Destroy;
begin
  if FThread <> nil then
  begin
    FThread.Terminate;
    application.WaitForThread(FThread);
    FThread.Destroy;
  end;
  inherited;
end;

procedure ttestthreadcontainer.Run;
begin
  FThread := tmsethread.Create(@Execute);
end;

function ttestthreadcontainer.Execute(thread: tmsethread): integer;
begin
  Sleep(3000);
  mainfo.tmWait.Enabled := FALSE;
  ShowMessage('Operation completed.');
  result := 0;
end;

{ tmainfo }

procedure tmainfo.ButtonExecute(const sender: TObject);
begin
  tmWait.Enabled := TRUE;
  FThreadContainer.Run;
end;

procedure tmainfo.FormCreate(const sender: TObject);
begin
  FThreadContainer := ttestthreadcontainer.Create();
  FBlink := FALSE;
end;

procedure tmainfo.TimerExecute(const sender: TObject);
begin
  pbWait.Invalidate;
  FBlink := not FBlink;
end;

procedure tmainfo.PaintBoxPaint(const sender: twidget; const acanvas: tcanvas);
begin
  if FBlink then
    acanvas.FillRect(MakeRect(0, 0, sender.bounds_cx, sender.bounds_cy), CL_BLUE);
end;

procedure tmainfo.FormDestroy(const sender: TObject);
begin
  FThreadContainer.Free;
end;

Hierarchy

Overview

Fields

Protected fowner: tmsecomponent;
Protected fport: trs232;
Protected fabort: boolean;
Protected fsendretries: integer;

Methods

Protected function checkabort(const sender: tobject): boolean; virtual;
Protected function execute(thread: tmsethread): integer; override;
Public constructor create(const aowner: tmsecomponent);
Public destructor destroy; override;
Public function writestring(const dat: string; timeout: integer = 0): boolean;
Public function readstring(anzahl: integer; out dat: string; timeout: integer = 0): boolean;
Public procedure abort;
Public procedure postevent(event: tcommevent);
Public procedure reset; virtual;

Properties

Public property port: trs232 read fport;
Public property sendretries: integer read fsendretries write fsendretries default 0;

Description

Fields

Protected fowner: tmsecomponent;

This item has no description.

Protected fport: trs232;

This item has no description.

Protected fabort: boolean;

This item has no description.

Protected fsendretries: integer;

This item has no description.

Methods

Protected function checkabort(const sender: tobject): boolean; virtual;

This item has no description.

Protected function execute(thread: tmsethread): integer; override;

This item has no description.

Public constructor create(const aowner: tmsecomponent);

This item has no description.

Public destructor destroy; override;

This item has no description.

Public function writestring(const dat: string; timeout: integer = 0): boolean;

This item has no description.

Public function readstring(anzahl: integer; out dat: string; timeout: integer = 0): boolean;

This item has no description.

Public procedure abort;

This item has no description.

Public procedure postevent(event: tcommevent);

This item has no description.

Public procedure reset; virtual;

This item has no description.

Properties

Public property port: trs232 read fport;

This item has no description.

Public property sendretries: integer read fsendretries write fsendretries default 0;

This item has no description.


Generated by PasDoc 1.0.4.