1

使用openge 10.2.b ItemObj.cls

CLASS mystuff.ItemObj :
  METHOD PUBLIC CHARACTER GetItemDesc
  ( INPUT pcOne AS CHARACTER,
  INPUT pcTwo AS CHARACTER,
  INPUT piThree   AS INTEGER ) :

    RETURN pcOne pcTwo pcThree.

END METHOD.

项目对象.p

USING mystuff.*.
DEFINE VARIABLE rItemObj AS CLASS mystuff.ItemObj NO-UNDO.
rItemObj = NEW mystuff.ItemObj( ).
MESSAGE "One : " rItemObj:GetItemDesc (1)       SKIP(1)
        "Two : " rItemObj:GetItemDesc (1, 2)    SKIP(1)
        "Three : " rItemObj:GetItemDesc (1, 2, 3) VIEW-AS ALERT-BOX INFO.
DELETE OBJECT rItemObj.

我希望所有这些语句的输出都相同,这样如果用户只输入 1 输入,其他两个默认为 2 和 3,如果用户输入 1 和 2,则三个默认为 3。

如何在不出现参数不匹配错误的情况下执行此操作?

4

1 回答 1

3

IIRC Progress 不允许在方法定义中使用可选参数,因此您必须为每个参数排列创建方法定义或接受将多个值作为参数处理的数据结构,如动态数组、临时表或自定义对象和解压它(但随后你将逻辑推给你的调用者)。

CLASS mystuff.ItemObj:
  METHOD PUBLIC CHARACTER GetItemDesc (INPUT pcOne   AS CHARACTER,
                                       INPUT pcTwo   AS CHARACTER,
                                       INPUT piThree AS INTEGER):
    RETURN pcOne pcTwo pcThree.
  END METHOD.

  METHOD PUBLIC CHARACTER GetItemDesc (INPUT pcOne   AS CHARACTER,
                                       INPUT pcTwo   AS CHARACTER):
    RETURN GetItemDesc(pcOne, pcTwo, 3).
  END METHOD.

  METHOD PUBLIC CHARACTER GetItemDesc (INPUT pcOne   AS CHARACTER):
    RETURN GetItemDesc(pcOne, "2").
  END METHOD.
END CLASS.
于 2012-04-20T15:13:05.530 回答