AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign IInvokable nachträglich einem Interface hinzufügen
Thema durchsuchen
Ansicht
Themen-Optionen

IInvokable nachträglich einem Interface hinzufügen

Ein Thema von WiPhi · begonnen am 3. Sep 2018 · letzter Beitrag vom 6. Sep 2018
 
Schokohase
(Gast)

n/a Beiträge
 
#4

AW: IInvokable nachträglich einem Interface hinzufügen

  Alt 4. Sep 2018, 15:36
Nein, so sollst du das machen
Delphi-Quellcode:
unit Unit1;

interface

type
  IFoo = interface
    ['{45486F85-F11C-47B8-A85A-328C8845CA41}']
    procedure Foo( );
  end;

implementation

end.
Delphi-Quellcode:
unit Unit2;

interface

type
{$M+}
  IMirrorFoo = interface
    ['{B5628A7F-7ECF-4123-A079-0193C8894185}']
    procedure Foo( );
  end;
{$M-}

implementation

end.
Delphi-Quellcode:
program MockMock;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  System.Rtti,
  Delphi.Mocks,
  Unit1 in 'Unit1.pas',
  Unit2 in 'Unit2.pas';

procedure Test( );
var
  mock: TMock<IMirrorFoo>;
  mirror: IMirrorFoo;
  org: IFoo;
begin
  mock := TMock<IMirrorFoo>.Create( );
  mock.Setup.WillExecute( 'Foo', function( const args: TArray<TValue>; const ReturnType: TRttiType ): TValue
    begin
      WriteLn( 'Foo called' );
    end );
  mirror := mock;
  org := IFoo( mirror );
  org.Foo();
end;

begin
  try
    Test( );
  except
    on E: Exception do
      Writeln( E.ClassName, ': ', E.Message );
  end;
  ReadLn;
end.
  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 22:11 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