AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

gemischter Interface-/Objektzugriff

Ein Thema von Lemmy · begonnen am 18. Mai 2017 · letzter Beitrag vom 24. Mai 2017
 
freimatz

Registriert seit: 20. Mai 2010
1.490 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: gemischter Interface-/Objektzugriff

  Alt 18. Mai 2017, 17:24
Bischen viel Quote, Sorry
a) Foo auch auf das Interface geben.
b) ein zweiters Interface machen
a) will ich nicht, weil der Konsument da nix zu schreiben hat. und b) Zeig doch bitte Code
ok ich ergänze gleich mal deinen

Delphi-Quellcode:
  IFooItem = Interface
   ['{9995E78E-45DF-4C25-B657-7396738FEA70}']
   procedure Bar;
  end;

  IFooFooItem =Interface
   ['{9995E78E-45DF-4C25-B657-7396738FEA70}']
    procedure Foo(const AValue);
  end;

  TFooItem = class(TinterfacedObject, IFooItem, IFooFooItem)
  public
    procedure Bar;
    procedure Foo(const AValue);
  end;
  
  function CreateItem():IFooItem;
  
...
  
  function CreateItem():IFooItem;
  begin
    Item := TFooItem.Create() as IFooItem;
  end;
und jetzt der Owner:

Delphi-Quellcode:
 TFooOwner = class
  private
    Fitem: IFooItem
    function GetItem: IFooItem
  public
    property Item: IFooItem getItem;
    property FooItem: IFooFooItem GetFooItem;
  end;
...
procedure TFooOwner.DoAbc();
var FooFooItem: IFooFooItem;
begin
  if not Supports(Item, IFooFooItem) then raise EPanic...;
  FooFooItem := Item as IFooFooItem;
  FooFooItem.Foo(abc)
end;
Wie wird jetzt die Instanz von FItem gespeichert? Als einzigste Lösung würde mir wieder die ObjektInstanz einfallen und in den Get* Methoden dann ein GetInterface(IFooXItem, Result)aber dann habe ich wieder einen Zugriff auf die Objektinstanz!?!?
Gespeichert als interface. Immer und überall. Vermischen ist böse.
Die beiden interfaces würde ich dann auch nicht in eine unit packen.
  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 19:09 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