Rational DOORS DXL:我可以检查是否存在局部字符串变量吗?

Rational DOORS DXL: can I check for existence of a local string variable?

假设我有一个包含各种 if/else 部分的 DXL 宏,这样一个特定的字符串只在特定条件下创建,而不是在其他时间创建。在尝试使用所述字符串之前如何测试是否存在?我正在寻找

的等价物
if (exist string foo) {
     do_something
    } else {
     do_some_other_thing
}

我可以通过初始化 string foo = "notset" 并测试值是否已更改来寻找解决方法,但如果不需要,我更喜欢不需要创建字符串变量的东西。

请注意,这是本地字符串,而不是在属性中找到(或未找到)的内容。

你试过if (null string_variable) {了吗?如果声明了字符串但没有给定值,这将计算为 true,因此它可能不是您想要的。如果尚未声明该字符串,它也可能会给您一个执行错误。

请注意,DXL 具有范围。这样的代码将不起作用:

if (cond) {
   string s = "Hello";
} else {
   // something different
}
if (s == ...) print "..." // parse time error, s not defined 

你需要使用这样的东西:

string s = null; 
if (cond1) {
    s = "Hallo"; 
} else {
    // something different
}
if (!null s) print "..."; 

我希望您不是在谈论检查 DXL 代码中是否声明了变量。这是不可能的,因为未声明的变量会在执行任何 DXL 之前产生解析时间错误(autodeclare 已关闭)。而且你永远不应该依赖自动声明。