2014-02-21 179 views
1

我有一個名爲ErrorItem的類,它有多個構造函數。是否有可能在構造函數中調用另一個構造函數來管理默認值?多構造函數

例子:

CONSTRUCTOR PUBLIC ErrorItem(): 
     ErrorItem("", "", "", -1, "", ""). 
    END CONSTRUCTOR. 

    CONSTRUCTOR PUBLIC ErrorItem(
     ItemNo AS CHARACTER 
     ,UpcCode AS CHARACTER 
     ,CustomerPo AS CHARACTER 
     ,ColumnId AS INTEGER 
     ,Description AS CHARACTER): 
     ErrorItem(ItemNo, UpcCode, CustomerPo, ColumnId, Description, ""). 
    END CONSTRUCTOR. 

    CONSTRUCTOR PUBLIC ErrorItem(
     ItemNo AS CHARACTER 
     ,UpcCode AS CHARACTER 
     ,CustomerPo AS CHARACTER 
     ,ColumnId AS INTEGER 
     ,Description AS CHARACTER 
     ,Detail AS CHARACTER 
    ):   
     ASSIGN 
      THIS-OBJECT:ItemNo = ItemNo 
      THIS-OBJECT:UpcCode = UpcCode 
      THIS-OBJECT:CustomerPo = CustomerPo 
      THIS-OBJECT:ColumnId = ColumnId 
      THIS-OBJECT:Description = Description 
      THIS-OBJECT:Detail = Detail 
     . 
    END CONSTRUCTOR. 

謝謝! 塞巴斯蒂安

+0

使用此代碼,我得到編譯器錯誤:構造函數不能直接調用 –

回答

4

是 - 格式爲:

CONSTRUCTOR PUBLIC ErrorItem(variable list): 
THIS-OBJECT(local variable list). 

/* Stuff */ 
END CONSTRUCTOR. 

而且「此對象」電話必須是在構造函數中的第一條語句。

+1

完美!謝謝! –