-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ProductivityExpertsOTAUtils.pas
98 lines (81 loc) · 2.54 KB
/
ProductivityExpertsOTAUtils.pas
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//---------------------------------------------------------------------------
// This software is Copyright (c) 2011 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
// of Delphi, C++Builder or RAD Studio (Embarcadero Products).
// This software is considered a Redistributable as defined under
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.
//---------------------------------------------------------------------------
unit ProductivityExpertsOTAUtils;
interface
uses
ToolsAPI;
type
TOTADebugMsg = class
end;
function FindModuleInterface(AInterface: TGUID): IUnknown;
function GetCurrentProjectGroup: IOTAProjectGroup;
function GetCurrentProject: IOTAProject;
function ProjectExists(AProject: IOTAProject): Boolean;
{$IF CompilerVersion >= 16.0} // Delphi 8 or later
type
TPersonality = (Unknown, BCB, DelphiWin32);
function ProjectPersonality(AProject: IOTAProject): TPersonality;
function PersonalityToDisplayName(APersonality: TPersonality): string;
{$IFEND}
implementation
uses
Windows, SysUtils;
{$IF CompilerVersion >= 16.0} // Delphi 8 or later
function ProjectPersonality(AProject: IOTAProject): TPersonality;
var
LPersonality: string;
begin
Result := Unknown;
LPersonality := AProject.Personality;
if LPersonality = sCBuilderPersonality then
Result := BCB else
if LPersonality = sDelphiPersonality then
Result := DelphiWin32;
end;
function PersonalityToDisplayName(APersonality: TPersonality): string;
begin
case APersonality of
BCB: Result := 'C++';
DelphiWin32: Result := 'Delphi Win32';
end;
end;
{$IFEND}
function FindModuleInterface(AInterface: TGUID): IUnknown;
var
I: Integer;
begin
Result := nil;
with BorlandIDEServices as IOTAModuleServices do
for I := 0 to ModuleCount - 1 do
if (Modules[I].QueryInterface(AInterface, Result) = S_OK) then
Break;
end;
function GetCurrentProjectGroup: IOTAProjectGroup;
begin
Result := FindModuleInterface(IOTAProjectGroup) as IOTAProjectGroup;
end;
function GetCurrentProject: IOTAProject;
var
ProjectGroup: IOTAProjectGroup;
begin
ProjectGroup := GetCurrentProjectGroup;
if Assigned(ProjectGroup) then
Result := ProjectGroup.ActiveProject
else
Result := FindModuleInterface(IOTAProject) as IOTAProject;
end;
function ProjectExists(AProject: IOTAProject): Boolean;
var
LProject: TInterfacedObject;
begin
Result := False;
if Supports(AProject, IUnknown, LProject) then
Result := LProject.RefCount>1;
end;
end.