Delphi Event Bus (for short DEB) is a publish/subscribe Event Bus framework for the Delphi platform.
DEB is designed to decouple different parts/layers of your application while still allowing them to communicate efficiently. It was inspired by EventBus framework for the Android platform.
Please "star" this project in GitHub! It costs nothing but helps to reference the code
1.Define events:
IEvent = interface(IInterface)
['{3522E1C5-547F-4AB6-A799-5B3D3574D2FA}']
// additional information here
end;
2.Prepare subscribers:
Declare your subscribing method:
[Subscribe]
procedure OnEvent(AEvent: IAnyTypeOfEvent);
begin
// manage the event
end;
Register your subscriber:
GlobalEventBus.RegisterSubscriberForEvents(Self);
3.Post events:
GlobalEventBus.post(LEvent);
1.Define channel:
const MY_CHANNEL = 'MYCHANNEL'
2.Prepare subscribers:
Declare your subscribing method:
[Channel(MY_CHANNEL)]
procedure OnMessage(AMsg: string);
begin
// manage the message
end;
Register your subscriber:
GlobalEventBus.RegisterSubscriberForChannels(Self);
3.Post event on channel:
GlobalEventBus.post(MY_CHANNEL, 'My Message');
Copyright 2016-2022 Daniele Spinetti
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.