Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

Delphi-Event-Dispatcher

Delphi Event Dispatcher (for short DED) is a publish/subscribe and Multicast Event framework for Cross platforms.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

![alt text]

DED an interfaced publish/subscribe and multicast framework for Delphi

Delphi Event Dispatcher (for short DED) is a publish/subscribe and multicast Event framework for Cross platforms.

Features

  • Easy : DelphiEventDispatch is easy to learn and use. it can override an interface of Events to be a subscribers, and publisher only call procedures of an virtual Event interface to invoke all subscribers.
  • __Decouple : based interface, decouple different parts/layers of your application.
  • Event Driven
  • Support different delivery mode: Specifying the CallInUIThread in Dispatcher constructor, you can choose to delivery the event in the Main Thread or in Caller Thread.
  • Thread Safe

Show me the code

Events

  1. efine Interface events:
delphi
{$M+}
IDataEvent = inteface(IInterface)
['{3522E1C5-547F-4AB6-A799-5B3D3574D2FA}']
// additional information here
// procedure OnDataReceived(Sender:IDataSender; const DataBuffer:Pointer; const DataBufferSize:Integer);
// procdure OnOpen(Sender:IDataSender);
// procedure OnClose(Sender:IDataSender);
end;
...
{$M-}
  1. repare publisher
pascal
type
  TDataModule1=class(TDataModule, IInterfaceObservable<IDataEvent>)
    ...
    FDataSubscribers:IInterfaceObservable<IDataEven>;
    ...
  published
    ...
    DataSubscribers:IInterfaceObservable<IDataEven> read FDataSubscribers;
    ...
  end;

procedure TDataModule1.DataModule1Create(Sender:TObject);
begin
  ...
  FDataSubscribers:=TDioInterfaceDispatcher<IDataEvent>.Create;
  ...
end;
  1. repare subscribers:
    • Declare your subscribing methods:
delphi
{Subscribe}
type
  TForm1=class(TForm, IDataEvent)
    procedure OnDataReceived(Sender:IDataSender; const DataBuffer:Pointer; const DataBufferSize:Integer);
    procedure OnOpen(Sender:IDataSender);
    procedure OnClose(Sender:IDataSender);
    ...
  end;
...
procedure TForm1.OnDataReceived(Sender:IDataSender; const DataBuffer:Pointer; const DataBufferSize:Integer);
begin
    //process data
end;

procedure TForm1.OnOpen(Sender:IDataSender);
begin
end;

procedure TForm1.OnClose(Sender:IDataSender);
begin
end;
  • Register your subscriber:
delphi
DataModule1.DataSubscribers.AddObserver(Form1);
  1. ost events:
delphi
DataModule1.DataSubscribers.Source.OnDataReceived(aSender, aDataBuffer, aDataBufferSize);
or
DataModule1.DataSubscribers.Source.OnOpen(aSender);
or
DataModule1.DataSubscribers.Source.OnClose(aSender);

Support

  • DED is a 100% ObjectPascal framework so it works on VCL and Firemonkey
  • It works with Delphi2010 and major

Release Notes

2020-12-11 Initial Release.

License

Copyright 2016-2020 Hezihang

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.