2012-12-27 23:32:04 +01:00
|
|
|
unit SendMessageForm;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StompClient, StompTypes,
|
|
|
|
Vcl.ExtCtrls;
|
|
|
|
|
|
|
|
type
|
|
|
|
TSendMessageMainForm = class(TForm)
|
|
|
|
QueueMemo: TMemo;
|
|
|
|
SendMessageButton: TButton;
|
|
|
|
QueueEdit: TEdit;
|
|
|
|
Label1: TLabel;
|
|
|
|
Label2: TLabel;
|
|
|
|
Label3: TLabel;
|
|
|
|
LogMemo: TMemo;
|
|
|
|
AutomaticSendTimer: TTimer;
|
|
|
|
AutomaticSendCheckBox: TCheckBox;
|
|
|
|
procedure SendMessageButtonClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
procedure AutomaticSendTimerTimer(Sender: TObject);
|
|
|
|
procedure AutomaticSendCheckBoxClick(Sender: TObject);
|
|
|
|
private
|
|
|
|
StompClient: TStompClient;
|
|
|
|
procedure BeforeSendFrame(AFrame: IStompFrame);
|
|
|
|
procedure Send;
|
|
|
|
public
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
SendMessageMainForm: TSendMessageMainForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
2016-08-02 18:15:11 +02:00
|
|
|
|
2012-12-27 23:32:04 +01:00
|
|
|
procedure TSendMessageMainForm.AutomaticSendCheckBoxClick(Sender: TObject);
|
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
if QueueEdit.Text = '' then
|
|
|
|
raise Exception.Create('Specify queue name');
|
|
|
|
if QueueMemo.Lines.Text = '' then
|
|
|
|
raise Exception.Create('Specify text of message to be sent');
|
|
|
|
if AutomaticSendCheckBox.Checked then
|
|
|
|
AutomaticSendTimer.Enabled := True
|
|
|
|
else
|
|
|
|
AutomaticSendTimer.Enabled := False;
|
2012-12-27 23:32:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSendMessageMainForm.BeforeSendFrame(AFrame: IStompFrame);
|
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
LogMemo.Lines.Add(StringReplace(AFrame.Output, #10, sLineBreak, [rfReplaceAll]));
|
2012-12-27 23:32:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSendMessageMainForm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
StompClient := TStompClient.Create;
|
|
|
|
StompClient.OnBeforeSendFrame := BeforeSendFrame;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSendMessageMainForm.FormDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
StompClient.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSendMessageMainForm.AutomaticSendTimerTimer(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if AutomaticSendCheckBox.Checked then
|
|
|
|
begin
|
|
|
|
AutomaticSendTimer.Enabled := False;
|
|
|
|
Send;
|
|
|
|
AutomaticSendTimer.Enabled := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSendMessageMainForm.Send;
|
|
|
|
begin
|
|
|
|
StompClient.Connect;
|
|
|
|
try
|
2013-05-10 18:00:10 +02:00
|
|
|
try
|
2016-08-02 18:15:11 +02:00
|
|
|
StompClient.Send(QueueEdit.Text, QueueMemo.Lines.Text);
|
2013-05-10 18:00:10 +02:00
|
|
|
except
|
2016-08-02 18:15:11 +02:00
|
|
|
on e: Exception do
|
2013-05-10 18:00:10 +02:00
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
LogMemo.Lines.Add('ERROR: ' + e.Message);
|
2013-05-10 18:00:10 +02:00
|
|
|
end;
|
|
|
|
end;
|
2012-12-27 23:32:04 +01:00
|
|
|
finally
|
|
|
|
StompClient.Disconnect;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSendMessageMainForm.SendMessageButtonClick(Sender: TObject);
|
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
if QueueEdit.Text = '' then
|
|
|
|
raise Exception.Create('Specify queue name');
|
|
|
|
if QueueMemo.Lines.Text = '' then
|
|
|
|
raise Exception.Create('Specify text of message to be sent');
|
2012-12-27 23:32:04 +01:00
|
|
|
Send;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|