unit IPCMessaging.Types;
interface
uses
Winapi.Messages,
Winapi.Windows,
System.Classes, System.SysUtils, System.Generics.Collections;
type
TDataMessageEvent =
procedure(Sender: TObject;
const AValue:
string)
of object;
type
TIPCMessagingListener =
class
private const
cUnregister = 0;
cRegister = 1;
cBroadcast = 2;
private
FClientMessageID: Cardinal;
FServerMessageID: Cardinal;
FWindowHandle: HWND;
strict protected
procedure HandleClientMessage(ASender: HWND; AData: Integer);
virtual;
procedure HandleDataMessage(ASender: HWND;
const AValue:
string);
virtual;
procedure HandleServerMessage(ASender: HWND; AData: Integer);
virtual;
procedure SendClientMessage(ARecipient: HWND; AData: Integer);
procedure SendDataMessage(ARecipient: HWND;
const AValue:
string);
procedure SendServerMessage(ARecipient: HWND; AData: Integer);
procedure WndProc(
var Msg: TMessage);
public
constructor Create;
destructor Destroy;
override;
end;
TIPCMessagingServer =
class(TIPCMessagingListener)
private
FClientHandles: TList<HWND>;
FData:
string;
procedure SetData(
const Value:
string);
strict protected
procedure HandleClientMessage(ASender: HWND; AData: Integer);
override;
procedure SendData;
public
constructor Create;
destructor Destroy;
override;
property Data:
string read FData
write SetData;
end;
TIPCMessagingClient =
class(TIPCMessagingListener)
private
FOnDataMessage: TDataMessageEvent;
FServerHandle: HWND;
strict protected
procedure DataMessage(
const AValue:
string);
virtual;
procedure HandleDataMessage(ASender: HWND;
const AValue:
string);
override;
procedure HandleServerMessage(ASender: HWND; AData: Integer);
override;
public
constructor Create;
destructor Destroy;
override;
property OnDataMessage: TDataMessageEvent
read FOnDataMessage
write FOnDataMessage;
end;
implementation