mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 16:25:54 +01:00
92 lines
2.5 KiB
ObjectPascal
92 lines
2.5 KiB
ObjectPascal
|
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}
|
||
|
|
||
|
procedure TSendMessageMainForm.AutomaticSendCheckBoxClick(Sender: TObject);
|
||
|
begin
|
||
|
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;
|
||
|
end;
|
||
|
|
||
|
procedure TSendMessageMainForm.BeforeSendFrame(AFrame: IStompFrame);
|
||
|
begin
|
||
|
LogMemo.Lines.Add(AFrame.Output);
|
||
|
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
|
||
|
StompClient.Send(QueueEdit.Text,QueueMemo.Lines.Text);
|
||
|
finally
|
||
|
StompClient.Disconnect;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TSendMessageMainForm.SendMessageButtonClick(Sender: TObject);
|
||
|
begin
|
||
|
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');
|
||
|
Send;
|
||
|
end;
|
||
|
|
||
|
end.
|