-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaceFunctions.pas
More file actions
42 lines (27 loc) · 895 Bytes
/
InterfaceFunctions.pas
File metadata and controls
42 lines (27 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
unit InterfaceFunctions;
interface
uses
SysUtils,
Classes;
function AsInterface(TargetInterface: IInterface; RequiredInterfaceGUID: TGUID): IInterface;
function AsInterfaceOrException(TargetInterface: IInterface; RequiredInterfaceGUID: TGUID; ExceptionMessage: String): IInterface;
implementation
function AsInterfaceOrException(
TargetInterface: IInterface;
RequiredInterfaceGUID: TGUID;
ExceptionMessage: String
): IInterface;
begin
Result := AsInterface(TargetInterface, RequiredInterfaceGUID);
if not Assigned(Result) then
Raise Exception.Create(ExceptionMessage);
end;
function AsInterface(TargetInterface: IInterface; RequiredInterfaceGUID: TGUID): IInterface;
var
RequiredInterface: IInterface;
begin
if Supports(TargetInterface, RequiredInterfaceGUID, RequiredInterface) then
Result := RequiredInterface
else Result := nil;
end;
end.