Ver Fonte

* removed IImplementorGetter interface and replaced it by the guid IObjectReference.
* GetInterface and GetInterfaceWeak is modified so that when querying for IObjectReference not an interface is returned but the object pointer

git-svn-id: trunk@15087 -

ivost há 15 anos atrás
pai
commit
a6022f5df2
3 ficheiros alterados com 25 adições e 55 exclusões
  1. 19 38
      rtl/inc/objpas.inc
  2. 5 9
      rtl/inc/objpash.inc
  3. 1 8
      rtl/objpas/sysutils/sysuintf.inc

+ 19 - 38
rtl/inc/objpas.inc

@@ -118,18 +118,9 @@
 
     function fpc_intf_is_class(const S: pointer; const aclass: tclass): Boolean;[public,alias: 'FPC_INTF_IS_CLASS']; compilerproc;
       var
-        tmpi: pointer;
         tmpo: tobject;
       begin
-        tmpi := nil;
-        if Assigned(S) and (IUnknown(S).QueryInterface(IImplementorGetter,tmpi)=S_OK) then
-          begin
-            tmpo := IImplementorGetter(tmpi).GetObject;
-            IUnknown(tmpi)._Release;
-            fpc_intf_is_class:=Assigned(tmpo) and tmpo.InheritsFrom(aclass);
-          end
-        else
-          fpc_intf_is_class:=false;
+        fpc_intf_is_class:=Assigned(S) and (IUnknown(S).QueryInterface(IObjectInstance,tmpo)=S_OK)  and tmpo.InheritsFrom(aclass);
       end;
 
 
@@ -167,19 +158,10 @@
 
     function fpc_intf_cast_class(const S: pointer; const aclass: tclass): pointer;[public,alias: 'FPC_INTF_CAST_CLASS']; compilerproc;
       var
-        tmpi: pointer;
         tmpo: tobject;
       begin
-        tmpi:=nil;
-        if Assigned(S) and (IUnknown(S).QueryInterface(IImplementorGetter,tmpi)=S_OK) then
-          begin
-            tmpo := IImplementorGetter(tmpi).GetObject;
-            IUnknown(tmpi)._Release;
-            if Assigned(tmpo) and tmpo.InheritsFrom(aclass) then
-              fpc_intf_cast_class:=tmpo
-            else
-              fpc_intf_cast_class:=nil;
-          end
+        if Assigned(S) and (IUnknown(S).QueryInterface(IObjectInstance,tmpo)=S_OK) and tmpo.InheritsFrom(aclass) then
+          fpc_intf_cast_class:=tmpo
         else
           fpc_intf_cast_class:=nil;
       end;
@@ -229,22 +211,13 @@
 
     function fpc_intf_as_class(const S: pointer; const aclass: tclass): pointer;[public,alias: 'FPC_INTF_AS_CLASS']; compilerproc;
       var
-        tmpi: pointer;
         tmpo: tobject;
       begin
         if assigned(S) then
           begin
-            tmpi := nil;
-            if IUnknown(S).QueryInterface(IImplementorGetter,tmpi)=S_OK then
-              begin
-                tmpo := IImplementorGetter(tmpi).GetObject;
-                IUnknown(tmpi)._Release;
-                if not assigned(tmpo) or not tmpo.inheritsfrom(aclass) then
-                  handleerror(219);
-                fpc_intf_as_class:=tmpo;
-              end
-            else
+            if not ((IUnknown(S).QueryInterface(IObjectInstance,tmpo)=S_OK) and tmpo.inheritsfrom(aclass)) then
               handleerror(219);
+            fpc_intf_as_class:=tmpo;
           end
         else
           fpc_intf_as_class:=nil;
@@ -802,6 +775,13 @@
           IEntry: PInterfaceEntry;
           Instance: TObject;
         begin
+          if IsGUIDEqual(IObjectInstance,iid) then
+          begin
+            TObject(Obj) := Self;
+            Result := True;
+            Exit;
+          end;
+
           Instance := self;
           repeat
             IEntry := Instance.GetInterfaceEntry(iid);
@@ -828,6 +808,13 @@
           IEntry: PInterfaceEntry;
           Instance: TObject;
         begin
+          if IsGUIDEqual(IObjectInstance,iid) then
+          begin
+            TObject(Obj) := Self;
+            Result := True;
+            Exit;
+          end;
+
           Instance := self;
           repeat
             IEntry := Instance.GetInterfaceEntry(iid);
@@ -1003,12 +990,6 @@
            self.destroy;
       end;
 
-    function TInterfacedObject.GetObject : TObject;
-
-      begin
-         GetObject:=Self;
-      end;
-
     procedure TInterfacedObject.AfterConstruction;
 
       begin

+ 5 - 9
rtl/inc/objpash.inc

@@ -279,21 +279,13 @@
             VarResult,ExcepInfo,ArgErr : pointer) : HResult;stdcall;
        end;
 
-       { for safe as operator support }
-       IImplementorGetter = interface
-         ['{D91C9AF4-3C93-420F-A303-BF5BA82BFD23}']
-         function GetObject : TObject;
-       end;
-
-       TInterfacedObject = class(TObject,IUnknown,IImplementorGetter)
+       TInterfacedObject = class(TObject,IUnknown)
        protected
           frefcount : longint;
           { implement methods of IUnknown }
           function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
           function _AddRef : longint;stdcall;
           function _Release : longint;stdcall;
-          { implement methods of IImplementorGetter }
-          function GetObject : TObject;
         public
           procedure AfterConstruction;override;
           procedure BeforeDestruction;override;
@@ -431,3 +423,7 @@
 
   var
     DispCallByIDProc : pointer;
+
+  const
+    { for safe as operator support }
+    IObjectInstance: TGuid = '{D91C9AF4-3C93-420F-A303-BF5BA82BFD23}';

+ 1 - 8
rtl/objpas/sysutils/sysuintf.inc

@@ -21,15 +21,8 @@
 }
 
 function Supports(const Instance: IInterface; const AClass: TClass; out Obj): Boolean;
-var
-  Getter: IImplementorGetter;
 begin
-  if (Instance<>nil) and (Instance.QueryInterface(IImplementorGetter,Getter)=S_OK) then
-  begin
-    TObject(Obj) := Getter.GetObject;
-    Result := Assigned(TObject(Obj)) and (TObject(Obj).InheritsFrom(AClass));
-  end else
-    Result := False;
+  Result := (Instance<>nil) and (Instance.QueryInterface(IObjectInstance,Obj)=S_OK) and (TObject(Obj).InheritsFrom(AClass));
 end;
 
 function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean;