Ich würde so für so etwas einen zentralen Nachrichtenverteiler in dein Hauptprogramm einbauen, bei dem sich die Plugins registrieren, wenn sie bestimmte Nachrichten empfangen wollen. Nachrichten kann man durch String-Konstanten (so funktioniert es in einen System, das ich mal gebaut habe) oder wie Window-Messages von Windows durch einen Integer identifizieren.
Ich habe als Nachrichtenverteiler eine Singleton-Klasse
TNotificationCenter, die (unter anderem) folgende Methoden hat:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| try TNotificationEvent = procedure (sender : TNotificationCenter; notification : TNotification) of object;
TNotificationCenter = class private ... public class function DefaultCenter : TNotificationCenter;
procedure AddObserver(const AObserver : TObject; const AEvent : TNotificationEvent; const ANotification : string = ''); procedure RemoveObserver(const AObserver : TObject; const ANotification : string = '');
procedure SendNotification(const ANotification : string; const ASender : TObject; const AUserInfo : TObject = nil; const AUserValue : string = ''); end; |
Gemeinsamer Zugriff deiner Plugins auf eine einzelne Singleton-Klasse wird allerdings nur funktionieren, wenn die Plugsins dynamisch geladene Delphi-Packages (bpl) sind. Bei DLLs müssten du die Funktionen des NotificationCenters über Callbacks aufrufen.
Stefan
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.