在Delphi XE中编写事件宏

12

根据 Delphi 的帮助文件, 当我打开对话框以添加构建事件到我的项目选项时,对话框应该显示一个可用于构建事件命令行的宏(占位符)列表。然而,在 Delphi XE 中尝试此操作时,宏列表为空。帮助文件中也没有列出可用的宏(至少我没找到)。

那么,有哪些宏是可用的呢?目前我需要一个用于编译后的完整 .exe 文件路径的宏(后置构建),以及 .dproj 文件的完整路径。但我希望能获得未来参考的完整可用宏列表。

3个回答

12

我不得不回到D2010才能列出这张清单:

BDS                 The environment variable $(BDS)
DEFINES             The project's conditional defines
DIR                 The environment variable $(DIR)
INCLUDEPATH         The project's include path
INPUTDIR            The input file's directory
INPUTEXT            The input file's extension
INPUTFILENAME       The input file's name, with extension
INPUTPATH           The input file's full path
LOCALCOMMAND        Local command entered by user in project manager
OUTPUTDIR           The output file's directory
OUTPUTEXT           The output file's extension
OUTPUTFILENAME      The output file's name, with extension
OUTPUTNAME          The output file's name, without extension
OUTPUTPATH          The output file's full path
Path                The environment variable $(PATH)
PROJECTDIR          The project's directory
PROJECTEXT          The project's extension
PROJECTFILENAME     The project file's name, with extension
PROJECTNAME         The project's name
PROJECTPATH         The project file's full path
SAVE                Save the input file to disk before it's compiled
SystemRoot          The environment variable $(SYSTEMROOT)
WINDIR              The environment variable $(WINDIR)

谢谢。像这样的东西应该在文档中,即使应用程序本身应该显示列表。 - Jan Goyvaerts
@Jan:感谢您修复格式。我似乎无法做到完全正确。 :) - Ken White
@Ken:诀窍是使用空格而不是制表符来对齐第二列。 - Jan Goyvaerts
1
@Jan:谢谢。我将来得记住这个方法。(无法从IDE的对话框中复制和粘贴,所以我不得不在记事本中输入所有内容,然后复制到剪贴板,切换回FireFox,并将其粘贴到答案中。我想过截取对话框的屏幕截图,但是你无法调整宏列表的底部大小,因此需要多张图片。) - Ken White
@Ken:不要轻易放弃。打开构建事件对话框并使其更高。启动EDA,切换到“修改窗口”选项卡,将窗口选择器拖到“宏”组框中,并增加DY。 - Uli Gerhardt
@Ulrich: :) 很好的建议。我得看看 - 我以前用过类似的东西,但昨晚没想那么快。 - Ken White

2
首先,我认为您想要的是 $(PROJECTPATH),它将是包括路径在内的 DPROJ 文件的完整名称。
这是 RAD XE 中的一个错误。我也见过这种情况。对我来说,在 Update 1 上解决了这个问题。等等。我的意思是,这是 Update 1 中的回归,而 RTM 中没有出现这种情况。
这是 Delphi 2009 的屏幕截图: enter image description here

1

我已经安装了Update 1,但仍然看不到它们,不过...

对于输出文件,请使用"$(OUTPUTDIR)$(OUTPUTFILENAME)",对于项目文件,请使用"$(ProjectDir)$(ProjectFileName)"

如果这些宏在IDE中没有显示出来,您可以在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Borland.Delphi.Targets中找到可用的宏列表(来源于Delphi的MSBuild项目级属性是什么?

在该文件中,我的计算机上有以下区域...

<!-- Build event properties settable in the IDE -->
    <ProjectName>$(MSBuildProjectName)</ProjectName>
    <ProjectFilename>$(MSBuildProjectFile)</ProjectFilename>
    <ProjectExt>$(MSBuildProjectExtension)</ProjectExt>
    <ProjectDir>$(MSBuildProjectDirectory)</ProjectDir>
    <ProjectPath>$(MSBuildProjectFullPath)</ProjectPath>

    <InputPath>@(DelphiCompile->'%(FullPath)')</InputPath>
    <InputDir>@(DelphiCompile->'%(RootDir)%(Directory)')</InputDir>
    <InputName>@(DelphiCompile->'%(Filename)')</InputName>
    <InputExt>@(DelphiCompile->'%(Extension)')</InputExt>
    <InputFilename>@(DelphiCompile->'%(Filename)%(Extension)')</InputFilename>

    <OutputPath>@(_DependencyCheckOutputName->'%(FullPath)')</OutputPath>
    <OutputDir>@(_DependencyCheckOutputName->'%(RootDir)%(Directory)')</OutputDir>
    <OutputName>@(_DependencyCheckOutputName->'%(Filename)')</OutputName>
    <OutputExt>@(_DependencyCheckOutputName->'%(Extension)')</OutputExt>
    <OutputFilename>@(_DependencyCheckOutputName->'%(Filename)%(Extension)')</OutputFilename>

HTH


我认为你不需要同时使用ProjectDir和ProjectFilename,只需使用更简单的PROJECTPATH即可。它会为您结合这两者。 - Warren P

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接