Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Operator not applicable (https://www.delphipraxis.net/90650-operator-not-applicable.html)

EWeiss 21. Apr 2007 09:25

Re: Operator not applicable
 
Zitat:

Zitat von Apollonius
Die Funktion scheint ja einen Zeiger zu erwarten (long* count). Probiere einfach mal, @intval zu übergeben.

Kein erfolg!
Bei intval mit oder ohne Zeiger
[Pascal Error] WMPUnit.pas(221): E2018 Record, object or class type required

If Assigned(IWmpEffects) Then
[Pascal Error] WMPUnit.pas(218): E2008 Incompatible types

If IWmpEffects <> nil Then
[Pascal Error] WMPUnit.pas(218): E2015 Operator not applicable to this operand type

Arrrrggghhhh :wall: :mrgreen:

Gruss Emil

EWeiss 21. Apr 2007 09:28

Re: Operator not applicable
 
Zitat:

Zitat von mkinzler
Du mußt es auf eine Instanz und nicht auf das Interface selber anwenden.

Jetzt verstehe ich ehrlich gesagt nur Bahnhof .. sorry
In C# OK da gibts diverse Beispiele an die man sich halten kann.

Mit der Instanz verstehe ich jetzt nicht was du da meinst.

Gruss Emil

Apollonius 21. Apr 2007 09:31

Re: Operator not applicable
 
Mir fällt da gerade was auf... in der Interfacedeklaration deines ersten Posts ist GetPresetCount eine Prozedur. Ich vermute stark, dass da die Typinkompatibilität liegt, denn du versuchst ja das nicht vorhandene Ergebnis result zuzuweisen.

Und: hast du eine Instanz(~Variable) deines interfaces? Du rufst die Routine nämlich am interface auf, du musst sie an der Variablen aufrufen.

mkinzler 21. Apr 2007 09:31

Re: Operator not applicable
 
IWmpEffects ist ein Interface und keine Instanz, die es implemnetiert.

Genausowenig wie du z.B.
Delphi-Quellcode:
if Integer = 0
schreibst sondern
Delphi-Quellcode:
i: integer;
...
   if i = 0

EWeiss 21. Apr 2007 09:36

Re: Operator not applicable
 
Zitat:

Zitat von mkinzler
IWmpEffects ist ein Interface und keine Instanz, die es implemnetiert.

Genausowenig wie du z.B.
Delphi-Quellcode:
if Integer = 0
schreibst sondern
Delphi-Quellcode:
i: integer;
...
   if i = 0

Ahh ja danke jetzt verstehe ich was du meinst.

Werds mal versuchen ;)

gruss Emil

EWeiss 21. Apr 2007 09:46

Re: Operator not applicable
 
So gehts jetzt bis auf einen Fehler ;)

Delphi-Quellcode:
function GetPresetCount(var count: LongInt): HRESULT;
Var
  IntVal: LongInt;
  WmpEffects: IWmpEffects;

begin
  If Assigned(WmpEffects) Then
    begin
       IntVal := 0;
       result := WmpEffects.GetPresetCount(IntVal);
       count := IntVal;

    end else
    result := -1;

end;
result := WmpEffects.GetPresetCount(IntVal);
[Pascal Error] WMPUnit.pas(222): E2010 Incompatible types: 'HRESULT' and 'procedure, untyped pointer or untyped parameter'

Gruss Emil

mkinzler 21. Apr 2007 09:49

Re: Operator not applicable
 
Delphi-Quellcode:
WmpEffects.GetPresetCount(IntVal);
result := IntVal;

EWeiss 21. Apr 2007 09:58

Re: Operator not applicable
 
Zitat:

Zitat von mkinzler
Delphi-Quellcode:
WmpEffects.GetPresetCount(IntVal);
result := IntVal;

Delphi-Quellcode:
function GetPresetCount(var count: LongInt): HRESULT;
Var
  IntVal: LongInt;

begin
  If Assigned(PWmpEffects) Then
    begin
       IntVal := 0;
       PWmpEffects.GetPresetCount(IntVal);
       result := IntVal;
       count := IntVal;

    end else
    result := -1;

end;
So gehts nun! Vielen Dank an alle die geholfen haben ;)
Aber eine frage noch im Anhang warum geht es nicht über die direkte Abfrage
Delphi-Quellcode:
result := PWmpEffects.GetPresetCount(IntVal);
nur auf deine weise ?

gruss Emil

Apollonius 21. Apr 2007 10:06

Re: Operator not applicable
 
Ich habe schon mal einen Post dazu geschrieben (#13). In deiner Interfacedeklaration ist getPresetCount eine Prozedur, und die gibt nunmal nichts zurück, das du zuweisen könntest.

mkinzler 21. Apr 2007 10:06

Re: Operator not applicable
 
Zitat:

Aber eine frage noch im Anhang warum geht es nicht über die direkte Abfrage
Weil die Methode keinen Rückgabewert hat, sondern einen var-Parameter(Zeiger)

Delphi-Quellcode:
IWMPEffects = interface(IUnknown)
   ['{D3984C13-C3CB-48e2-8BE5-5168340B4F35}']
   procedure GetPresetCount(var pnPresetCount : LongInt); safecall;
Deshalb wird versucht Result die Methode zuzuweisen, was obigen Fehler auslöst.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:40 Uhr.
Seite 2 von 3     12 3      

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