Delphi 调试输出文件夹属性

Delphi debug output folder attributes

我想弄清楚如何在 delphi 构建项目时创建的文件夹上设置默认属性。我所有的谷歌搜索都没有提供答案。

例如:

假设我在 C:\MyProject\myProject.dpr 有一个 delphi 项目。当我构建这个项目时,Delphi 将创建 C:\MyProject\Win32\Debug\ 个文件夹。 Win32\Debug\ 个文件夹来自 Tools - Options - Environment Options - Delphi Options - Debug DCU Path

问题是创建的 Debug 文件夹 delphi 选中了只读属性。由于该文件夹是只读的,我经常遇到构建错误,例如:

[fatal error] could not create output file C:\MyProject\myProject.exe

如果我手动取消选中只读属性,我可以很好地构建我的项目。

那么 SO 上的任何人都知道如何告诉 Delphi 创建这个文件夹而不是只读的吗?

(我正在使用 Delphi XE8,但我相信这适用于所有版本和 Windows 7 Professional)

您无法控制文件夹的创建方式。没有指定所需属性的选项。但是,您可以尝试使用 Pre-Build event 执行命令行脚本,在编译开始前手动更改文件夹属性。

文件夹是通过调用 CreateDirectory 创建的,该调用将 NULL 作为 lpSecurityAttributes 参数传递。如文档所述,这意味着:

If lpSecurityAttributes is NULL, the directory gets a default security descriptor. The ACLs in the default security descriptor for a directory are inherited from its parent directory.

换句话说,安全设置是从父级继承的。您可以通过使其父目录可写来使该目录可写。