正在处理未命名的可选包含文件参数

问题描述 投票:0回答:1

我正在尝试向我的

IF
文件添加一个简单的
include .i
语句来处理可选的
unnamed parameters
:

消息.i:

/*
    - {1}: Message.
    - {2}: OPTIONAL Sender name
*/
&IF DEFINED({2}) <> 0 &THEN
    {2} = "Unknown sender".
&ENDIF.
MESSAGE "{2}" + ": " + "{1}" VIEW-AS ALERT-BOX.

测试.p:

{message.i "hello world" }
// Should output "Unknown sender: hello world".
// Does not compile.

{message.i "hello world" "Michael" }
// Should output "Michael: hello world".

在此版本中,如果缺少第二个参数,

message.i
将抛出错误。

我想使用

unnamed parameters
并避免参数命名。

如何修复代码以使其正常工作?

parameters progress progress-4gl
1个回答
0
投票

您可以检查第二个参数是否为空:

消息.i

&IF "{2}" <> "" &THEN
    MESSAGE "{2}" + ": " + "{1}" VIEW-AS ALERT-BOX.
&ELSE
    MESSAGE "Unknown sender" + ": " + "{1}" VIEW-AS ALERT-BOX.
&ENDIF.

AblDojo 示例

© www.soinside.com 2019 - 2024. All rights reserved.