////////////////////////////////////////////////////////////////////////////////
// TComThread //
////////////////////////////////////////////////////////////////////////////////
constructor TComThread.Create( CreateSuspended: Boolean;
TimeOut: Integer;
MaxTry: Integer;
MainFormHandle: THandle;
DebugMode: Boolean = FALSE );
begin
inherited Create( CreateSuspended );
self.FreeOnTerminate := TRUE;
self.FHandle := MainFormHandle;
self.FMaxTry := MaxTry;
self.FTimeOut := TimeOut;
// seconds
self.FStop := FALSE;
self.FCurrentTry := 0;
self.FDebugMode := DebugMode;
end;
procedure TComThread.ResetTry();
begin
self.FCurrentTry := 0;
end;
procedure TComThread.Beep( Short: Boolean = FALSE );
begin
if ( Short )
then
windows.beep( 1500, 200 )
else
begin
windows.beep( 4000, 30 );
windows.beep( 3000, 30 );
windows.beep( 2000, 30 );
windows.beep( 5000, 30 );
windows.beep( 4000, 30 );
end;
end;
procedure TComThread.Execute();
var
i: Integer;
begin
if ( self.FDebugMode )
then
self.Beep( TRUE );
while ( (
not self.FStop )
AND
( self.FMaxTry > self.FCurrentTry )
AND
(
not Terminated ) )
do
begin
for i:=0
to 100
do
if (
not Terminated )
then
Sleep( self.FTimeOut * 10 )
else
break;
if (
not Terminated )
then
begin
if ( self.FDebugMode )
then
self.Beep();
self.FCurrentTry := self.FCurrentTry + 1;
if ( self.FDebugMode )
then
SendMessage(
Handle, MTM_MESSAGE, 0,
Integer( PChar( '
PASS ' + IntToStr( self.FCurrentTry ) +
'
OF ' + IntToStr( self.FMaxTry ) ) ) );
end;
end;
self.FStop := TRUE;
if ( Terminated )
then
SendMessage(
Handle, MTM_ABORTED, 0, Integer( PChar( '
TERMINATED' ) ) )
else
SendMessage(
Handle, MTM_TIMEOUT, 0, Integer( PChar( '
TIMEOUT' ) ) );
self.Free();
end;
procedure TComThread.Reset();
begin
self.FStop := FALSE;
self.ResetTry();
end;