Example 1: URL-based web component using Google maps

This example shows how to implement a simple mobile application using a WEBCOMPONENT field interacting with Google maps

The form file: webcomp.per

LAYOUT
GRID
{
[f1                     ]
[                       ]
[                       ]
[                       ]
[                       ]
[                       ]
[                       ]
[                       ]
[f2                     ]
[f3                     ]
[                       ]
}
END
END
ATTRIBUTES
WEBCOMPONENT f1 = FORMONLY.mymap, STRETCH=BOTH;
BUTTONEDIT f2 = FORMONLY.location, ACTION=set_loc;
TEXTEDIT f3 = FORMONLY.value, STRETCH=X;
END

The program file: webcomp.4gl

MAIN
    CONSTANT c_gmaps = "http://maps.google.com/"
    DEFINE rec RECORD
               mymap STRING,
               location STRING,
               value STRING
           END RECORD
    OPEN FORM f1 FROM "webcomp"
    DISPLAY FORM f1
    LET rec.location = "Paris"
    LET rec.mymap = c_gmaps||"?q="||rec.location
    INPUT BY NAME rec.* WITHOUT DEFAULTS
          ATTRIBUTES(UNBUFFERED)
        ON ACTION set_loc
           LET rec.mymap = c_gmaps||"?q="||rec.location
           LET rec.value = rec.mymap
        ON CHANGE mymap
           LET rec.value = rec.mymap
           MESSAGE "URL has changed! "||CURRENT HOUR TO FRACTION(3)
    END INPUT
END MAIN