Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions StompClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ implementation

uses
// Windows, // Remove windows unit for compiling on ios
IdGlobal,
Character;
IdGlobal
{$IF CompilerVersion > 15}
, Character
{$IFEND}
;

{$ENDIF}

Expand Down Expand Up @@ -167,7 +170,8 @@ procedure TStompClient.Ack(const MessageID: string; const TransactionIdentifier:
begin
Frame := TStompFrame.Create;
Frame.SetCommand('ACK');
Frame.GetHeaders.Add(TStompHeaders.MESSAGE_ID, MessageID);
Frame.GetHeaders.Add(
{$IF CompilerVersion <= 15}StompTypes{$ELSE}TStompHeaders{$IFEND}.MESSAGE_ID, MessageID);
if TransactionIdentifier <> '' then
Frame.GetHeaders.Add('transaction', TransactionIdentifier);
SendFrame(Frame);
Expand Down Expand Up @@ -502,25 +506,35 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
function InternalReceiveINDY(ATimeout: Integer): IStompFrame;
var
c: char;
{$IF CompilerVersion <= 15}
sb: string;
{$ELSE}
sb: TStringBuilder;
{$IFEND}
tout: boolean;
FirstValidChar: boolean;
// UTF8Encoding: TEncoding;
{$IF CompilerVersion < 24}
{$IF CompilerVersion <= 15}
UTF8Encoding: IIdTextEncoding;
{$ELSEIF CompilerVersion < 24}
UTF8Encoding: TIdTextEncoding;
{$ELSE}
UTF8Encoding: IIdTextEncoding;
{$IFEND}
begin
{$IF CompilerVersion < 24}
{$IF CompilerVersion <= 15}
UTF8Encoding := IndyTextEncoding_UTF8;
{$ELSEIF CompilerVersion < 24}
UTF8Encoding := TEncoding.UTF8;
{$ELSE}
{$ELSEIF CompilerVersion >= 24}
UTF8Encoding := IndyTextEncoding_UTF8();
{$ENDIF}
{$IFEND}
tout := False;
Result := nil;
try
{$IF CompilerVersion > 15}
sb := TStringBuilder.Create(1024 * 4);
{$IFEND}
try
FTCP.ReadTimeout := ATimeout;
try
Expand All @@ -533,7 +547,11 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
Continue;
FirstValidChar := True;
if c <> CHAR0 then
{$IF CompilerVersion <= 15}
sb := sb + c
{$ELSE}
sb.Append(c)
{$IFEND}
else
begin
// FTCP.IOHandler.ReadChar(TEncoding.UTF8);
Expand All @@ -547,20 +565,20 @@ function TStompClient.Receive(ATimeout: Integer): IStompFrame;
end;
on E: Exception do
begin
if sb.Length > 0 then
raise EStomp.Create(E.message + sLineBreak + sb.toString)
if {$IF CompilerVersion <= 15}Length(sb){$ELSE}sb.Length{$IFEND} > 0 then
raise EStomp.Create(E.message + sLineBreak + sb{$IF CompilerVersion > 15}.toString{$IFEND})
else
raise;
end;
end;
if not tout then
begin
Result := StompUtils.CreateFrame(sb.toString + CHAR0);
Result := StompUtils.CreateFrame(sb{$IF CompilerVersion > 15}.toString{$IFEND} + CHAR0);
if Result.GetCommand = 'ERROR' then
raise EStomp.Create(Result.GetHeaders.Value('message'));
end;
finally
sb.Free;
{$IF CompilerVersion > 15}sb.Free;{$IFEND}
end;
except
on E: Exception do
Expand Down Expand Up @@ -632,7 +650,7 @@ procedure TStompClient.SendFrame(AFrame: IStompFrame);
FOnBeforeSendFrame(AFrame);

{$IF CompilerVersion < 25}
FTCP.IOHandler.write(TEncoding.UTF8.GetBytes(AFrame.output));
FTCP.IOHandler.write({$IF CompilerVersion <= 15}IndyTextEncoding_UTF8{$ELSE}TEncoding.UTF8{$IFEND}.GetBytes(AFrame.output));
{$IFEND}
{$IF CompilerVersion >= 25}
FTCP.IOHandler.write(IndyTextEncoding_UTF8.GetBytes(AFrame.output));
Expand Down
22 changes: 17 additions & 5 deletions StompTypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ TStompHeaders = class(TInterfacedObject, IStompHeaders)
class function NewReplyToHeader(const DestinationName: string): TKeyValue;

/// /////////////////////////////////////////////7
{$IF CompilerVersion > 15}
const
MESSAGE_ID: string = 'message-id';
TRANSACTION: string = 'transaction';
{$IFEND}
/// /
function Add(Key, Value: string): IStompHeaders; overload;
function Add(HeaderItem: TKeyValue): IStompHeaders; overload;
Expand Down Expand Up @@ -181,7 +183,7 @@ TAddress = record
end;

TStompClientListener = class(TThread, IStompListener)
strict protected
{$IF CompilerVersion > 15}strict{$IFEND} protected
FStompClientListener: IStompClientListener;
FStompClient: IStompClient;
procedure Execute; override;
Expand Down Expand Up @@ -210,11 +212,21 @@ StompUtils = class
AcceptVersion: TStompAcceptProtocol = STOMP_Version_1_0): IStompClient;
end;

