编译器为设计时包或代码定义以检查 IDE 中的执行情况

Compiler define for Design Time package or code to check for execution in IDE

是否有任何编译器定义或 functions/constants/variables 可用于判断某些代码是为设计时包构建还是从 IDE 内部执行?

我们有一些代码挂钩,我们在初始化作为包一部分的单元时设置它们。我们不希望在 IDE 中安装包时执行此代码,仅当它是 运行 作为我们应用程序的一部分时才执行。

现在我已经在设计时包中添加了一个编译器定义,它去掉了代码,但我想知道是否有一个内置的编译器定义表明这是设计时包的一部分,或者是否有一些 function/constant 可以检查代码是否是 运行 里面的 IDE。类似于人们从内部组件使用的旧 if csDesigning in ComponentState then

Are there any compiler defines or functions/constants/variables that can be used to tell whether some code is being built for a design time package or is being executed from inside the IDE?

没有

We have some code hooks that we setup in the initialization of a unit which is part of a package. We don't want this code to be executed when installing the package in the IDE, only when it's running as part of our application.

那么该代码根本不属于该单元的 initialization 部分。将其移动到您的应用程序代码可以在其启动期间调用的单独函数。

For now I have added a compiler define to the design time package which strips out the code

这意味着您的设计时包正在直接编译您的 运行 时代码,它根本不应该这样做。 运行-时间代码和设计时间代码需要在不同的包中。 运行-time 代码不属于设计时包,设计时代码不属于 运行-time 包。

I was wondering if there was a built in compiler define that indicates that this is part of a design time package

没有。但是,如果您创建单独的 运行-time 和设计时包(您应该这样做),那么您的钩子代码仅属于 运行-time 包。设计时包可以 require 运行-time 包(因此它可以访问您的 运行-time 组件),并且 运行-time 包可以公开一个设计时包可以设置的全局变量。如果设置了该变量,运行-time 代码可以忽略它需要忽略的任何内容。