Search Temp-Table by Class Instance Property

KMoody

Member
I have two classes: maze_util and point_util (see below).

A maze_util contains a temp table (tt) of point_util instances stored as Progress.Lang.Object.

In maze_util:getTestValue, I want to find a tt record by looking up the x and y values of the tt's point. I tried to do this by CASTing tt.point as a point_util. However, this doesn't seem to work since you can't call functions (such as CAST) in a WHERE statement.

Is there some other way to search a temp-table by looking up a Progress.Lang.Object's original class instance property?

maze_util.cls
Code:
USING Progress.Lang.*.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS maze_util:

    DEFINE PUBLIC PROPERTY height AS INTEGER NO-UNDO 
        GET.
        PRIVATE SET.   
    
    DEFINE PUBLIC PROPERTY width AS INTEGER NO-UNDO 
        GET.
        PRIVATE SET.   

    DEF TEMP-TABLE tt
        FIELD test       AS CHAR
        FIELD point      AS Progress.Lang.Object
        FIELD pointValue AS CHAR
        .
 
      METHOD PUBLIC CHARACTER generateMap(in_width AS integer, in_height AS INTEGER):
       
        def var i          AS INTEGER.
        def var j          AS INTEGER.
        def var tempCourse AS CHAR.
        DEF VAR tempPoint  AS point_util.
       
        width = in_width.
        height = in_height.
       
        DO j = 1 TO height:
            DO i = 1 TO width:
               
                tempPoint = new point_util(i,j).
                CREATE tt.
                tt.point = tempPoint.
                tt.pointValue = "0".
                tt.test = "testingvalue".
               
            END.
        END.

    END METHOD.      

 
      METHOD PUBLIC CHARACTER getTestValue(in_x as integer, in_y as integer):
     
        def var i    AS INTEGER.
        def var j    AS INTEGER.

        FIND TT WHERE cast(tt.point,point_util):x = in_x and cast(tt.point,point_util):y = in_y no-lock no-error.
        if available tt then
        return tt.test.
       
    END METHOD.
   
END CLASS.

point_util.cls
Code:
USING Progress.Lang.*.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS point_util:

    DEFINE PUBLIC PROPERTY x AS INTEGER NO-UNDO
    GET.
    PRIVATE SET.
   
    DEFINE PUBLIC PROPERTY y AS INTEGER NO-UNDO
    GET.
    PRIVATE SET.
 
    CONSTRUCTOR PUBLIC point_util (in_x as INTEGER, in_y AS INTEGER):
       
        x = in_x.
        y = in_y.
       
    END CONSTRUCTOR.
   
END CLASS.
 

SimonB

New Member
You can iterate temp-tables and leave when something matches like this:


Code:
DEFINE TEMP-TABLE tt NO-UNDO
    FIELD Id        AS INTEGER 
    FIELD Obj       AS Progress.Lang.Object 
    FIELD TestValue AS CHARACTER
    INDEX idx1 IS PRIMARY UNIQUE Id.

DEFINE VARIABLE xToFind     AS INTEGER    NO-UNDO.   
DEFINE VARIABLE yToFind     AS INTEGER    NO-UNDO.
DEFINE VARIABLE myPoint     AS point_util NO-UNDO.
DEFINE VARIABLE ReturnValue AS CHARACTER  NO-UNDO.

loopFind:
FOR EACH tt NO-LOCK:
    IF TYPE-OF(tt.Obj, point_util) THEN
    DO:
        myPoint = CAST(tt.Obj, point_util).
        IF (myPoint:x = xToFind AND myPoint:y = yToFind) THEN
        DO:
            ReturnValue = TestValue.
            LEAVE loopFind.
        END.
    END.
END.

You can also wrap your temp-table in an object point_util_Collection that implement this kind of search and Add/Remove methods.
 
Top