Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   E2232 Interface 'x' besitzt keine Interface-Identifikation? (https://www.delphipraxis.net/185937-e2232-interface-x-besitzt-keine-interface-identifikation.html)

Whookie 20. Jul 2015 12:40

Delphi-Version: XE8

E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Hänge gerade an einem Interface - Problem und verstehe nicht wieso ich den E2232 Fehler (oder im Alternativfall kein Interface bekomme)!

Folgendes leeres Delphi VCL Projekt (leere Form):
Delphi-Quellcode:
unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}


Const
  MyIntfAGuid: TGuid = '{23D5751F-8368-4672-ACFC-3BF667F1F544}';

Type
  IMyIntfA = Interface
    [MyIntfAGuid]
    procedure foo;
  End;


  TMyClass = Class(TInterfacedObject, IMyIntfA)
    procedure foo;
  End;



{ TMyClass }

procedure TMyClass.foo;
begin
end;

procedure TForm2.FormCreate(Sender: TObject);
var
  LMy: TMyClass;
  LIMyA: IMyIntfA;
  x: Integer;
begin
  LMy := TMyClass.Create;

  // so gibts E2232
  if Supports(LMy, IMyIntfA) then
  begin
    x := 3;
  end;

  // so gibts kein Interface
  if LMy.QueryInterface(MyIntfAGuid, LIMyA) = S_OK then
  begin
    x := 3;
  end;


  LMy.Free;
end;

end.

Irgendwas mache ich offensichtlich falsch....?

stahli 20. Jul 2015 12:54

AW: E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Ob´s das ist, weiß ich nicht, aber ich kenne die Deklaration so:

Delphi-Quellcode:
Const
   MyIntfAGuid = '{23D5751F-8368-4672-ACFC-3BF667F1F544}';

Whookie 20. Jul 2015 12:58

AW: E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Zitat:

Zitat von stahli (Beitrag 1309267)
Ob´s das ist, weiß ich nicht, aber ich kenne die Deklaration so:

Delphi-Quellcode:
Const
   MyIntfAGuid = '{23D5751F-8368-4672-ACFC-3BF667F1F544}';

Hatte ich auch schon probiert aber dann mäkelt der Compiler bei:

Delphi-Quellcode:
if LMy.QueryInterface(MyIntfAGuid, LIMyA) = S_OK then
mit E2010 Inkompatible Typen: 'TGUID' und 'string' rum

Bambini 20. Jul 2015 13:01

AW: E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Zitat:

Zitat von Whookie (Beitrag 1309266)
Irgendwas mache ich offensichtlich falsch....?

Vermutlich kannst du die GUID für das Interface nur so angeben:

Delphi-Quellcode:
  IMyIntfA = Interface
    ['{23D5751F-8368-4672-ACFC-3BF667F1F544}']
    procedure foo;
  End;

Union 20. Jul 2015 13:23

AW: E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Nein, Du brauchst 2:

Delphi-Quellcode:
const

  MyStringIntfAGuid = '{23D5751F-8368-4672-ACFC-3BF667F1F544}';
  MyGuidIntfAGuid : TGUID = MyStringIntfAGuid;

Type
  IMyIntfA = Interface(IUnknown)
    [MyStringIntfAGuid] // Hier den Stringtyp verwenden, wird vom Compiler umgewandelt in Recordtypen
    procedure foo;
  End;
  ...
  // so gibts ein Interface
  if LMy.QueryInterface(MyGuidIntfAGuid, LIMyA) = S_OK then
Und das Free unterläßt Du besser ;)

jaenicke 20. Jul 2015 14:03

AW: E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Warum eigentlich so kompliziert? Warum nicht einfach so:
Delphi-Quellcode:
type
  IMyIntfA = Interface(IUnknown)
  ['{23D5751F-8368-4672-ACFC-3BF667F1F544}']
    procedure foo;
  end;

  // so gibts ein Interface
  if LMy.QueryInterface(IMyIntfA, LIMyA) = S_OK then

// oder
  if Supports(LMy, IMyIntfA, LIMyA) then

Whookie 20. Jul 2015 16:18

AW: E2232 Interface 'x' besitzt keine Interface-Identifikation?
 
Danke, wieder was dazugelernt!


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:31 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz