mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 07:09:23 +02:00
* added supports helper functions for IInterface supports TClass -> TObject,Boolean
git-svn-id: trunk@15086 -
This commit is contained in:
parent
561997e8ef
commit
7025b1ac01
@ -23,12 +23,16 @@
|
|||||||
const
|
const
|
||||||
GUID_NULL: TGuid = '{00000000-0000-0000-0000-000000000000}';
|
GUID_NULL: TGuid = '{00000000-0000-0000-0000-000000000000}';
|
||||||
|
|
||||||
|
function Supports(const Instance: IInterface; const AClass: TClass; out Obj): Boolean; overload;
|
||||||
function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean; overload;
|
function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean; overload;
|
||||||
function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload;
|
function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload;
|
||||||
function Supports(const Instance: TObject; const IID: Shortstring; out Intf): Boolean; overload;
|
function Supports(const Instance: TObject; const IID: Shortstring; out Intf): Boolean; overload;
|
||||||
|
|
||||||
|
function Supports(const Instance: IInterface; const AClass: TClass): Boolean; overload;
|
||||||
function Supports(const Instance: IInterface; const IID: TGUID): Boolean; overload;
|
function Supports(const Instance: IInterface; const IID: TGUID): Boolean; overload;
|
||||||
function Supports(const Instance: TObject; const IID: TGUID): Boolean; overload;
|
function Supports(const Instance: TObject; const IID: TGUID): Boolean; overload;
|
||||||
function Supports(const Instance: TObject; const IID: Shortstring): Boolean; overload;
|
function Supports(const Instance: TObject; const IID: Shortstring): Boolean; overload;
|
||||||
|
|
||||||
function Supports(const AClass: TClass; const IID: TGUID): Boolean; overload;
|
function Supports(const AClass: TClass; const IID: TGUID): Boolean; overload;
|
||||||
function Supports(const AClass: TClass; const IID: Shortstring): Boolean; overload;
|
function Supports(const AClass: TClass; const IID: Shortstring): Boolean; overload;
|
||||||
|
|
||||||
|
@ -20,6 +20,18 @@
|
|||||||
System Utilities For Free Pascal
|
System Utilities For Free Pascal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
end;
|
||||||
|
|
||||||
function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean;
|
function Supports(const Instance: IInterface; const IID: TGUID; out Intf): Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=(Instance<>nil) and (Instance.QueryInterface(IID,Intf)=S_OK);
|
Result:=(Instance<>nil) and (Instance.QueryInterface(IID,Intf)=S_OK);
|
||||||
@ -40,6 +52,15 @@ begin
|
|||||||
Result:=(Instance<>nil) and Instance.GetInterface(IID,Intf);
|
Result:=(Instance<>nil) and Instance.GetInterface(IID,Intf);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function Supports(const Instance: IInterface; const AClass: TClass): Boolean;
|
||||||
|
var
|
||||||
|
Temp: TObject;
|
||||||
|
begin
|
||||||
|
Result:=Supports(Instance,AClass,Temp);
|
||||||
|
end;
|
||||||
|
|
||||||
function Supports(const Instance: IInterface; const IID: TGUID): Boolean;
|
function Supports(const Instance: IInterface; const IID: TGUID): Boolean;
|
||||||
var
|
var
|
||||||
Temp: IInterface;
|
Temp: IInterface;
|
||||||
@ -59,6 +80,8 @@ begin
|
|||||||
Result:=(Instance<>nil) and (Instance.GetInterfaceEntryByStr(IID)<>nil);
|
Result:=(Instance<>nil) and (Instance.GetInterfaceEntryByStr(IID)<>nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Supports(const AClass: TClass; const IID: TGUID): Boolean;
|
function Supports(const AClass: TClass; const IID: TGUID): Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=(AClass<>nil) and (AClass.GetInterfaceEntry(IID)<>nil);
|
Result:=(AClass<>nil) and (AClass.GetInterfaceEntry(IID)<>nil);
|
||||||
@ -70,13 +93,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function StringToGUID(const S: string): TGUID;
|
function StringToGUID(const S: string): TGUID;
|
||||||
begin
|
begin
|
||||||
if not TryStringToGUID(S, Result) then
|
if not TryStringToGUID(S, Result) then
|
||||||
raise EConvertError.CreateFmt(SInvalidGUID, [S]);
|
raise EConvertError.CreateFmt(SInvalidGUID, [S]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
|
function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
|
||||||
var
|
var
|
||||||
e: Boolean;
|
e: Boolean;
|
||||||
@ -124,7 +147,6 @@ begin
|
|||||||
Result := e;
|
Result := e;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function IsEqualGUID(const guid1, guid2: TGUID): Boolean;
|
function IsEqualGUID(const guid1, guid2: TGUID): Boolean;
|
||||||
var
|
var
|
||||||
a1,a2: PIntegerArray;
|
a1,a2: PIntegerArray;
|
||||||
@ -137,7 +159,6 @@ begin
|
|||||||
(a1^[3]=a2^[3]);
|
(a1^[3]=a2^[3]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function GuidCase(const GUID: TGUID; const List: array of TGuid): Integer;
|
function GuidCase(const GUID: TGUID; const List: array of TGuid): Integer;
|
||||||
begin
|
begin
|
||||||
for Result := High(List) downto 0 do
|
for Result := High(List) downto 0 do
|
||||||
@ -146,7 +167,6 @@ begin
|
|||||||
Result := -1;
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function GUIDToString(const GUID: TGUID): string;
|
function GUIDToString(const GUID: TGUID): string;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 38);
|
SetLength(Result, 38);
|
||||||
|
Loading…
Reference in New Issue
Block a user