This commit is contained in:
dgaspary 2010-12-02 23:16:39 +00:00
parent ade6685eaa
commit fbb7315114
3 changed files with 107 additions and 108 deletions

View File

@ -16,7 +16,7 @@ object Form1: TForm1
Visible = True Visible = True
object Edit1: TEdit object Edit1: TEdit
Left = 8 Left = 8
Height = 23 Height = 25
Top = 22 Top = 22
Width = 144 Width = 144
Font.Height = -13 Font.Height = -13

View File

@ -6,7 +6,7 @@ LazarusResources.Add('TForm1','FORMDATA',[
+'nu'#0#7'Caption'#6#13'Receiver Form'#12'ClientHeight'#3'+'#1#11'ClientWidth' +'nu'#0#7'Caption'#6#13'Receiver Form'#12'ClientHeight'#3'+'#1#11'ClientWidth'
+#3#238#2#11'Font.Height'#2#245#9'Font.Name'#6#6'Tahoma'#7'OnClose'#7#9'FormC' +#3#238#2#11'Font.Height'#2#245#9'Font.Name'#6#6'Tahoma'#7'OnClose'#7#9'FormC'
+'lose'#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.29'#7'Visible'#9#0 +'lose'#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.29'#7'Visible'#9#0
+#5'TEdit'#5'Edit1'#4'Left'#2#8#6'Height'#2#23#3'Top'#2#22#5'Width'#3#144#0#11 +#5'TEdit'#5'Edit1'#4'Left'#2#8#6'Height'#2#25#3'Top'#2#22#5'Width'#3#144#0#11
+'Font.Height'#2#243#9'Font.Name'#6#6'Tahoma'#10'Font.Style'#11#6'fsBold'#0#10 +'Font.Height'#2#243#9'Font.Name'#6#6'Tahoma'#10'Font.Style'#11#6'fsBold'#0#10
+'ParentFont'#8#8'TabOrder'#2#0#4'Text'#6#14'/topic/mytopic'#0#0#7'TButton'#7 +'ParentFont'#8#8'TabOrder'#2#0#4'Text'#6#14'/topic/mytopic'#0#0#7'TButton'#7
+'Button1'#4'Left'#3#8#1#6'Height'#2#25#3'Top'#2#22#5'Width'#2'\'#7'Caption'#6 +'Button1'#4'Left'#3#8#1#6'Height'#2#25#3'Top'#2#22#5'Width'#2'\'#7'Caption'#6

View File

@ -1,111 +1,110 @@
unit ReceiverForm; unit ReceiverForm;
{$MODE Delphi} {$MODE Delphi}
interface interface
uses uses
{Windows,} {Windows,}
Messages, Messages,
SysUtils, SysUtils,
Classes, Classes,
Graphics, Graphics,
Controls, Controls,
Forms, Forms,
Dialogs, Dialogs,
StdCtrls, StdCtrls,
StompClient, StompClient,
StompTypes, StompTypes,
ExtCtrls, LResources; ExtCtrls, LResources;
type type
TForm1 = class(TForm, IStompClientListener) TForm1 = class(TForm, IStompClientListener)
Edit1: TEdit; Edit1: TEdit;
Button1: TButton; Button1: TButton;
Button5: TButton; Button5: TButton;
Memo1: TMemo; Memo1: TMemo;
Button3: TButton; Button3: TButton;
Button4: TButton; Button4: TButton;
Button6: TButton; Button6: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject); procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject); procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject); procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject); procedure Button3Click(Sender: TObject);
procedure Button6Click(Sender: TObject); procedure Button6Click(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
private private
stomp: IStompClient; stomp: IStompClient;
th: TStompClientListener; th: TStompClientListener;
public public
procedure OnMessage(StompFrame: IStompFrame); procedure OnMessage(StompFrame: IStompFrame);
end; end;
var var
Form1: TForm1; Form1: TForm1;
implementation implementation
uses uses
DateUtils; DateUtils;
procedure TForm1.Button1Click(Sender: TObject); procedure TForm1.Button1Click(Sender: TObject);
begin begin
stomp.Subscribe(Edit1.Text); stomp.Subscribe(Edit1.Text);
end; end;
procedure TForm1.Button3Click(Sender: TObject); procedure TForm1.Button3Click(Sender: TObject);
begin begin
stomp.Unsubscribe(Edit1.Text); stomp.Unsubscribe(Edit1.Text);
end; end;
procedure TForm1.Button4Click(Sender: TObject); procedure TForm1.Button4Click(Sender: TObject);
begin begin
th.StopListening; th.StopListening;
FreeAndNil(th); FreeAndNil(th);
stomp.Disconnect; stomp.Disconnect;
end; end;
procedure TForm1.Button5Click(Sender: TObject); procedure TForm1.Button5Click(Sender: TObject);
begin begin
stomp.Subscribe(Edit1.Text, amAuto, StompUtils.NewHeaders.Add(TStompHeaders.NewDurableSubscriptionHeader('pippo'))); stomp.Subscribe(Edit1.Text, amAuto, StompUtils.NewHeaders.Add(TStompHeaders.NewDurableSubscriptionHeader('pippo')));
end; end;
procedure TForm1.Button6Click(Sender: TObject); procedure TForm1.Button6Click(Sender: TObject);
begin begin
stomp.Connect('localhost', 61613, 'myclientid'); stomp.Connect('localhost', 61613, 'myclientid');
th := TStompClientListener.Create(stomp, Self); th := TStompClientListener.Create(stomp, Self);
end; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin begin
if assigned(stomp) then if assigned(stomp) then
begin begin
if assigned(th) then if assigned(th) then
begin begin
th.StopListening; th.StopListening;
th.Free; th.Free;
end; end;
stomp.Disconnect; stomp.Disconnect;
stomp := nil; stomp := nil;
end; end;
end; end;
procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
begin begin
stomp := TStompClient.Create; stomp := TStompClient.Create;
end; end;
procedure TForm1.OnMessage(StompFrame: IStompFrame); procedure TForm1.OnMessage(StompFrame: IStompFrame);
begin begin
Caption := DateTimeToStr(StompUtils.TimestampAsDateTime(StompFrame.GetHeaders.Value('timestamp'))); Caption := DateTimeToStr(StompUtils.TimestampAsDateTime(StompFrame.GetHeaders.Value('timestamp')));
Memo1.Lines.Add(StompFrame.GetBody); Memo1.Lines.Add(StompFrame.GetBody);
end; end;
initialization initialization
{$i ReceiverForm.lrs} {$i ReceiverForm.lrs}
{$i ReceiverForm.lrs}
end. end.