unit UMessageThread;

interface

uses
  Classes,Dialogs,SysUtils,Windows;

procedure MessageOut(ParMessageString,ParMessageCaption:String);

type
  TMessageThread = class(TThread)    
  constructor Create(CreateSuspended:Boolean;
  ParMessageString,ParMessageCaption:String);
  private
    { Private declarations }
  protected
    procedure Execute; override;
  public
    MessageString:String;
    MessageCaption:String;
  end;


const MaxMessageCount=5;
var MessageCount:Cardinal=0;

implementation

uses Unit1,ShellApi;

constructor TMessageThread.Create(CreateSuspended:Boolean;
  ParMessageString,ParMessageCaption:String);
begin
  inherited Create(CreateSuspended);

  MessageString:=ParMessageString;
  MessageCaption:=ParMessageCaption;
end;



procedure TMessageThread.Execute;
begin
  try
    Inc(MessageCount);
    if MessageCount<=MaxMessageCount then 
    MessageBox(0, PChar(MessageString),
    PChar(MessageCaption), MB_ICONINFORMATION or MB_OK);
    Dec(MessageCount);
  except
    on e: exception do begin
      showmessage(e.Message);
    end;
  end;
end;

procedure MessageOut(ParMessageString,ParMessageCaption:String);
var MessageThread:TMessageThread;
begin
  MessageThread:=
  TMessageThread.Create(true,ParMessageString,ParMessageCaption);
  MessageThread.Resume;
end;

end.
