Heiko Rompel wrote:
> Hallo Arno,
>
>> Der IDE-Standard-Name des Projekts steht in $(MSBuildProjectName).
>>
>
> Schade, damit funktioniertes doch nicht richtig.
> Es ist alles super wenn ich das Projekt mittels
> [Umschalt][F9] Erzeuge oder mittels [STRG][F9] Compiliere,
> aber ein Start mittels [F9] ausführe erhalte ich die Meldung:
>
> Programm 'D:\projekte\delphi\Delphi
> XE5\%MSBuildProjectName%\Win32_Debug\Mathetrainer.exe' kann nicht
> gefunden werden.
>
> Starte ich das Programm mittels [Umschalt][STRG][F9], erhalte ich die
> Meldung:
>
> Prozess kann nicht erzeugt werden: Der Verzeichnisname ist ungültig.
>
> Also, scheint %MSBuildProjectName% nicht durchgängig "aufgelöst zu
> werden".
Yup, teste mal Folgendes:
{code}
{*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Description: Adds/writes an environment variable "ProjectName" before each compile.
Usage: 1.) Add this unit to a new design-time package.
2.) Make sure "designide.dcp" is in package's Requires node, if not add a reference.
3.) Build and install the package.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit uProjectNameVar;
{.$DEFINE DEBUGLOG}
interface
uses
Windows, SysUtils, Classes, Forms, TypInfo,
ToolsApi;
type
TIdeNotifier = class(TNotifierObject, IOTAIDENotifier)
private
FLastDpr : string;
protected
procedure AfterCompile(Succeeded: Boolean);
procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
procedure FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
end;
procedure Register;
implementation
var
IDENotifierIndex : Integer = -1;
{$IFDEF DEBUGLOG}
GMessageService: IOTAMessageServices = nil;
{$ENDIF}
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{$IFDEF DEBUGLOG}
procedure DebugLog(const Msg: string);
begin
GMessageService.AddTitleMessage(Msg);
end;
{$ENDIF}
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure Register;
var
Services : IOTAServices;
begin
Services := BorlandIDEServices as IOTAServices;
{$IFDEF DEBUGLOG}
GMessageService := BorlandIDEServices as IOTAMessageServices;
{$ENDIF}
if IDENotifierIndex = -1 then
begin
IDENotifierIndex := Services.AddNotifier(TIdeNotifier.Create);
{$IFDEF DEBUGLOG}
DebugLog('Installed NotifierIndex: #' + IntToStr(IDENotifierIndex));
{$ENDIF}
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TIdeNotifier.AfterCompile(Succeeded: Boolean);
begin
{$IFDEF DEBUGLOG}
DebugLog('After Compile');
{$ENDIF}
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function SetEnvVar(const VarName, VarValue: string): Integer;
begin
if SetEnvironmentVariable(PChar(VarName),
PChar(VarValue)) then
Result := 0
else
Result := GetLastError;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TIdeNotifier.BeforeCompile(const Project: IOTAProject;
var Cancel: Boolean);
var
ProjName: string;
LastErr: Integer;
begin
{$IFDEF DEBUGLOG}
DebugLog('Before Compile');
{$ENDIF}
ProjName := ChangeFileExt(ExtractFileName(Project.GetFileName), '');
{$IFDEF DEBUGLOG}
DebugLog('ProjectName=' + ProjName);
{$ENDIF}
LastErr := SetEnvVar('ProjectName', ProjName);
{$IFDEF DEBUGLOG}
if LastErr <> 0 then
DebugLog('Error=' + SysErrorMessage(LastErr));
{$ENDIF}
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TIdeNotifier.FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
begin
{$IFDEF DEBUGLOG}
DebugLog('FileNotification');
{$ENDIF}
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure RemoveIDENotifier;
var
Services : IOTAServices;
begin
if IDENotifierIndex > -1 then
begin
Services := BorlandIDEServices as IOTAServices;
if Services <> nil then
Services.RemoveNotifier(IDENotifierIndex);
IDENotifierIndex := -1;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
initialization
finalization
RemoveIDENotifier;
end.
{code}