The fwCursor class can be used as a base class for objects that are to be serialized to JSON format with the fwJSON.Write method for downloading to an Ajax client-side script. The output produced, when an object based on this class is serialized, is identical to the output that the fwJSON.WriteCursor method would produce for the same cursor, or table. Scripts would utilize this class in instances, where the JSON response needs to include data from multiple cursors, or additional data values. In such cases, the value passed to the fwJSON.Write method would be an object, or array, containing one, or more objects based on the fwCursor class.
MyObject = CREATEOBJECT("fwCursor", [TableAlias], [NumberOfRecords])
Optional string value, used to populate the TableAlias property.
Optional numeric value, used to populate the NumberOfRecords property.
The following script reads a search term from the query string, searches two tables and then sends the results in JSON format to the browser.
|
TableAlias | The work area, or alias of the table/cursor to be serialized. |
NumberOfRecords | The number of records to output. |
ToJSONString | Serializes the contents of cursor/table into a JSON string. |
The TableAlias property sets/gets the work area, or alias of the table/cursor to be serialized. The table/cursor must be open at the time when objects, based on the fwCursor class are to be serialized. If this property is not set, then the serialization code uses the table/cursor in the currently selected work area. Typically this property gets populated via a parameter passed to the constructor, when the object is created with the CREATEOBJECT command. This property can be set to either a string value (alias), or a numeric value (work area).
The NumberOfRecords property sets/gets the number of records to output and has a default value is 0. If NumberOfRecords is 0, all records are output. If NumberOfRecords is greater than the number of records remaining in the table, all remaining records are output. Typically this property gets populated via a parameter passed to the constructor, when the object is created with the CREATEOBJECT command.
The ToJSONString method serializes a VFP data value into a JSON string. It is typically used in Ajax applications to return data to browser-side JavaScript programs. Typically scripts don't call this method, but rather use the fwJSON.Write method to serialize a container array, or object.
MyObject.ToJSONString()