{$DEFINE Meckermodus}
unit BeforeAfterCompileExperteUnit1;
interface
{$I-}
uses
ToolsAPI;
Type
TBeforeCompile =
class(TNotifierObject, IOTAIDENotifier, IOTAIDENotifier50, IOTAWizard, IOTAMenuWizard)
protected
procedure AfterCompile(Succeeded: Boolean);
overload;
procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean);
overload;
procedure BeforeCompile(
const Project: IOTAProject;
var Cancel: Boolean);
overload;
procedure BeforeCompile(
const Project: IOTAProject; IsCodeInsight: Boolean;
var Cancel: Boolean);
overload;
procedure FileNotification(NotifyCode: TOTAFileNotification;
const FileName:
string;
var Cancel: Boolean);
public
function GetMenuText :
string;
function GetIDString :
string;
function GetName :
string;
function GetState : TWizardState;
procedure Execute;
constructor Create;
function AddNotifier(
const Notifier: IOTAIDENotifier50) : Integer;
procedure RemoveNotifier(
Index: Integer);
end;
procedure Register;
implementation
uses
SysUtils,
Dialogs,
Classes,
ShellAPI;
Var
// Die werden nicht alle gebraucht, sind nur hier, um zu sehen,
// was es so gibt.
MainServices : INTAServices;
ActionServices : IOTAActionServices;
CodeInsideServices : IOTACodeInsightServices;
DebuggerServices : IOTADebuggerServices;
EditorServices : IOTAEditorServices;
KeyBindingServices : IOTAKeyBindingServices;
KeyboardDiagnostics : IOTAKeyboardDiagnostics;
KeyboardServices : IOTAKeyboardServices;
MessageServices : IOTAMessageServices;
ModuleServices : IOTAModuleServices;
PackageServices : IOTAPackageServices;
Services : IOTAServices;
WizardServices : IOTAWizardServices;
Index : Integer;
procedure Register;
begin
RegisterPackageWizard(TBeforeCompile.create
as IOTAWizard);
end;
procedure InitExpert;
begin
MainServices := (BorlandIDEServices
as INTAServices);
ActionServices := (BorlandIDEServices
as IOTAActionServices);
CodeInsideServices := (BorlandIDEServices
as IOTACodeInsightServices);
DebuggerServices := (BorlandIDEServices
as IOTADebuggerServices);
EditorServices := (BorlandIDEServices
as IOTAEditorServices);
KeyBindingServices := (BorlandIDEServices
as IOTAKeyBindingServices);
KeyboardDiagnostics := (BorlandIDEServices
as IOTAKeyboardDiagnostics);
KeyboardServices := (BorlandIDEServices
as IOTAKeyboardServices);
MessageServices := (BorlandIDEServices
as IOTAMessageServices);
ModuleServices := (BorlandIDEServices
as IOTAModuleServices);
PackageServices := (BorlandIDEServices
as IOTAPackageServices);
Services := (BorlandIDEServices
as IOTAServices);
WizardServices := (BorlandIDEServices
as IOTAWizardServices);
Index := (BorlandIDEServices
as IOTAServices).AddNotifier(TBeforeCompile.create);
end;
procedure DoneExpert;
begin
(BorlandIDEServices
as IOTAServices).RemoveNotifier(
Index);
end;
procedure TBeforeCompile.AfterCompile(Succeeded: Boolean);
begin
{$IFDEF Meckermodus}
ShowMessage('
AfterCompile(Succeeded: Boolean) - AfterCompile(' + BoolToStr(Succeeded) + '
)');
{$ENDIF}
end;
procedure TBeforeCompile.AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean);
var
path :
string;
params :
string;
begin
{$IFDEF Meckermodus}
ShowMessage('
AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean) - AfterCompile('
+ BoolToStr(Succeeded) + '
;(' + BoolToStr(IsCodeInsight) + '
)');
{$ENDIF}
if not IsCodeInsight
then begin
// Hier kann man beliebige Aufgaben nach dem Kompilieren ausführen.
path := '
cmd.exe';
// Die Konsole oder irgendein Programm aufrufen.
params := '
/C %temp%\AfterCompile.Bat';
// Die für das Programm erforderlichen Parameter.
ShellAPI.ShellExecute(0,'
open',PChar(path),PChar(params),
nil,0);
end;
end;
procedure TBeforeCompile.BeforeCompile(
const Project: IOTAProject;
var Cancel: Boolean);
begin
{$IFDEF Meckermodus}
ShowMessage('
BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);'
+ #13 + '
BeforeCompile(' + Project.FileName + '
; ' + BoolToStr(Cancel) + '
);');
{$ENDIF}
end;
procedure TBeforeCompile.BeforeCompile(
const Project: IOTAProject; IsCodeInsight: Boolean;
var Cancel: Boolean);
Var
sl : TStringList;
begin
{$IFDEF Meckermodus}
ShowMessage('
BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean);'
+ #13 + '
BeforeCompile(' + Project.FileName + '
; ' + BoolToStr(IsCodeInsight) + '
; ' + BoolToStr(Cancel) + '
);');
{$ENDIF}
if not IsCodeInsight
then begin
// Hier kann man beliebige Aufgaben vor dem Kompilieren ausführen.
// Zum Beispiel eine Batchdatei erstellen, die von AfterCompile dann ausgeführt wird.
sl := TStringList.Create;
sl.Add('
ECHO OFF');
sl.Add('
type ' + Project.FileName + '
> %temp%\type.txt');
sl.SaveToFile(GetEnvironmentVariable('
TEMP') + '
\AfterCompile.Bat');
sl.Free;
End;
end;
procedure TBeforeCompile.FileNotification(NotifyCode: TOTAFileNotification;
const FileName:
string;
var Cancel: Boolean);
begin
//
end;
function TBeforeCompile.GetMenuText;
begin
// Caption des Menüeintrages im Hilfemenü der IDE.
result := '
TBeforeCompile';
end;
function TBeforeCompile.GetName;
begin
result := '
TBeforeCompile';
end;
function TBeforeCompile.GetState;
begin
result := [wsEnabled];
end;
function TBeforeCompile.GetIDString;
begin
result := '
TBeforeCompile';
end;
Constructor TBeforeCompile.Create;
begin
inherited;
end;
procedure TBeforeCompile.Execute;
begin
ShowMessage('
Das bekommen wir zu sehen, wenn wir im Hilfemenü auf TBefoeCompile klicken.');
end;
function TBeforeCompile.AddNotifier(
const Notifier: IOTAIDENotifier50) : Integer;
begin
Result := 0;
end;
procedure TBeforeCompile.RemoveNotifier(
Index: Integer);
begin
//
end;
initialization
InitExpert;
finalization
DoneExpert;
end.