Browse Source

+ add TValue.AsInterface to retrieve a COM style interface again

git-svn-id: trunk@36969 -
svenbarth 8 years ago
parent
commit
9c0423b3a4
1 changed files with 8 additions and 0 deletions
  1. 8 0
      packages/rtl-objpas/src/inc/rtti.pp

+ 8 - 0
packages/rtl-objpas/src/inc/rtti.pp

@@ -85,6 +85,7 @@ type
     function AsBoolean: boolean;
     function AsCurrency: Currency;
     function AsInteger: Integer;
+    function AsInterface: IInterface;
     function ToString: String;
     function IsType(ATypeInfo: PTypeInfo): boolean; inline;
     function TryAsOrdinal(out AResult: int64): boolean;
@@ -814,6 +815,13 @@ begin
     raise EInvalidCast.Create(SErrInvalidTypecast);
 end;
 
+function TValue.AsInterface: IInterface;
+begin
+  if Kind <> tkInterface then
+    EInvalidCast.Create(SErrInvalidTypecast);
+  Result := PInterface(FData.FValueData.GetReferenceToRawData)^;
+end;
+
 function TValue.ToString: String;
 begin
   case Kind of