{ Unit PrimeThread }
 
type
 TPrimeThrd = class(TThread)
 private
 FTestNumber: integer;
 FResultString: string;
 protected
 function IsPrime: boolean;
 procedure Execute; override;
 public
 property TestNumber: integer write FTestNumber;
 property ResultString: string read FResultString;
 end;
 
procedure TPrimeThrd.Execute;
begin
 if IsPrime then
 FResultString := IntToStr(FTestNumber) + ' es primo.'
 else
 FResultString := IntToStr(FTestNumber) + ' no es primo.';
 if not Terminated then {Lnea B}
 PostMessage(PrimeFrm.Handle, WM_THREAD_COMPLETE, 0, 0);
end;
 
{ Unit PrimeForm }
 
procedure TPrimeFrm.HandleThreadCompletion(var Message: TMessage);
begin
 if Assigned(FThread) then
 begin
 FThread.WaitFor;
 ResultsMemo.Lines.Add(FThread.ResultString);
 FThread.Free;
 FThread := nil;
 end;
end;