Snippets
Created by
Stefan Glienke
last modified
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | unit Main;
interface
procedure Register;
implementation
uses
ToolsAPI,
TlHelp32,
SysUtils,
Windows,
PsAPI,
Vcl.Dialogs,
UITypes;
type
TCompileNotifier = class(TInterfacedObject, IOTAIDENotifier, IOTAIDENotifier50)
public
procedure AfterCompile(Succeeded: Boolean); overload;
procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
procedure FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
procedure AfterSave;
procedure BeforeSave;
procedure Destroyed;
procedure Modified;
procedure BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean;
var Cancel: Boolean); overload;
procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean); overload;
end;
var
notifier: Integer;
procedure Register;
begin
notifier := (BorlandIDEServices as IOTAServices).AddNotifier(TCompileNotifier.Create);
end;
procedure Unregister;
begin
(BorlandIDEServices as IOTAServices).RemoveNotifier(notifier);
end;
function GetFullFileName(processId: Cardinal): string;
var
process: THandle;
path: array[0..MAX_PATH - 1] of Char;
begin
process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, processId);
if process <> 0 then
try
if GetModuleFileNameEx(process, 0, path, MAX_PATH) <> 0 then
Exit(path);
finally
CloseHandle(process);
end;
Result := '';
end;
function TerminateProcess(const exeFileName: string): Boolean;
const
PROCESS_TERMINATE = $0001;
var
snapshot: THandle;
entry: TProcessEntry32;
canContinue: Boolean;
begin
Result := False;
snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
try
entry.dwSize := SizeOf(entry);
canContinue := Process32First(snapshot, entry);
while canContinue do
begin
if SameText(GetFullFileName(entry.th32ProcessID), exeFileName) then
if MessageDlg('Process is still running - do you want to stop it?',
mtConfirmation, mbYesNo, 0) = mrYes then
Result := Windows.TerminateProcess(
OpenProcess(PROCESS_TERMINATE, False, entry.th32ProcessID), 0);
canContinue := Process32Next(snapshot, entry);
end;
finally
CloseHandle(snapshot);
end;
end;
{ TCompileNotifier }
procedure TCompileNotifier.AfterCompile(Succeeded: Boolean);
begin
end;
procedure TCompileNotifier.AfterCompile(Succeeded, IsCodeInsight: Boolean);
begin
end;
procedure TCompileNotifier.AfterSave;
begin
end;
procedure TCompileNotifier.BeforeCompile(const Project: IOTAProject;
var Cancel: Boolean);
begin
end;
procedure TCompileNotifier.BeforeCompile(const Project: IOTAProject;
IsCodeInsight: Boolean; var Cancel: Boolean);
begin
if not IsCodeInsight and Assigned(Project)
and Assigned(Project.ProjectOptions) then
TerminateProcess(Project.ProjectOptions.TargetName);
end;
procedure TCompileNotifier.BeforeSave;
begin
end;
procedure TCompileNotifier.Destroyed;
begin
end;
procedure TCompileNotifier.FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
begin
end;
procedure TCompileNotifier.Modified;
begin
end;
initialization
finalization
Unregister;
end.
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.