Autor Beitrag
locutus2k5
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 33

Windows Vista Ultimate
BDS2005
BeitragVerfasst: Do 24.05.07 11:28 
Hallo!

Ich habe ein Pluginsystem, bei dem gefordert ist das die Plugins auch untereinander kommunizieren können, doch wie realisiere ich das?

Mittels Messages wäre eine Möglichkeit, jedoch habe ich auch mal was über TMemoryStreams gelesen. Hat noch jemand eine andere Idee wie eine Kommunikation möglich wäre?
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Do 24.05.07 11:32 
Naja, eine Realisierung über Events wäre vielleicht möglich?
Ob das geht kann ich nicht sagen, da ich deine Pluginstruktur nicht kenne.
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Do 24.05.07 12:08 
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:

ausblenden 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
    // Zugriff auf die Singleton-Instanz
    class function DefaultCenter : TNotificationCenter; 

    // Regisrtiert sich ein Objekt AObserver für Nachrichten mit dem Namen ANotification
    // trifft eine solche Nachricht ein, wird AEvent aufgerufen
    procedure AddObserver(const AObserver : TObject;
                          const AEvent : TNotificationEvent;
                          const ANotification : string = ''); 
    // hebt die Registrierung des Objekts AObserver für Nachrichten des Names ANotification auf
    // wenn man ANotification leer lässt, wird die Registrerung für alle Nachrichten aufgehoben
    procedure RemoveObserver(const AObserver : TObject;
                             const ANotification : string = '');

    // Sendet eine Nachricht mit dem Namen ANotification an alle registrierten Objekte
    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.
locutus2k5 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 33

Windows Vista Ultimate
BDS2005
BeitragVerfasst: Fr 25.05.07 00:23 
Vielen danke für die Info's!
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Fr 25.05.07 08:20 
user profile iconlocutus2k5 hat folgendes geschrieben:
Vielen danke für die Info's!

Nein Nein Nein :autsch:
siehe: www.deppenapostroph.de/

_________________
In the beginning was the word.
And the word was content-type: text/plain.
locutus2k5 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 33

Windows Vista Ultimate
BDS2005
BeitragVerfasst: Fr 25.05.07 18:31 
Ich find's toll so wie's 'is, gell?
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Fr 25.05.07 18:45 
[OT]
user profile iconlocutus2k5 hat folgendes geschrieben:
Ich find's toll so wie's 'is, gell?

Hey, und jetz sind sogar fast alle Apostrophs an der richtigen Stelle; bis auf das 'is ist's OK. :lol:
[/OT]

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]