-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
OTAUtils.pas
90 lines (78 loc) · 2.24 KB
/
OTAUtils.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
unit OTAUtils;
interface
uses
ToolsAPI;
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, CSharp, DelphiNET, DelphiWin32, VB);
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 = sCSharpPersonality then
Result := CSharp else
if LPersonality = sDelphiDotNetPersonality then
Result := DelphiNET else
if LPersonality = sDelphiPersonality then
Result := DelphiWin32 else
if LPersonality = sVBPersonality then
Result := VB;
end;
function PersonalityToDisplayName(APersonality: TPersonality): string;
begin
case APersonality of
BCB: Result := 'C++';
CSharp: Result := 'C#';
DelphiNET: Result := 'Delphi.NET';
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.