Please enable JavaScript to view this site.

KOL/MCK - User Guide

TThread( unit KOL.pas ) TObj _TObj

TThread = object( TObj )

 

type Thread = ^TThread;

 

type TOnThreadExecute = function( Sender: PThread ): Integer of object;

Event to be called when Execute method is called for TThread

 

 

Constructors:

 

function NewThread: PThread;

Creates thread object (always suspended). After creating, set event OnExecute and perform Resume operation.

 

function NewThreadEx( const Proc: TOnThreadExecute ): PThread; stdcall;

Creates thread object, assigns Proc to its OnExecute event and runs it.

 

function NewThreadAutoFree( const Proc: TOnThreadExecute ): PThread;

Creates thread object similar to NewThreadEx, but freeing automatically when executing of such thread finished. Be sure that a thread is resumed at least to provide its object keeper freeing.

 

 

Methods and properties:

 

function Execute: integer; virtual;

Executes thread. Do not call this method from another thread! (Even do not call this method at all!) Instead, use Resume.

Note also that in contrast to VCL, it is not necessary to create your own descendant object from TThread and override Execute method. In KOL, it is sufficient to create an instance of TThread object (see NewThread, NewThreadEx, NewThreadAutoFree functions) and assign OnExecute event handler for it.

 

procedure Resume;

Continues executing. It is necessary to make call for every nested Suspend.

 

procedure Suspend;

Suspends thread until it will be resumed. Can be called from another thread or from the thread itself.

 

procedure Terminate;

Terminates thread.

 

function WaitFor: Integer;

Waits (infinitively) until thread will be finished.

 

function WaitForTime( T: DWORD ): Integer;

Waits (T milliseconds) until thread will be finished.

 

property Handle: THandle;

Thread handle. It is created immediately when object is created (using NewThread).

 

property Suspended: Boolean;

True, if suspended.

 

property Terminated: Boolean;

True, if terminated.

 

property ThreadId: DWORD;

Thread id.

 

property PriorityClass: Integer;

Thread priority class. One of following values: HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS.

 

property ThreadPriority: Integer;

Thread priority value. One of following values: THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_NORMAL, THREAD_PRIORITY_TIME_CRITICAL.

 

property Data : Pointer;

Custom data pointer. Use it for Your own purpose.

 

property AutoFree: Boolean;

Set this property to true to provide automatic destroying of thread object when its executing is finished.

 

property PriorityBoost: Boolean;

By default, priority boost is enabled for all threads.

 

procedure Synchronize( Method: TThreadMethod );

Call it to execute given method in main thread context. Applet variable must exist for that time.

 

procedure SynchronizeEx( Method: TThreadMethodEx; Param: Pointer );

Call it to execute given method in main thread context, with a given parameter. Applet variable must exist for that time. Param must not be nil.

 

Events:

 

property OnExecute: TOnThreadExecute;

Is called, when Execute is starting.

 

property OnSuspend: TObjectMethod;

Is called, when Suspend is performed.

 

property OnResume: TOnEvent;

Is called, when resumed.

 

 

Pseudo Streams

Variables:

 

MainThread: PThread;

 

PseudoThreadStackSize: DWORD = 1024 * 1024;

 

CreatingMainThread: Boolean;

 

 

Methods:

 

function WaitForSingleObject( hHandle: THandle; dwMilliseconds: DWORD ): DWORD; stdcall;

 

function WaitForMultipleObjects( nCount: DWORD; lpHandles: PHandle; fWaitAll: BOOL; dwMilliseconds: DWORD ): DWORD; stdcall;

 

KOL / MCK User Guide - Created by Carl Peeraer - Diamant Soft, based on the work of Vladimir Kladov - Artwerp.be

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Nav Header: ALT+n
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Exit Menu/Up: ESC