Johan Vergeer
Johan Vergeer

Reputation: 5578

OpenEdge get data-type of property value that is retrieved using DYNAMIC-PROPERTY

I have to use the DYNAMIC-PROPERTY function in OpenEdge to get data out of a class.

So far this works just fine, but now I would like to know the data type of the values that was retrieved. This is required because the values are formatted based on the data type.

So for example:

CLASS Customer:
    DEF PUBLIC PROPERTY Name AS CHAR NO-UNDO
        GET.
        SET.

    DEF PUBLIC PROPERTY Email AS CHAR NO-UNDO
        GET.
        SET.

CLASS Invoice:
    DEF PUBLIC PROPERTY Amount AS DECIMAL NO-UNDO
        GET.
        SET.

    DEF PUBLIC PROPERTY Customer AS Customer NO-UNDO
        SET.
        GET.

In another procedure I would like to do something like this:

DEF INPUT PARAM oInvoice AS Invoice NO-UNDO.

DEF VAR theValue AS Progress.Lang.Object NO-UNDO.

theValue = DYNAMIC-PROPERTY(oInvoice, "Amount").

IF theValue:WHATS-THE-TYPE = "decimal" THEN 
    RETURN STRING(theValue, ">>>>>9.99").
ELSE
    RETURN TRIM(theValue). // It is a character field

Since I don't know the type at runtime, I can't format the value.

In a later stage I would even want to get the property values of the customer.

IF theValue:WHATS-THE-TYPE = "Customer" THEN
   RETURN DYNAMIC-PROPERTY(theValue, "Name").

Upvotes: 2

Views: 2160

Answers (1)

Mike Fechner
Mike Fechner

Reputation: 7192

OpenEdge 11.6 has introduced a reflection API which allows to query that.

DEFINE VARIABLE oProperties AS Progress.Reflect.Property NO-UNDO EXTENT .

oProperties = oObject:GetClass():GetProperties() . 

DO i = 1 TO EXTENT (oProperties):
    MESSAGE oProperties[i]:Name oProperties[i]:DataTypeName .
END.

Upvotes: 4

Related Questions