{$IF CompilerVersion <= 15}
const
MESSAGE_ID: string = 'message-id';
TRANSACTION: string = 'transaction';
{$IFEND}

implementation

uses
Dateutils,
StompClient;
StompClient
{$IF CompilerVersion <= 15}
, IdGlobal
{$IFEND}
;

class function StompUtils.NewStomp(Host: string = '127.0.0.1';
Port: Integer = DEFAULT_STOMP_PORT; ClientID: string = '';
Expand Down Expand Up @@ -314,7 +326,7 @@ function TStompFrame.GetHeaders: IStompHeaders;

function TStompFrame.MessageID: string;
begin
Result := self.GetHeaders.Value(TStompHeaders.MESSAGE_ID);
Result := self.GetHeaders.Value({$IF CompilerVersion <= 15}StompTypes{$ELSE}TStompHeaders{$IFEND}.MESSAGE_ID);
end;

function TStompFrame.Output: string;
Expand All @@ -331,7 +343,7 @@ function TStompFrame.ContentLength: Integer;
procedure TStompFrame.SetBody(const Value: string);
begin
FBody := Value;
FContentLength := Length(TEncoding.UTF8.GetBytes(FBody));
FContentLength := Length({$IF CompilerVersion <= 15}IndyTextEncoding_UTF8{$ELSE}TEncoding.UTF8{$IFEND}.GetBytes(FBody));
end;

procedure TStompFrame.SetCommand(const Value: string);
Expand Down Expand Up @@ -406,7 +418,7 @@ class function StompUtils.CreateFrame(Buf: string): TStompFrame;
contLen := StrToInt(sContLen);
other := StripLastChar(other, COMMAND_END);

if TEncoding.UTF8.GetByteCount(other) <> contLen then
if {$IF CompilerVersion <= 15}IndyTextEncoding_UTF8{$ELSE}TEncoding.UTF8{$IFEND}.GetByteCount(other) <> contLen then
// there is still the command_end
raise EStomp.Create('frame too short');
Result.Body := other;
Expand Down
2 changes: 1 addition & 1 deletion examples/Chat/ChatClient/ChatClient.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ uses

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
// Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm5, Form5);
Application.Run;
end.
Binary file modified examples/Chat/ChatClient/ChatClient.res
Binary file not shown.
14 changes: 7 additions & 7 deletions examples/Chat/ChatClient/MainFormClient.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Form5: TForm5
Width = 137
Height = 21
TabOrder = 0
Text = 'localhost'
Text = '192.168.2.68'
end
object Edit2: TEdit
Left = 150
Expand Down Expand Up @@ -52,8 +52,8 @@ object Form5: TForm5
object Memo1: TMemo
Left = 9
Top = 39
Width = 494
Height = 314
Width = 478
Height = 276
Anchors = [akLeft, akTop, akRight, akBottom]
Color = clMenuBar
Font.Charset = ANSI_CHARSET
Expand All @@ -67,8 +67,8 @@ object Form5: TForm5
end
object Memo2: TMemo
Left = 8
Top = 359
Width = 389
Top = 321
Width = 373
Height = 68
Anchors = [akLeft, akRight, akBottom]
Enabled = False
Expand All @@ -82,8 +82,8 @@ object Form5: TForm5
OnKeyUp = Memo2KeyUp
end
object Button2: TButton
Left = 403
Top = 359
Left = 387
Top = 321
Width = 100
Height = 68
Anchors = [akRight, akBottom]
Expand Down
2 changes: 2 additions & 0 deletions examples/Chat/ChatClient/MainFormClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ procedure TForm5.tmrTimer(Sender: TObject);
if assigned(f) then
begin
Memo1.Lines.Add('[' + f.GetHeaders.Value('datetime') + ' ' + f.GetHeaders.Value('sender') + ']' + sLineBreak + f.GetBody);
{$IF CompilerVersion > 15}
if (WindowState = wsMinimized) or (Application.ActiveFormHandle <> self.Handle) then
begin
fw.cbSize := SizeOf(FLASHWINFO);
Expand All @@ -94,6 +95,7 @@ procedure TForm5.tmrTimer(Sender: TObject);
fw.dwTimeout := 500;
FlashWindowEx(fw);
end;
{$IFEND}
end;

end;
Expand Down
Binary file modified examples/GlobalDemo/GlobalDemo/GlobalDemo.res
Binary file not shown.
Binary file modified examples/GlobalDemo/GlobalDemo/Receiver.res
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/QueueAck/Receiver/Receiver.dpr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
program Receiver;

uses
Vcl.Forms,
Forms,
ReceiverForm in 'ReceiverForm.pas' {ReceiverMainForm},
ThreadReceiver in 'ThreadReceiver.pas';

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
//Application.MainFormOnTaskbar := True;
Application.CreateForm(TReceiverMainForm, ReceiverMainForm);
Application.Run;
end.
Loading