Advertisement
Borrisholt

Multicast event

Sep 2nd, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.75 KB | None | 0 0
  1. DFM:
  2.  
  3. object Form15: TForm15
  4.   Left = 0
  5.   Top = 0
  6.   Caption = 'Form15'
  7.   ClientHeight = 187
  8.   ClientWidth = 605
  9.   Color = clBtnFace
  10.   Font.Charset = DEFAULT_CHARSET
  11.   Font.Color = clWindowText
  12.   Font.Height = -11
  13.   Font.Name = 'Tahoma'
  14.   Font.Style = []
  15.   OldCreateOrder = False
  16.   OnCreate = FormCreate
  17.   OnDestroy = FormDestroy
  18.   PixelsPerInch = 96
  19.   TextHeight = 13
  20.   object Memo1: TMemo
  21.     Left = 8
  22.     Top = 8
  23.     Width = 185
  24.     Height = 89
  25.     Lines.Strings = (
  26.       'Memo1')
  27.     TabOrder = 0
  28.   end
  29.   object Memo2: TMemo
  30.     Left = 208
  31.     Top = 8
  32.     Width = 185
  33.     Height = 89
  34.     Lines.Strings = (
  35.       'Memo2')
  36.     TabOrder = 1
  37.   end
  38.   object Memo3: TMemo
  39.     Left = 408
  40.     Top = 8
  41.     Width = 185
  42.     Height = 89
  43.     Lines.Strings = (
  44.       'Memo3')
  45.     TabOrder = 2
  46.   end
  47.   object Edit1: TEdit
  48.     Left = 304
  49.     Top = 128
  50.     Width = 121
  51.     Height = 21
  52.     TabOrder = 3
  53.     Text = 'Edit1'
  54.   end
  55.   object Button1: TButton
  56.     Left = 184
  57.     Top = 126
  58.     Width = 99
  59.     Height = 25
  60.     Caption = 'Send meeesage'
  61.     TabOrder = 4
  62.     OnClick = Button1Click
  63.   end
  64. end
  65.  
  66. Unit
  67.  
  68. unit MainU;
  69.  
  70. interface
  71.  
  72. uses
  73.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  74.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  75.  
  76.   System.MulticastEventU, Vcl.StdCtrls;
  77.  
  78. {$M+,O+}
  79. {$IFOPT O-}
  80. {$MESSAGE Fatal 'Optimization _must_ be turned on for this unit to work!'}
  81. {$ENDIF}
  82.  
  83.  
  84. type
  85.   TForm15 = class(TForm)
  86.     Memo1: TMemo;
  87.     Memo2: TMemo;
  88.     Memo3: TMemo;
  89.     Edit1: TEdit;
  90.     Button1: TButton;
  91.     procedure FormCreate(Sender: TObject);
  92.     procedure FormDestroy(Sender: TObject);
  93.     procedure Button1Click(Sender: TObject);
  94.   private
  95.     { Private declarations }
  96.   public
  97.     { Public declarations }
  98.     FMulticastEvent: TMulticastEvent<TGetStrProc>;
  99.     procedure StrProc1(const message : string);
  100.     procedure StrProc2(const message : string);
  101.     procedure StrProc3(const message : string);
  102.   end;
  103.  
  104. var
  105.   Form15: TForm15;
  106.  
  107. implementation
  108.  
  109. {$R *.dfm}
  110.  
  111. procedure TForm15.Button1Click(Sender: TObject);
  112. begin
  113.   FMulticastEvent.Invoke(Edit1.Text);
  114. end;
  115.  
  116. procedure TForm15.FormCreate(Sender: TObject);
  117. begin
  118.   FMulticastEvent := TMulticastEvent<TGetStrProc>.Create;
  119.   FMulticastEvent.Add(StrProc1);
  120.   FMulticastEvent.Add(StrProc2);
  121.   FMulticastEvent.Add(StrProc3);
  122. end;
  123.  
  124. procedure TForm15.FormDestroy(Sender: TObject);
  125. begin
  126.   FMulticastEvent.Free;
  127. end;
  128.  
  129. procedure TForm15.StrProc1(const message: string);
  130. begin
  131.   Memo1.Lines.Add(message);
  132. end;
  133.  
  134. procedure TForm15.StrProc2(const message: string);
  135. begin
  136.   Memo2.Lines.Add(message);
  137. end;
  138.  
  139. procedure TForm15.StrProc3(const message: string);
  140. begin
  141.   Memo3.Lines.Add(message);
  142. end;
  143.  
  144. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement