AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign Delphi Den Delegaten nachträglich ändern - Unterschiedliches Verhalten
Thema durchsuchen
Ansicht
Themen-Optionen

Den Delegaten nachträglich ändern - Unterschiedliches Verhalten

Ein Thema von Der schöne Günther · begonnen am 29. Jan 2014 · letzter Beitrag vom 30. Jan 2014
 
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#9

AW: Den Delegaten nachträglich ändern - Unterschiedliches Verhalten

  Alt 29. Jan 2014, 22:48
Fast ... so sollte das gehen
Delphi-Quellcode:
  ISomeInterface = interface
    ['{A06F92AD-9E22-4EA9-9770-3B02C2AE8E5A}']
    procedure SomeProc( );
  end;

  IProxy<T : IInterface> = interface
    //['{AF691ABC-D561-4E5D-BFF1-AC30D97F007A}'] nicht bei Generics!
    procedure setDelegate( const delegate : T );
    function getDelegate( ) : T;
  end;

  TSomeInterfaceProxy = class( TInterfacedObject, ISomeInterface, IProxy<ISomeInterface> )
  private
    myDelegate : ISomeInterface;
  private
    constructor Create( const realDelegate : ISomeInterface );

    // ISomeInterface Delegate
    procedure DelegateSomeProc( );
    procedure ISomeInterface.SomeProc = DelegateSomeProc;

    // IProxy<ISomeInterface>
    procedure setDelegate( const delegate : ISomeInterface );
    function getDelegate( ) : ISomeInterface;
  public
    class function Construct( const realDelegate : ISomeInterface ) : ISomeInterface;
    class function ConstructProxy( const realDelegate : ISomeInterface ) : IProxy<ISomeInterface>;
  end;

{ TSomeInterfaceProxy }

class function TSomeInterfaceProxy.Construct( const realDelegate : ISomeInterface ) : ISomeInterface;
begin
  Result := TSomeInterfaceProxy.Create( realDelegate );
end;

class function TSomeInterfaceProxy.ConstructProxy( const realDelegate : ISomeInterface ) : IProxy<ISomeInterface>;
begin
  Result := TSomeInterfaceProxy.Create( realDelegate );
end;

constructor TSomeInterfaceProxy.Create( const realDelegate : ISomeInterface );
begin
  inherited Create;
  myDelegate := realDelegate;
end;

procedure TSomeInterfaceProxy.DelegateSomeProc;
begin
  getDelegate.SomeProc;
end;

function TSomeInterfaceProxy.getDelegate : ISomeInterface;
begin
  Result := myDelegate;
end;

procedure TSomeInterfaceProxy.setDelegate( const delegate : ISomeInterface );
begin
  myDelegate := delegate;
end;
und dann so benutzen
Delphi-Quellcode:
var
  LProxy : IProxy<ISomeInterface>;
  LSome : ISomeInterface;

LProxy := TSomeInterfaceProxy.Construct( TSome.Create );
Supports( LProxy, ISomeInterface, LSome );

LSome.SomeProc; // TSome.SomeProc
LProxy.setDelegate( TSomeOther.Create );
LSome.SomeProc; // TSomeOther.SomeProc
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (29. Jan 2014 um 23:00 Uhr)
  Mit Zitat antworten Zitat
 

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz