The example described in this section has a client user interface for
displaying data in the database. You use VisualAge visual parts to
define the client UI. When you finish this section, the client UI
resembles:
To define the client UI, add a visual part to MyDatabaseTCPIPApp and name it, for example, MyClientView.
In a Composition Editor open on MyClientView, do the following:
Situate a Text part beside each label. Open the settings for the Staff ID# Text part and set notifyChangeOnEachKeystroke to false, and set partName to id. For the Logon ID Text part, set partName to logonId. For the Host ID Text part, set converter to String and partName to hostIdField. For the Port Text part, set converter to Integer, notifyChangeOnEachKeystroke to false, and partName to portField. For the Password Text part, set partName to password.
For the object properties of the Text parts, you might specify default values so users do not need to type them in later.
Go to the Script Editor for MyClientView and add two instance methods:
data ^((self subpartNamed: 'logonId') object abrPadWithBlanks: 8), ((self subpartNamed: 'password') object abrPadWithBlanks: 8), ((ByteArray new: 2) uint16At: 0 put: (self subpartNamed: 'id') object; yourself), (String new: 2000)
formatData: aString | newString id name dept job years salary rec col | ( aString includes: $[ ) ifFalse: [ ^CwMessagePrompter warn: 'No data was returned by server program' ]. newString := aString subStrings: $[. id := (newString at: 2) abtWithoutOccurencesOf: $]. id := id abtWithoutOccurencesOf: $'. name := (newString at: 3) abtWithoutOccurencesOf: $]. name := name abtWithoutOccurencesOf: $'.
dept := (newString at:4) abtWithoutOccurencesOf: $]. dept := dept abtWithoutOccurencesOf: $'. job := (newString at: 5) abtWithoutOccurencesOf: $]. job := job abtWithoutOccurencesOf: $'. years := (newString at: 6) abtWithoutOccurencesOf: $]. years := years abtWithoutOccurencesOf: $'. salary := (newString at: 7) abtWithoutOccurencesOf: $]. salary := salary abtWithoutOccurencesOf: $'.
rec := (AbtCompoundType new name: '' ; addField: (( AbtCCharArrayField new name: 'ID'; length: ( id size ) )); addField: (( AbtCCharArrayField new name: 'NAME'; length: ( name size ) )); addField: (( AbtCCharArrayField new name: 'DEPT'; length: ( dept size ) )); addField: (( AbtCCharArrayField new name: 'JOB'; length: ( job size ) )); addField: (( AbtCCharArrayField new name: 'YEARS'; length: (years size) )); addField: (( AbtCOBOLPackedDecimalField new name: 'SALARY'; length: 10 )); yourself ) newRecord. rec at: 'ID' put: id; at: 'NAME' put: name; at: 'DEPT' put: dept; at: 'JOB' put: job; at: 'YEARS' put: years; at: 'SALARY' put: salary asDecimal. col := OrderedCollection new. col add: rec. (self subpartNamed: 'Container Details1') items: col.
Next, return to the Composition Editor and add TCP/IP parts that enable you to connect to the host machine at a designated port:
To enable connections to the server machine, make the following connections:
After you complete the connections, your work resembles:
When you test MyClientView, you now see values specified for hostIdField and portField.