Programming Guide : Working with Images and Text Strings : How You Can Work with Text Strings
 
Share this page          
How You Can Work with Text Strings
The StringObject class is an in-memory text string of any length. It provides methods that enable you to manipulate a text by extracting, truncating, and concatenating strings. It also provides the attributes and methods you use for storing and updating the strings, either in standard text files or in the database. The StringObject class makes it easy to build applications that let users create, modify, and store textual data of indeterminate size.
When you create a multiline entry field in OpenROAD Workbench, you can choose between two types of variables, a varchar data type and a StringObject data type. When you select the StringObject data type, the variable associated with the entry field is a reference variable that points to an object of the class StringObject. The StringObject class is also useful for local and global variables, which you can use to store text or pass as parameters between frames or 4GL procedures.
StringObject objects are very effective for storing moderately sized text. However, because all manipulation is done in dynamically allocated memory, using StringObject objects to store large text strings is not very efficient. For text that is always less than 2000 bytes, the varchar data type is the most efficient format.
Setting a StringObject attribute does more than change the attribute's value. Each time you change the value, OpenROAD executes implied procedures. For example, when you set the FileHandle attribute to a new value and the StringObject is associated with an entry field, OpenROAD displays the new string in the field. This process simplifies your coding because all you need to do is set the attribute.
The StringObject class lets you store strings either in standard text files or in a database. Using your native file system to store strings in standard files provides performance advantages. You can use SQL to store and retrieve the file names in a database table.
For example, assume your application uses standard text files to store sections of a document and stores the names of the files in a database table. You can use the StringObject attributes and methods that deal with files to manipulate the strings from your application.
The disadvantage of storing strings outside of the database is that you are responsible for maintaining the string files. You must ensure that any files you reference from the application actually exist, and you must back up and update the files appropriately. In addition, if you create a portable application or use a network, your application must take into account the different conventions for file specifications.
Storing strings in the database offers the following advantages:
You can take advantage of the DBMS recovery and transaction facilities.
If you use networks, there are no problems with file name transparency.
Storing strings in the database, however, has the following disadvantages:
It is difficult for other programs to access the data.
To alleviate this problem, after loading the text into the database, use the WriteToFile method to transfer the text back out to a system file for manipulation outside of the database.
There is extra overhead in using the database instead of the native file system.
The following sections describe how to work with strings stored in files and in the database.