discovering_object_oriented_dataflex
discovering_object_oriented_dataflex
Object Oriented
D
Training Guide
PN: 917000
COPYRIGHT NOTICE
DISCLAIMER
Data Access Corporation makes no representation or warranties, expressed or implied, with respect to
the software or this publication, or any Data Access Corporation product, including but not limited to
warranties of merchantability or fitness for any particular purpose.
Data Access Corporation reserves to itself the right to make changes, enhancements, revisions and
alterations of any kind to this manual and / or its accompanying software without obligation to notify
any person, institution, or organization of such changes, enhancements, revisions, and alterations.
TRADEMARKS
Data Access Corporation has a forum on CompuServe devoted to the support of all of our products.
Additionally, it is a meeting place for the Data Access community. In our forum, users – ranging in
experience from first time computer users to experienced MIS professionals – share ideas and help
each other. Of course, the Data Access Corporation staff spends many hours each day on-line
answering questions and listening to user's requests. CompuServe is an invaluable aid during the
learning process and will serve as an excellent resource during projects.
Once connected to CompuServe, type GO DACCESS at any Compuserve ! prompt. Once in our
forum, you will see each product has its own message area and library area. The library area most
useful to DataFlex Object Oriented users is the "OOP Programming Section". If you need assistance
with particular aspects of the forum, leave a messaged to *SYSOP ( a private message to the forum
administrators). As soon as we receive that message, we will respond accordingly.
The 3.x support library contains code examples, questions and answer files, etc. From Data Access
Corporation and other users. By frequenting the Data Access Corporation forum on CompuServe and
contributing and retrieving files, you can learn the OOP language faster and more efficiently.
Additionally, once you're confident in your 3.X knowledge, you can assist other new users in learning
the product as well.
So, go on-line with CompuServe and GO DACCESS for instant access to hundreds of DataFlex users
who want to help YOU learn the DataFlex language!
Introduction.............................................................................................................................................. 9
How to use the Manual.................................................................................................................................................. 11
How Items will be Displayed ........................................................................................................................................ 12
DataFlex Manuals ......................................................................................................................................................... 14
Lesson 1 .................................................................................................................................................. 15
Class Setup....................................................................................................................................................... 15
Equipment Requirements .............................................................................................................................................. 16
Copying Class Files....................................................................................................................................................... 17
Lesson 2 .................................................................................................................................................. 19
The Basics ........................................................................................................................................................ 19
Our Project .................................................................................................................................................................... 20
File Relationships.......................................................................................................................................................... 24
Using DFFile ................................................................................................................................................................. 27
Creating a new file in DFFile ........................................................................................................................................ 31
Classes and Objects....................................................................................................................................................... 39
Using DFAuto ............................................................................................................................................................... 41
Moving & Resizing Objects .......................................................................................................................................... 45
Drawing Lines ............................................................................................................................................................... 47
Building Multiple Objects ............................................................................................................................................. 51
Switching between Objects ........................................................................................................................................... 55
Entry Options ................................................................................................................................................................ 56
Generating Code............................................................................................................................................................ 59
Running a New Program ............................................................................................................................................... 62
Object Toolbox (correcting navigation problems) ........................................................................................................ 66
Creating Selection Lists (Prompts)................................................................................................................................ 75
Connecting Prompts at Item level & Object level ......................................................................................................... 79
Lesson 2 Lab: ................................................................................................................................................................ 81
Did You Discover?:....................................................................................................................................................... 83
Lesson 3 ...................................................................................................... Error! Bookmark not defined.
Code Changes .................................................................................................................................................. 85
The Big Picture ............................................................................................................................................................. 86
Procedural Programming vs Object Oriented Programming ......................................................................................... 89
Connecting Views ......................................................................................................................................................... 90
Loading a file from a .DEF file ..................................................................................................................................... 93
Sibling Files in DFAuto................................................................................................................................................. 97
Loading Images with DFAuto ....................................................................................................................................... 98
Lesson 3 Lab: .............................................................................................................................................................. 109
Did You Discover?...................................................................................................................................................... 115
Lesson 4 ................................................................................................................................................ 117
DEOs And DSOs ........................................................................................................................................... 117
Differences between DEOs and DSOs ........................................................................................................................ 118
Object Nesting............................................................................................................................................................. 119
Constraint Blocks ........................................................................................................................................................ 120
Linking DEOs to DSOs ............................................................................................................................................... 124
Connecting DSOs to DSOs ......................................................................................................................................... 126
Lesson 4 Lab: .............................................................................................................................................................. 128
Did You Discover?:..................................................................................................................................................... 131
Lesson 5 ................................................................................................................................................ 133
Messages......................................................................................................................................................... 133
Procedures and Functions............................................................................................................................................ 134
Forwarding and Delegating ......................................................................................................................................... 136
Reading Online Documentation .................................................................................................................................. 138
Augmenting a Message ............................................................................................................................................... 143
Canceling a Message ................................................................................................................................................... 143
Overriding a Message.................................................................................................................................................. 144
Adding (creating) a Message....................................................................................................................................... 144
Accelerator Keys (On_Key command)........................................................................................................................ 145
Timers ......................................................................................................................................................................... 146
Access Methods........................................................................................................................................................... 147
Lesson 5 Lab: .............................................................................................................................................................. 151
Did You Discover?:..................................................................................................................................................... 154
Lesson 6 ................................................................................................................................................ 155
Procedures Functions and Properties ......................................................................................................... 155
Properties (Set & Get commands) ............................................................................................................................... 156
Entry Options (Ientry, Iexit & Ivalidate) ..................................................................................................................... 157
Procedures................................................................................................................................................................... 159
Functions ..................................................................................................................................................................... 160
Lesson 6 Lab: .............................................................................................................................................................. 161
Did You Discover?:..................................................................................................................................................... 166
Lesson 7 ................................................................................................................................................ 167
Image Manipulation...................................................................................................................................... 167
Images Zero-Based..................................................................................................................................................... 168
Hard Coded Item Number ........................................................................................................................................... 169
Item# Reference .......................................................................................................................................................... 170
Entry_Name_Item Reference ...................................................................................................................................... 171
Defaulting Current_Item ............................................................................................................................................. 172
Referencing Items outside the Current_Object............................................................................................................ 173
Table Item Reference - Base_Item .............................................................................................................................. 174
Entry_Defaults Procedure ........................................................................................................................................... 175
Sub_Page..................................................................................................................................................................... 177
Lesson 7 Lab: .............................................................................................................................................................. 180
Did You Discover?:..................................................................................................................................................... 184
Lesson 8 ................................................................................................................................................ 187
Using Predefined Classes.............................................................................................................................. 187
Entry Item & Standard Item Classes ........................................................................................................................... 188
Creating Buttons.......................................................................................................................................................... 189
Creating Checkboxes and Radios ................................................................................................................................ 190
Creating Messages and Forms..................................................................................................................................... 193
Creating Selection Lists and Pick Lists ....................................................................................................................... 194
Using DFAuto to its FULLEST! ................................................................................................................................. 195
Activate_View Command ........................................................................................................................................... 196
Lesson 8 Lab: .............................................................................................................................................................. 197
Did You Discover?:..................................................................................................................................................... 200
Lesson 9 ................................................................................................................................................ 201
Data Set Objects............................................................................................................................................ 201
Data_Set Objects......................................................................................................................................................... 202
Procedures Creating / Deleting/ Update / Backout..................................................................................................... 203
Functions Validate_Save & Validate_Delete .............................................................................................................. 206
Procedures Save_Main_File & Delete_Main_File...................................................................................................... 207
Lesson 9 Lab: .............................................................................................................................................................. 208
Did You Discover?:..................................................................................................................................................... 211
Lesson 10 .............................................................................................................................................. 213
Creating New Classes ................................................................................................................................... 213
Why create Sub-Classes .............................................................................................................................................. 214
Business Rules............................................................................................................................................................. 215
Class structure ............................................................................................................................................................. 216
Properties (creating) .................................................................................................................................................... 219
Lesson 10 Lab: ............................................................................................................................................................ 222
Did You Discover?:..................................................................................................................................................... 226
Lesson 11 .............................................................................................................................................. 227
Reporting ....................................................................................................................................................... 227
DFQuery & Reporting Classes .................................................................................................................................... 228
DFQuery Chart of Accounts........................................................................................................................................ 228
DFQuery Balance Sheet .............................................................................................................................................. 235
DFQuery Income Statement ........................................................................................................................................ 242
Chart of Accounts Modifications ................................................................................................................................ 250
Balance Sheet Modifications....................................................................................................................................... 252
Income Sheet Modifications........................................................................................................................................ 254
Lesson 11 Lab: ............................................................................................................................................................ 257
Did you Discover?:...................................................................................................................................................... 259
Workshop.............................................................................................................................................. 261
Appendix A ........................................................................................................................................... 263
“Did you Discover Answers”........................................................................................................................ 263
Lesson 2 - Fill-In Answers .......................................................................................................................................... 264
Lesson 2 - Discover Answers ...................................................................................................................................... 265
Lesson 3 - Fill-In Answers .......................................................................................................................................... 266
Lesson 3 - Discover Answers ...................................................................................................................................... 267
Lesson 4- Fill-In Answers ........................................................................................................................................... 268
Lesson 4 - Discover Answers ..................................................................................................................................... 270
Lesson 5 - Fill-In Answers .......................................................................................................................................... 272
Lesson 5 - Discover Answers ...................................................................................................................................... 273
Lesson 6 - Fill-In Answers .......................................................................................................................................... 274
Lesson 6 - Discover Answers ...................................................................................................................................... 275
Lesson 7 - Fill-In Answers .......................................................................................................................................... 276
Lesson 7 - Discover Answers ...................................................................................................................................... 277
Lesson 8 - Fill-In Answers .......................................................................................................................................... 278
Lesson 8 - Discover Answers ...................................................................................................................................... 280
Lesson 9 - Fill-In Answers .......................................................................................................................................... 281
Lesson 9 - Discover Answers ...................................................................................................................................... 282
Lesson 10 - Discover Answers .................................................................................................................................... 283
Lesson 11 - Discover Answers .................................................................................................................................... 284
Appendix B ........................................................................................................................................... 285
Problems & Solutions ................................................................................................................................... 285
Multiple Selection Processing: .................................................................................................................................... 286
Move_Value_Out Procedure & Display_Buffer_msg Property: ................................................................................. 287
AutoGen.INI................................................................................................................................................................ 288
Auto-Prompting........................................................................................................................................................... 289
Pre-compiling .............................................................................................................................................................. 290
Code_Selection_List, Code_Pick_List & Code_Radio_Entry_Form.......................................................................... 291
Table Optimizing: ....................................................................................................................................................... 292
Appendix C ........................................................................................................................................... 293
Extra Notes: ................................................................................................................................................... 293
Class Hierarchy Chart ................................................................................................................................................. 294
Accelerator Keys ......................................................................................................................................................... 295
New DataFlex Features ............................................................................................................................................... 296
AutoCreate Utility (DFAuto) & (AutoGen) .............................................................................................................. 297
Compiler (DFComp) ................................................................................................................................................... 297
File Definition Utility (DFFile) ................................................................................................................................... 297
File Administration Utility (DFRun DFAdmin) .......................................................................................................... 297
Query Utility (DFQUERY) ......................................................................................................................................... 297
DFRun DFBrowse....................................................................................................................................................... 297
Import/Export Utility (DFImport) ............................................................................................................................... 298
DFConfig & DFSetup ................................................................................................................................................. 298
Menu Utility (DFRun MenuDef)................................................................................................................................. 298
Help Utilities (DFRUN DFHelp) ............................................................................................................................... 298
Things to Standardize.................................................................................................................................................. 299
Events to trigger Messages.......................................................................................................................................... 300
Student Notes: ............................................................................................................................................................. 301
Glossary ................................................................................................................................................ 302
Additional Training ...................................................................................................................................... 305
Additional Related Products:....................................................................................................................... 305
Evaluation ............................................................................................................................................ 307
Object Oriented DataFlex .................................................................................................................... 307
Discovering Object Oriented DataFlex Introduction
Introduction
Discovering Object Oriented DataFlex is a training guide designed to introduce users to object oriented
programming. The manual was written using DataFlex version 3.1 to be used in a classroom
environment or as a self taught study guide. DataFlex version 3.1 will be required when using this
manual since the packages and new features of this version are used.
Students should have some familiarity with DOS and/or Microsoft Windows and know how to use a
computer mouse. Prior knowledge of the DataFlex language is not required, although knowing a
computer language will make the concepts presented here easier to grasp. It would be in the student’s
best interest if they researched a few topics before class:
• DataFlex file extensions (.dat; .k??; .tag; .def; .fd)
• Overview of DataFlex utilities
• General knowledge of DataFlex file relationships
• Indexes (unique, non-unique, overlap)
• Students are encouraged to read the reading list on the next page
• Use of your favorite Editor that allows multiple files to be opened, the editor
used in the manual is the DataFlex Editor (DataFlex Program Development
System, DFPDS)
Students with prior DataFlex experience may wish to jump over sections, therefore, all chapters list the
topics covered and a “Who could Skip” note, which will help the very motivated student decide if they
wish to skip over a lesson. Included on the startup diskette that comes with the training manual are
.ZIP files. These .ZIP files are step by step snapshots of the files at the end of every lesson. Lessons
are built on code from prior lessons. If you wish to skip Lesson 2, unzip Lesson02.Zip and all your
files will be ready to start Lesson 3.
To Excel Quickly:
A training plan must be implemented. This should include all of the DataFlex manuals. The manuals
have been updated and the UIMS Handbook is now full of fabulous examples. No matter if you attend
a class or use this manual as a self study guide a recommended study list will speed you along to
success.
Developing Application with DataFlex is a tutorial. Reading this manual before attending class
will increase the knowledge obtained from this course.
Another avenue that should not be overlooked is the Example programs that can be found in the
\USR\EXAMPLE sub-directories. You will find full applications that I’m sure you will find
useful.
If you have no procedural programming experience the encyclopedia will list all commands and
an explanation of them. Make sure this manual is available or have the on-line help easily
accessible.
The students will be guided through Object Oriented concepts while creating a small application. The
hands-on classroom environment will normally consist of two students per computer. The sharing of
computers will allow each student time to practice what they are learning while also learning from each
other. The course length is flexible but normally will be three days. This will be a fast pace course
covering lessons 1 through 11 and their corresponding labs. If the course length is increased the
workshop project will be covered and the Discovery Questions included. When additional course days
are included it is also suggested that lab times be increased. The appendixes were not intended to be
covered in class but were added as additional information and examples.
The manual is divided into eleven lessons, each ending in a Lab. The instructor will guide the class
during the basic lesson section in a lecture format or when appropriate, creating the application with
the students following along on their computers. The labs give the students time to practice on their
own, with the instructor giving assistance only when required. The labs will add more and more
functionality to the application. Upon completion of the lab, the material will be summarized by the
instructor. This will include answering questions and also covering the code changes as time permits.
Day one uses the DataFlex utilities (DFFILE, DFAUTO, DFGEN) as it builds the files and basic code
sections what will be modified throughout the rest of the course. Day two and three cover more object
oriented concepts while adding code fragments to the application. These code fragments occasionally
are complex, and may require the students to study the code outside of class to fully grasp the concept.
Therefore it is recommended that the students read the code changes the night before these last two
class days. The instructor will instruct you on the next day’s lesson plan.
File | Options
• Informative Text:
Informative data will be displayed in this font and will be used to explain topics.
• Notes:
Notes will be displayed like this. If a note is directed to only certain students,
example: (for users of prior versions of DataFlex) it will state this in
parentheses at the beginning of the note so students can skip over notes that
do not pertain to them.
Use UI
Clearscreen
Start_UI My_Editor
• Test Programs:
If the code is available as a test program that can be run to demonstrate a
concept, the source code filename will be displayed at the top of the code.
• Code Segments:
There are a few modification to the code that require considerable typing. In
these instances, files are available on the startup diskette that allow the student to
simply load the code segment into their program. This will allow them to
concentrate on the code modification and not their typing skills. When loading
the code, be sure you are in the correct location where the code should be
inserted.
End_Object
End_Object
DataFlex Manuals
The purchase of a DataFlex license really buys two languages, a Procedural and an Object Oriented
Language. The manuals available are:
The manuals are now available as online documentation via the Acrobat Reader. If you are using
Microsoft Windows it is highly suggested that you open a window with the Acrobat Reader loaded.
This will give you quick reference to the manual and get you accustomed to using it. Manual can also
be purchased in printed form.
L esso n 1
Class Setup
The manual was created for use with DataFlex 3.1. This lesson ensures that we have the required
equipment and software. The setup diskette that comes with this manual has all the needed files that
are used throughout the manual. We will install these files in a newly created directory.
• Equipment Requirements
Who could Skip?: Skip only if all class computers have been set up to match the manual in an effort
to meet class time requirements. Otherwise a review of these screens and their settings is very helpful
to discover what default settings are available, and to learn of defaults that will help save you time and
energy.
Equipment Requirements
• Computer
• 386SX or better
• Hard Drive Space: 20 MB for installation and 23 MB for Documentation
• EMM 386 or QEMM 386 Ver 7.0
• 3 MB of free EMS or XMS
• Share /F:8192 /L:500 (if required)
• Computer mouse installed
• DOS 6.22 or Windows 95 installed
• DataFlex Full Development License Version 3.1 installed
• Acrobat Reader and Documentation installed
The diskette that comes with this manual contains all required files to complete the lessons. We will
make a working subdirectory on your Hard Drive and copy the entire floppy to that directory. Included
on this floppy is a Filelist.CFG.
MD C:\FLEX\ClassOOP
Copy A:*.* C:\FLEX\ClassOOP
Setpath
DFRun
L esso n 2
The Basics
This lesson covers the use of DFFile, AutoCreate and AutoGen. Our files and programs that are used
throughout the rest of the manual are created in this chapter.
• Our Project
• File Relationships
• Using DFFile
• Creating a new file in DFFile
• Classes and Objects
• Using DFAuto
• Moving & Resizing Objects
• Drawing Lines
• Building Multiple Objects
• Switching between Objects
• Entry Options
• Generating Code
• Running a New Program
• Object Toolbox (correcting navigation problems)
• Creating Selection Lists (Prompts)
• Connecting Prompts at Item level & Object level
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Our Project
The project that we will be creating throughout this manual is a small accounting system to track our
personal books and net worth over the years. I apologize to accountants and bookkeepers if I do not
follow true accounting rules, but my objective is not to teach principles of accounting, but to
demonstrate as many Object Oriented skills as possible.
As we create our bookkeeping system, we will be adding test data. The test data you enter may be
altered to protect your true financial condition or enter Bill Gates’ net worth, in which case you will
need to drastically increase the size of all amount fields.
Files Description
Type Stores a list of valid GL Account Types. E.g., Assets, Liabilities, Expense
GL_Accts General Ledger File containing a record for each Account that we wish to track. E.g.,
Checkbook, Charge Cards, Computer Expenses
Yr_Hist This file will be related to the GL_Accts file, each record will be a yearly summary,
with individual fields of the monthly running totals for activity in the GL_Acct.
Budget information is also stored. (normally only income and expense accounts have
budget information).
Tran_Hdr Transaction Header file contains the general information about each transaction
(Trans#, Date).
Tran_Dtl Transaction Detail information of each transaction ($5.00 from the checkbook).
Sysfile A one record file, that stores system information, such as the next transaction number.
E Expenses
I Income
SYSFILE
C Capital
L Liabilities
A Assets
TYPE FILE
-------------------------------------------------------------------
DATE: 01/25/96 TIME: 13:49 PAGE: 1
FILE DEFINITION FOR FILE: TYPE (# 5)
-------------------------------------------------------------------
...
2 DESCRIPTION NO NO 20 3 1 ON-LINE
-------------------------------------------------------------------
DATE: 01/25/96 TIME: 13:49 PAGE: 1
FILE DEFINITION FOR FILE: YR_HIST (# 4)
...
-------------------------------------------------------------------
DATE: 01/25/96 TIME: 13:49 PAGE: 1
FILE DEFINITION FOR FILE: TRAN_DTL (# 3)
-------------------------------------------------------------------
...
-----------------------------------------------------------------------------
DATE: 03/13/96 TIME: 20:58 PAGE: 1
FILE DEFINITION FOR FILE: SYSFILE (# 6)
-----------------------------------------------------------------------------
DRIVER NAME : DATAFLEX
FILE ROOT NAME : SYSFILE
USER DISPLAY NAME : Sysfile
DATAFLEX FILE NAME : SYSFILE
-----------------------------------------------------------------------------
RECORD LENGTH : 32 ( USED: 3 )
MAX NUMBER OF RECORDS : 1 ( USED: 0 )
FILE COMPRESSION : NONE
RE-USE DELETED SPACE : YES
LOCKING TYPE : FILE
HEADER INTEGRITY CHECKING : YES
TRANSACTION TYPE : CLIENT ATOMIC
RECORD IDENTITY INDEX : 0 ( 0 , 0 )
FILE LOGIN PARAMETER :
SYSTEM FILE : YES
-----------------------------------------------------------------------------
Figure 1
File Relationships
The main purpose for creating a relationship is to aid data integrity. This is accomplished by stopping
duplication of data. When data is duplicated, data integrity starts dropping. (E.g., A customer has
opened multiple accounts at a bank: saving account, checking account, a car loan, and a safe deposit
box). If the customer’s address changes and this data is duplicated, four corrections to the database
would be needed. If the account records related to a customer master file, then only one correction
would be required.
We create relationships between parent and child files by a common field that is the same in both files.
This related field is the link for child records to find their parent record and for a parent record to find
all related child records. In the above example a Customer number would typically be used.
Types of Relationships
Books Child
Bridge Relationships:
Many to Many relationships are not
Doctors Operations
supported in DataFlex, but a bridge
file solves this problem. In our
example, we have many doctors
per operation, and many operations
per doctor. Here the only fields LinkFile
needed in the Linkfile are the two
related fields, but many
bridge files store other valuable data.
Employee
Sibling Relationships:
This relationship links two child
files to a single parent file
PayHist TimeCard
This “rule” is really another way of stating rule #2. DataFlex does not support many to many
relationships. DataFlex supports one parent record to many child records, or a one to one
relationship.
Rule #2 * _________________________________________________________
Rule #3 * _________________________________________________________
Using DFFile
DFFile is the utility to create or change database structures. The detail field information is stored in the
header of the .DAT file, where the raw data is stored, unless compression is used. Another important
file is Filelist.CFG. This file stores the available filenames (Rootname, DataFlex name, and User
name).
CD\Flex\ClassOOP
DFRUN
Figure 2
We will first open an existing file and browse through some of the screens in DFFile.
File | Open
Figure 3
[ Yr_Hist
[ Open
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Max Records is only used within DataFlex’s sorts to make them more efficient. Add 20% above the
maximum size to which you believe the file will grow.
File | New
Figure 9
[ OK
Figure 10
[ Fast Compression
Figure 11
COMPRESSION
TYPES: SPEED STORAGE
Fast Best Good Compression base on occurrences
Standard Good Better Uses Huffman Encoding Table
Custom Good Best Compression based on actual stored data
Must re-compress periodically
Figure 12
Alt+2
Figure 13
Note: This is an unique index. Records with the same GL# will not be allowed to save. If we
wanted a non-unique index we would add recnum as the second segment of the index.
[ U/C (uppercase)
Figure 14
We are done creating the GL_Acct file, but we wish to create a relationship between Yr_Hist and
GL_Accts. We first need to switch back to the YR_Hist file that we opened earlier.
When multiple files are opened in DFFile you can switch between them by using F7 and F8 keys
(Prev/Next keys). The status bar will display the current file on the bottom left.
Alt+1
Figure 15
F4
[ Attach to Field
Figure 16
GL_Accts
[ OK
Figure 17
[ GL#
[ OK
Figure 18
Note: Only fields of the same length and type are displayed.
Figure 19
File | Save
Figure 20
[ OK
Figure 21
File | Exit
Figure 22
[ Yes
Figure 23
[ OK
Figure 24
The Entry_Form Class is a Tool that will provide data entry services displaying one logical record at a
time. A Table Class is a tool that allows users to view and edit a scrolling, multi-column list from a
database file. Sample objects that use these two classes are shown below. Notice the Use command.
This command will bring in the code needed to make the class operate.
Objects:
...
While creating tools can be quite complex, using them is relatively straight forward.
Note: (for DataFlex Procedural Programmers) The ENTER, ENTERGROUP, and REPORT
Macros are each similar to a CLASS. Each time you used them would be an example of an
OBJECT. The BIG advantage is that the enter and report macro could only be used once in a
program, whereas the Entry_Form class can have multiple objects built from it.
DataFlex provides a full set of classes (tools). These are the most common, high level classes.
Programmers can create their own classes, use those provided, or customize those provided. Most
application developers will find the DataFlex tool set provided with the language to be adequate for
their need. Programmer should guard against becoming tool builders.
Using DFAuto
We now have our files and we’re ready to start an application.
Development | Auto
Definition Utility
Figure 25
Application | New
Figure 26
Figure 27
Note: The main file cannot be changed! Therefore, be sure it is the child-most file needed in the
view.
[ OK
Figure 28
Figure 29
Figure 30
Radio buttons are a way to make a selection. Below they allow you to select a border type and title
style. To select, click with the mouse or move the cursor and select by pressing the spacebar.
[ OK
Figure 31
Figure 32
Resizing is done from the right or bottom border. Selecting the bottom right corner will “rubber band”,
changing the size in both directions at once.
Figure 33
As with a word processor, we can type in static data to our image. The Ins/Over mode can be changed
with the I key.
Figure 34
Figure 35
Drawing Lines
The secret of drawing lines is to position the cursor where you wish to start the line before turning on
Line mode, and then remembering to turn it off again.
Line Mode can be selected from the Edit pull down or it may be toggled (on/off) using the Ctrl+F1.
The status bar on the bottom right will show you the line mode status.
When drawing lines you may use the arrow keys, but it is faster to use the END, HOME, PGUP,
PGDN keys to quickly draw a line from border to border.
Figure 37
Figure 38
Figure 39
Database | Open
Figure 40
Figure 41
Figure 42
[ OK
Figure 43
Figure 44
Description Field
Figure 45
Figure 46
Figure 47
Figure 48
Figure 49
Figure 50
Entry Options
GL_Accts.GL# should be
displayed in the middle of
the status bar
Figure 51
To select an option either move to the option and press Space bar, or click on the option.
[ AutoClear
[ AutoFind
[ OK
Figure 52
A short cut to bringing up the Entry Option Dialog is to use the (F4) Key
F4
Check Capslock
[ OK
Figure 54
Figure 55
Generating Code
Application | Generate
Figure 56
[ OK
Figure 57
[ OK
Figure 58
[ OK
[ OK to overwrite
[ OK to complete
Figure 59
Application | Exit
Figure 60
Type: Test
[ OK
Figure 61
Figure 62
We have things to change, but this test is to simply check the cursor navigation.
Press T or J multiple
times and notice the
navigation through the
images
NAVIGATION KEYS
Tab Next item
Shift Tab Back item
F6 Switch
Shift F6 Switch Back
Record | Exit
[ OK
Development | Auto
Definition Utility
Figure 65
Application | Open
Figure 66
[ Ledger
Figure 67
Figure 68
Figure 70
[ OK
Figure 71
Figure 72
To solve the problem of keeping the memo object on top, we nest it inside the GL_Account Form.
Figure 74
The next problem was the program starting in the Yearly_Summary object instead of the GL_Accounts
object. To solve this, we move the GL_Accounts Form before the Yearly Summary Form.
One important fact is that the Data Entry Objects are serviced (for finds, clears, saves and deletes) by
the Data Set Objects that they are listed under.
For this reason the GL_Accounts Form should be moved below the GL_Accts Data Set.
w GL_Account_Form
to the box behind the
GL_Accts Data Set
Figure 75
Figure 76
Application | Generate
[ OK
[ OK
Figure 77
[ Compile after
generation
[ OK
[ OK to overwrites
Figure 78
Application | Exit
Figure 79
Type: Test
[ OK
Figure 80
Figure 81
KEY OPERATION
F2 Save
Shift F2 Delete
F7 F8 F9 Prev/Next/Find
Figure 82 F5 Clear
F6 Switch
Figure 83
In future modifications to this view we will have the Yearly Summary Object fill automatically when a
GL account record is found. But for now we will only enter GL Account records.
Return to DFAuto
Application | Open
Ledger
Figure 84
Figure 85
[ OK
Figure 86
Figure 87
The selection list is now created BUT it must be attached to a window or object.
Attaching it to the GL# window will allow us to call the selection list from this window by pressing the
F4 key.
F2
Figure 89
Note: A common mistake is to attach the prompt to itself, attach it to an item (Field | Field Entry
Options) or another object (Object | Style).
Figure 90
Figure 91
Changing Objects: When multiple objects have been created, you can skip between them with the
mouse but sometimes an object is totally hidden behind another object. You can use the Object |
Switch pull down or you can use the tab key to rotate between the objects. The status bar will indicate
which object is in focus.
[ GL# field
F4
At this point the selection list still exists, BUT it is again unattached. Attaching it with the Object |
Style will allow us to call the selection list from any window in the object.
Object | Style
F4 select GL_List
[ OK
Figure 93
Figure 94
Lesson 2 Lab:
Description:
Create a New Application that will allow TYPE file records to be created/edited/or deleted. DFAuto
will be used to create this view, at the same time creating the file, fields and indexes all within the
DFAuto utility.
Tasks: Type
The next step will be slightly different from what was done in the lesson. The lesson created the file
using DFFile, but DFAuto can also create a new file. Instead of selecting Fields | Field Toolbox
from the pull-down, this time select Fields | New Field Toolbox to create the file from within
DFAuto.
FIELD
FIELD NAME TYPE LENGTH
Code ASCII 1
Description ASCII 20
Figure 95
• Add a prompt that displays both fields and attach it at the object level of the entry form.
• name the prompt GLType
• use a double border
• use a popup title style
• add lines to separate fields
• place fields using Fields | Field Toolbox
• attach prompt at object level
• Run Test program and Enter the following Test Data. Since it may be helpful to know if an
account normally has a debit or credit balance, we will add this to the description.
CODE DESCRIPTION
A Assets (debit)
L Liabilities (credit)
C Capital (credit)
I Income (credit)
E Expenses (debit)
2 - 2. Within DFAuto, what is the difference between a Dialog Title and a Popup Title?
2 - 3. In Lab #2, when creating the Type.Code field, if a mistake was made and this field was created
as a numeric field instead of an ASCII field, could this be altered without leaving DFAuto?
2 - 4. You were hired to write an application for a college and you have two files: Classes and
Students. What type of relationship is this?
2 - 5. Can you select a pull-down from the Action Bar if a prompt is displayed? Try it.
L esso n 3
Code Changes
In this lesson we leave DFAuto and start to modify the code manually. We see how to connect
multiple views together and make small improvements to our program.
• Connecting Views
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Let’s look at a final application with all its modular parts. The Use command allows us to have our
modular code in separate files. When compiling this “Use”d file is brought in and compiled with the
rest of the program. With our code broken down into stand-alone modules, we have encapsulation.
//EnClient.PKG
Use AllEntry // Code for Classes (Tools) //Allentry.PKG
Use ExitApp // Smart Exit Code use enclient
use data_set
//Data_Set.PKG
Set Application_name to "Payroll Application" use menu
...
//Menu.PKG File
Use BackGnd // Standard background and title
Send Paint_Desktop to (Background(Current_Object)) //Exitapp.PKG
ôMy Programö
/*
Things to note!
• The main program is a shell where modular sections of code are included (via the USE Command)
• During compiling the Use command loads the file only if it has not previously been loaded.
• The first 3 files brought in by the USE command end with the extension .PKG. These Package
files contain Class definitions (the code to make the tools work). The .PKG files are not always
classes, sometimes they are support packages that perform special functions.
• The last 4 files that the USE command brought in end with the extension .VW. These are View
files and are the heart and soul of the program. These views are modular sections of code that can
operate independently. A small Test program is used to test and debug each view. When the views
work properly alone, they are added to the main program.
• Also note that all the views have the same command “USE EMPLOYEE.DS”. This file is needed
in each view so it will operate correctly when using the view separately in a test program.
Although all the views are added together in the main program, the EMPLOYEE.DS file is only
included into the program once! If a change has to be added to the code in the EMPLOYEE.DS
file, it only needs to be modified in the one place and after re-compiling will affect all the views.
• The cascading affect of one file using code that uses another file allows our code to be very
modular. These modular code sections seem confusing at first. The real benefit is gained when
you modify or debug your code. In the same way that it is harder to trouble shoot a computer that
has everything built into the motherboard. If the serial port is a separate card you can repair it
without worrying about breaking the Disk Controller. But if everything is on the mother board,
fixing one problem can break other parts.
Note: (for DataFlex procedural programmers) The Use command is very similar to the
#INCLUDE compiler directive that you may have used in your code. The main difference is that the
#INCLUDE would include a file numerous times, but the USE command will only bring in a file
once.
Note: (for DataFlex procedural programmers) A Menu program with RunProgram wait and
Chain wait commands is comparable to what we now call views.
These tasks can be performed by different developers and they can be performed in any order. This
makes team development easier and allows developers to stay focused on the task at hand. When
working with views you will be concentrating on the visual aspects. When working on the DSOs,
business rules will be the focus.
There are many similarities between Procedural and Object Oriented programming. Let’s look at an
example of both:
Connecting Views
We’ve created two views so far, our Ledger view and our TypeEnt view. If you notice each time we go
into DFAUTO and generate code using the “View test program” option, the file Test.SRC is
overwritten, making the view pull-down list the newest view package created. If we select the “View
package” option when generating, then only the view is generated and the file Test.SRC will not
change.
Use DFTEST
Add_test "Test Program..." Send Activate_TYPEENT to desktop
Use TYPE.VW
Start_Ui (Main_Menu(Current_Object))
//Type.VW File
...
If we look inside the TypeEnt.VW Activate_View Activate_TYPEENT for Type_View
file, there are two items that must
match. The Object_name of the Object Type_View is an Entry_View_Client
...
Entry_View_Client and the
Activate_procedure_name that
will be created at the desktop
for you.
Development | Program
Development System
Test.SRC
[ OK
Figure 97
As you can see, the Test.SRC program is very small. It is used as a test bed to test all programs before
adding them to the large application. If we wanted the Test.SRC program to test multiple views, we
would modify it like this:
Use DFTEST
Use LEDGER.VW
Use TYPEENT.VW
// use command will bring in View code
Start_Ui (Main_Menu(Current_Object))
File | Save as
MyTest.SRC
Figure 98
Record | Exit
Figure 99
.DEF files are ASCII representations of existing files, that can be created from DFFile and DFMaint.
DFFile can quickly create a duplicate file by loading a .DEF. This is useful when two files have
similar structures or to add a new file to the customer’s filelist. These DEF’s also provide an excellent
visual reference for the files.
-----------------------------------------------------------------------------
DATE: 01/19/96 TIME: 12:38 PAGE: 1
FILE DEFINITION FOR FILE: TRAN_DTL (# 3)
-----------------------------------------------------------------------------
DRIVER NAME : DATAFLEX
FILE ROOT NAME : TRAN_DTL
USER DISPLAY NAME : tran_dtl
DATAFLEX FILE NAME : TRAN_DTL
-----------------------------------------------------------------------------
RECORD LENGTH : 512 ( USED: 13 )
MAX NUMBER OF RECORDS : 1000 ( USED: 31 )
FILE COMPRESSION : NONE
RE-USE DELETED SPACE : YES
LOCKING TYPE : FILE
HEADER INTEGRITY CHECKING : YES
TRANSACTION TYPE : CLIENT ATOMIC
RECORD IDENTITY INDEX : 0 ( 0 , 0 )
FILE LOGIN PARAMETER :
SYSTEM FILE : NO
-----------------------------------------------------------------------------
NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD
--- --------------- ---- ----- ----- -- ---------------------------------
1 TRANS# NUM 6.0 1 1 TRAN_HDR.FIELD_1 (2,1)
2 DETAIL# NUM 6.0 4 1
3 GL# NUM 4.0 7 2 GL_ACCTS.FIELD_1 (1,1)
4 DC ASC 1 9
5 AMOUNT NUM 6.2 10
Figure 100
Figure 101
Tran_Dtl
[ OK
Figure 102
The “Load ONLY field & index info:” checkbox will default a few values (such as max length and
max records) found on the Parameters Screen. After loading the .DEF, the Parameters Screen is
displayed, allowing you to make any needed changes.
Alt + 1
Figure 103
File | Exit
[ Yes
Figure 105
DFAuto can only work with files located in the file structure at a level above that of the main file. The
next object we need will be displaying fields from the Tran_Dtl and Tran_Hdr files. The Tran_Dtl file
is a sibling file to Yr_Hist. We will not be able to create everything from within DFAuto BUT we can
save time by allowing DFAuto to generate as much code as possible. We’ll then take our code to an
editor to make the final modifications.
Type
GL_Accts Tran_Hdr
Yr_Hist
Tran_Dtl
We’ll add another object using DFAuto, but instead of creating the object from scratch, we will import
the image in from an ASCII file. This feature will allow you to reuse images created at an earlier time.
Within DFAuto
Application | Open |
Ledger
Figure 106
Figure 107
Trans.IMG
[ OK
Figure 108
[ OK
Figure 109
Application | Exit
Figure 111
Development | Program
Development System
Ledger.VW
Figure 112
Note: DFAuto will not know about any modifications made outside DFAuto, so make sure you
accomplish as much as possible in DFAuto before starting to make manual code changes.
Note: (for New DataFlex Users) The semicolon “;” is used to continue a command on the
following line.
DFAuto has generated as much code as possible for a sibling file. We’ll have to manually modify the
rest of the code. There are six modifications required to make our new view functional. (More code
changes will be added in later lessons.) This is our first code modification. Concentrate more on the
code structure and not on each detail command.
Code Modifications:
1. Substitute the .DS files with Accts.DS. Remember we stated the .DS files are the Class
Definitions. Accts.DS is a file that has a Data_Set Class definition for every file in our accounting
system. The file was place on the startup diskette so we could simply use the ACCT.DS file for
now and cover it in depth in Lesson 10.
2. Create Data_Sets for the added files. Every file opened should have its own Data_Set object.
Since we are using two new files, we’ll create two new Data_Set Objects. Lesson 9 will cover this
in detail.
3. Update the Transaction_TBL_Image. Since we did not place any fields in this object, the item
windows need to be inserted.
4. Adding the Using Clause to Transaction_TBL Object. This link will connect the Data_Set to this
object for database services (finds, clears, saves & deletes)
5. Since this object will eventually be used for viewing only, we’ll modify the confirmation messages.
6. Add entry_items in the Transaction_TBL which lists the file.fields associated with each window
item.
//********************************************************************************
// LEDGER
//
// Author : Student's Name
// Originally created : 01/13/96
// Last Update :
//
//********************************************************************************
Use ALLENTRY
Use CONFIRM
Set Class_Colors to U_TEXT_WINDOW 0 0
//Use GL_ACCTS.DS
//Use YR_HIST.DS
Use ACCT.DS // This is a supplied file with a Data_Set Class for each file
// this file will be covered in detail in lesson 10
// Selection_list object-packages
Begin_constraints
constrain YR_HIST relates to GL_ACCTS
End_Constraints
End_Object // YR_HIST_DS
Object TRAN_HDR_DS is a TRAN_HDR_Data_Set No_Image // Two new files requiring DataSet Objects
End_Object // TRAN_HDR_DS // explained in full in Lesson 9
/GL_Accounts_EF_Image
┌─ General Ledger Accounts: ───────────┐
│ GL# ___. Type _ │
│ │
│ ___________________________________ │
│ │
│ Current Balance ______.__ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────┘
/Memo_EC_Image
┌─ Memo: ────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
└────────────────────────────────────┘
/Yearly_Summary_EF_Image
┌─ Yearly Summary: ────────────────────┐
│ ___. Budget: Actual: Differ:│
├──────────────────────────────────────┤
│ Jan ______.__ ______.__ │
│ Feb ______.__ ______.__ │
│ Mar ______.__ ______.__ │
│ Apr ______.__ ______.__ │
│ May ______.__ ______.__ │
│ Jun ______.__ ______.__
│ Jul ______.__ ______.__
│
│
Switch to overtype mode (Press the insert key)
│ Aug ______.__ ______.__ │
│ Sep ______.__ ______.__ │
│ Oct ______.__ ______.__ │ Date mm/dd/yyyy
│ Nov ______.__ ______.__
│ Dec ______.__ ______.__
│
│
Type ASCII 1
└──────────────────────────────────────┘ Amount Numeric 6.2
/Transactions_TBL_Image
Explanation ASCII
┌─ Transactions: ───────────────────────────────────────────────────────────┐ 50
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
└───────────────────────────────────────────────────────────────────────────┘
/*
Item_List
Entry_Item GL_ACCTS.GL# { AutoClear, AutoFind, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.TYPE { AutoClear, Capslock, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.NAME { AutoClear, IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.CURRENT_BALANCE { AutoClear, ;
IPrompt=(GL_List_SL(Current_object)) }
End_Item_List
End_Object // Memo_EC
End_Object // GL_Accounts_EF
Item_List
Entry_Item YR_HIST.YEAR { AutoClear, AutoFind }
Entry_Item YR_HIST.BUDGET_01 { AutoClear }
Entry_Item YR_HIST.ACTUAL_01 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_02 { AutoClear }
Entry_Item YR_HIST.ACTUAL_02 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_03 { AutoClear }
Entry_Item YR_HIST.ACTUAL_03 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_04 { AutoClear }
End_Object // Yearly_Summary_EF
// Properties you might need to set. These reverse the default settings.
// Remove what you do not need.
Begin_Row
Entry_Item TRAN_HDR.DATE { DisplayOnly }
Entry_Item TRAN_DTL.DC { DisplayOnly }
Entry_Item TRAN_DTL.AMOUNT { DisplayOnly }
Entry_Item TRAN_HDR.EXPLANATION { NoPut } // Will not put data to the buffer
// but will take focus to allow
// scrolling.
End_Row
End_Object // Transactions_TBL_Im_TBL
End_Object // LEDGER_View
File | Save
Figure 113
File | Open
TypeEnt.VW
Make Modification
Figure 114
File | Open
Mytest.SRC
Alt+G
Figure 115
Note: We must always Compile the .SRC file NOT the .VW or .DS files.
Figure 116
File | Exit
Figure 117
Lesson 3 Lab:
Description:
Create a new view, “Journal”, that will allow transactions to be entered. Our views in Lesson 2 were
ready for data entry as soon as they were created from DFAuto and generated from AutoGen. Some
views, such as this next one, require additional manual coding before use. This lab will create a basic
view structure in DFAuto. The code created will then be modified throughout the rest of the manual.
Tasks:
• Within DFAuto, start a new application and call it Journal, the main file will be Tran_Dtl.
Figure 118
• Object | Object
Toolbox and make
the necessary
changes/additions
To create Tran_Hdr
Data Set select:
Object | New |
Data_Set
Since we modified the .DS files in Ledger.VW to use ACCTS.DS, we’ll also need to do the same
inside Journal.VW & TypeEnt.VW. Open both views and change the .DS files as shown:
//********************************************************************************
// JOURNAL
//
// Author : student's name
// Originally created : 03/03/96
// Last Update :
//
//********************************************************************************
Use ALLENTRY
Use CONFIRM
Set Class_Colors to U_TEXT_WINDOW 0 0
//Use GL_ACCTS.DS
//Use TRAN_HDR.DS
//Use TRAN_DTL.DS
Use Acct.DS
In Lab 2 you created the TYPE file. In future code modifications we will need the relationship
between GL_Acct and Type. Create this relationship in DFFile.
• Within DFFile open the Child File, which is ___________
• In the Relate to column of child field _____________ relate it to parent field ___________.
• Verify that the Parent related field is uniquely indexed.
• Save File and Exit DFFile.
Now that we have a relationship between the GL_Accts and Type files, there is one more modification
that has to be made to the Ledger view, and that is changing the reference of the child related field to
the parent related field. When a related field is being displayed the parent field NOT the child field
should be referenced. During a save operation, an Attach command is executed. This moves the
related field data from the parent to the child. If the child related field were to be displayed, a blank
field would be saved to the child record.
Mainprog.TEM is a file that comes with your DataFlex product and can be modified to quickly put our
views together. You will find this file in your classoop subdirectory.
• Open Mainprog.TEM in an editor
• Modify to include our three views (Ledger, Journal and Type)
• An About.PKG has already been included in your classoop directory
//======================================================================
// MainProg.Src - Template main program
//
// This is a template for creating a main program. Enter the Views you
// need and USE the object package files as required. Look for ???
// where you need to fill in your own information
//======================================================================
//----------------------------------------------------------------------
// Mainprog.Src: Personal Accounting System
//
//
//----------------------------------------------------------------------
Use AllEntry
Use ExitApp // Smarter exit. Checks and warns of changes.
/Main_Menu
______ ____ ____ ________ ____
/View_Pull_Down
┌─────────────────────────────┐
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
├─────────────────────────────┤
│ ___________________________ │
└─────────────────────────────┘
/*
Create_Menu Main_Menu Location 1 0 Absolute
#INCLUDE TXTW_PD.INC
#INCLUDE NAVI_PD.INC
#INCLUDE HELPA_PD.INC // modified help pulldown. Includes about.
End_Menu
• Save As Mainprog.SRC
3 - 3. In Mainprog.SRC, we used a file called MyAbout.PKG. This file was modified for you from
the About.TEM file. Did you discover what this file is for?
3 - 4. There is a TypeTbl.IMG file in your Class subdirectory. Create a new application in DFAuto.
Load this ASCII image as a table object that displays records from the Type file.
3 - 5. When using the USE command can you leave off the file extension?
L esso n 4
DEOs And DSOs
This lesson divides classes into their two major groups. Describing the most important features in
both.
• Object Nesting
• Constraint Blocks
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Computer glossaries are full of acronyms. Here are two new ones: DEOs and DSOs.
Object Nesting
Nesting of Objects is the actual physical positioning of one object inside another object in your
source code. Nesting is often done with Client classes since they were designed to be used as
containers.
End_Object // Entry_View1
DSOs should never contain DEOs. This breaks one of the basic Framework* rules. Your code may
work with this structure, but there are limitations to this structure and inconsistent results will occur
when using this structure.
DEOs may be nested, the basic reason for this being navigation. Chapter 2’s memo object
demonstrated this.
* Note: DataFlex Application Framework (or framework) is the methodology / guidelines for
writing object oriented DataFlex applications.
Constraint Blocks
One type of constraint is based on relationships. We constrain the view so only related child records of
the parent can be seen. This constraint is needed in some views and not desired in others.
Dept
Employee
Needs a Constraint
In this view we want the table to
fill only with Employees (child
records) that are related to the
Dept. (parent record).
Figure 119
Figure 120
The Constraint Blocks in the prior example were used to limit the records shown in a table to only the
related child records of the parent. We can use them to restrict the database viewing in many ways.
We will cover properties in the next lesson, but I wish to note a short-cut here. A relate constraint
block can be coded by setting a property.
Begin_Constraints
Constrain EMPL relates to DEPT
End_Constraints
End_Object
Here we limit the view to only TimeCard records with a date greater than 01/01/1996
Begin_Constraints
Constrain TimeCard.Date GE 01/01/1996
End_Constraints
There can also be multiple constrain commands within the Constraint Block.
Here we limit the view to only TimeCard records with dates greater then 01/01/1996 and Employ_ID
that are greater then 250.
Begin_Constraints
Constrain TimeCard.Date GE 01/01/1996
Constrain TimeCard.Employ_ID GE 250
End_Constraints
The above example can also be written like this, but because of the use of expressions it would not be
optimized. For this reason avoid it whenever possible.
Begin_Constraints
Constrain Timecard as ((TimeCard.Date GE 01/01/1996) and ;
(TimeCard.Employ_ID GE 250))
End_Constraints
You might be thinking . . . Hey, this sounds great, but I want to change these constraints on the fly in
my running program!
In both these cases as soon as you change the value of the variable or property you MUST send
the message Rebuild_Constraints to the data_set.
Begin_Constraints
Constrain Customer.State EQ "FL"
End_Constraints
...
Begin_Constraints
If Limit_View Constrain Customer.State EQ "FL"
End_Constraints
If Limit_View, is true then only FL customers will show, if false then all customers will show.
In order for our views to operate correctly, each DEO should have a DSO that services it, for such
things as Finds, Clears, Saves, and Deletes. The Using clause is what Links the DEOs to their DSO
Server.
Customer_DSO is a Customer_Data_Set
End_Object
End_Object
Each View will have DSOs and DEOs that will connect by way of USING clauses. Each Data Entry
Object in each view is served by Data Set Objects within its own view. This is what makes each view
operate independently of all other views!
End_Object // DSO1_View
End_Object // DSO2_View
Remember, we stated that Data Set Objects are never nested. However related files do need their
DSOs to be connected. In order for our database operations to perform correctly, we link our DSOs
together much like our file relationship structure.
The connecting of DSO to DSO is done with the UPDATING clause. We connect DSOs when they
should act in a coordinated manner. In a general rule, the child-to-parent file updating links will match
the child-to-parent relationships.
Employee
Relate Relate
Constraint Constraint
Data-Set Structure:
Object Dept_DS is a Dept_Data_Set no_image
End_Object
Begin_Constraints
Constrain PayHist Relates to Empl
End_Constraints
End_Object
Begin_Constraints
Constrain Timecard Relates to Empl
End_Constraints
End_Object
Step 1 Code an object for each file. Start at the top of the file structure, and work from left
to right and from top to bottom. Listing the DSOs in this order will eliminate
forward reference problems of using a DSO in a clause before the object
declaration.
Step 2 Add the DSO Updating clauses. Each child file will have an Updating clause listing
all of its parents. Note that the Updating clause can have more then one parent
DSO listed. Therefore, the Updating clause should always be the last clause listed.
Step 3 Add a constraint block in the child DSO if needed! Not all child files should be
constrained. Think about your application and add the constraints where they are
required.
Lesson 4 Lab:
Description:
Practice linking DEOs to DSOs using the “USING” clause.
Practice creating a Data Set Structure using the “UPDATING” clause.
File structure:
Type
GL_Accts Tran_Hdr
Yr_Hist
Tran_Dtl
Ledger View:
• Fill in the Using Clauses
• Fill in the Updating Clauses
• Create Constraint Blocks in the DSOs that require them
Object Ledger_View is an Entry_View_Client
End_Object // Yr_Hist_DS
// End_Constraints
End_Object // Tran_Dtl_DS
End_Object // GL_Accounts_EF
End_Object // Transactions_View
Tasks:
Journal View:
• Fill in the Using Clauses
• Fill in the Updating Clauses
• Create Constraint Blocks in the DSOs that require them
Object Journal_View is an Entry_View_Client
End_Object // Tran_Dtl_DS
End_Object // Header_EF
End_Object // Transactions_View
4 - 2. Write a constraint block that would not show records from the Employee file if they have a “Y”
in the Terminated field
4 - 3. If I add a Constraint Block, I know I can no longer find a record outside the constraint, but can I
save a record that does not meet the constraint? Take your TypeEnt.VW and add a constraint
block that limits Type.Code GE “I” and then try saving a new record that has a code of “B”.
4 - 4. In the below example the Entry Form references the Customer file, the OrdHead file and the
OrdType file. Which file should the using clause reference?
OrdDetail
File
L esso n 5
Messages
This lesson covers messages, how to send them, how they are forwarded and delegated and the
creation of new messages.
• Augmenting
• Canceling
• Overriding
• Adding (creating)
• Timers
• Access Methods
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested. I
believe this is such an important chapter that no matter how much of a review you think this chapter is,
please scan it.
Object oriented programming is ideally suited for supporting “Event Driven” environments. An event
has to occur in order for anything to happen. Earlier in the manual, we compared procedural code to
object oriented code. In procedural code we used the gosub command, in which we performed a
subroutine and then returned to the main flow of the program. Object oriented programming is similar
in that we now send messages. These messages correspond to procedures or functions with the same
name. An important way in which procedures and subroutines differ is that a subroutine jumps to a
label. There can only be one label with the same name, therefore a subroutine call can be made to only
one subroutine. We’ll discover that we can have multiple procedures with the same name.
Pressing Sends
F2 key Request_Save Procedure Request_Save
Which Sends
other messages
Sending the message “my_routine” without referencing an object will cause the message to be sent to
the current_object (the object currently in control).
Send my_routine
In order to send a message to an object, we need the object’s ID. Here we wish to send the my_routine
message to Empl_EF object using the current_object access method. Basically, this method says, “find
an object named Empl_EF that is a child of the (current_object), and return the object ID”.
Send my_routine to (Empl_EF(current_object))
New Terms:
Current_Object and the Focus Object are often confused, mainly because they are often the same.
• Current Object is the object where the processing is taking place at that instant.
If the user’s cursor is sitting in an Entry_Form, both Current and Focus Objects would be the
Entry_Form. If the user presses the Save Key, the Focus Object remains the same and the Current
Object changes according to which object is processing the many messages that cascade from the
Request_Save message.
When a message is sent to an object, it does not stop if the object does not have a corresponding
procedure. It loops through a cycle trying to find the procedure. I refer to this cycle as the message
waltz. A message cycles through three steps over and over again, trying to find a procedure with the
same name as the message being sent. When it finds the procedure, the dance is over and the
procedure is executed. These three steps are:
2. Forward the message (forward the message up the inheritance path, through classes)
...
Object MyBackground is an Entry_Client
Procedure Request_Clear
Send Bell
End_Procedure Step 1
...
End_Object //My_Entry_Form Found within the current object
Object My_Table is a Table
...
End_Object //My_Table
End_Object // MyClient
End_Object // MyClient
Start_UI MyClient
use UI Step 1
Step 2
Object MyBackground isNot Found within the
Entry_Client
current object Forwarded up the Inheritance Path
Object Employee_DS is a Data_Set
End_Object // Employy_DS
Found in the Object Class
Object My_Client is an Entry_View_Client
Start_UI MyClient
The class that has the procedure in it is referred to as the defining class. How do we know which class
that is? We look it up in the Procedure and Function Chart in the Reference Manual.
This is a good time to look at the Reference manual in the Adobe Acrobat Reader.
If using Windows,
select Acrobat
Reader from the
menu
Or at the OS
command prompt,
type: AcroRead
Figure 121
Select UIMS
Ref.PDF file
Figure 122
If Index to
Messages is not
expanded then click
on the icon
Figure 123
Clicking on the
Object icon will
switch us to the
page where the bell
message is
described.
Figure 124
use UI
End_Object // MyClient
Start_UI MyClient
In the prior example we sent the message Request_Clear and it was found in the current_object.
If we would NOT have had the procedure Request_Clear in the current_object then the message would
have been Forwarded or Delegated And found in which class? ________________
End_Object // MyBackground
Start_UI
Message Do_IT sent
Almost all messages are found and handled by the object or its class. Delegation rarely occurs and
when it does it is usually an explicit process. In other words, the developer knows that an object (or its
class) will not understand the message and that it will have to delegate the message. In the case where
delegation is expected the developer will often explicitly delegate the message (Delegate Send
My_Message). While explicit delegation is not required it does make the programmer’s intent more
clear.
The topics below are methods for creating or changing procedures. These procedures should be
created in the object that you wish to affect.
Augmenting a Message
Augmenting adds to the normal operation of a pre-existing procedure. This is done by Forward
Sending the message. Augment whenever you wish the normal procedure behavior, but need a little
extra.
Procedure Request_Save
Forward Send Request_save // do normal save behavior
Send Bell // then ring computer bell
End_Procedure
Canceling a Message
Canceling is done to stop an object from performing a procedure. Since your procedure is found before
the predefined procedure (in the class or within a parent object), it will look no further and never find
the other procedure.
Procedure Request_Clear
End_Procedure
Overriding a Message
Overriding a procedure is changing the normal behavior and doing something different.
Procedure Request_Delete
Send Bell
GotoXY 24 0
Show “NO DELETIONS ALLOWED!”
Sleep 5
ClearXY 24 0
End_Procedure
....
On_Key Key_Alt+Key_P Send Print_Labels
....
Procedure Print_Labels
Chain wait "PrtLabel"
Send Refresh_Screen
End_Procedure
Note: One procedure can call another procedure. This cascading of messages is very powerful and
useful. If you add the above examples within an Entry_Form Object you will see that a save no
longer clears. Why? Check out Did You Discover Questions
Note: Children will inherit accelerator keys (just like messages) through normal delegation unless
the Private option is used.
Timers
The Timer package is used to manipulate object event timers. You may have multiple timers in your
program sending an endless stream of messages.
Types:
• One_Shot (sends a message at a specific time)
• Periodic (periodically sends a message)
• Idle (sends message if keyboard is idle for a stated period,
checks for idle keyboard not mouse)
• Timer_Delete (deletes timer & reuses space)
Use Timer
Access Methods
Access methods are special kinds of expressions used to reference objects. The access method is a
function, which returns the object ID.
The Current_Object Access method is the recommended method, but we’ll cover two more just so
you can recognize them in case you must update existing code.
End_Object //Cust_View
...
This command is read: Send Calc_it to Empl_Form child of Payroll_View child of the Desktop
...
// at the top of your code you listed all your Name_Object commands
Name_Object Payroll_View Global
Name_Object Empl_Form child Payroll_View
Name_Object Empl_Comments child Empl_Form
Name_Object Time_Card child Payroll_View
...
Send Calc_It to Empl_Form
The Current_Object access method, like all the other access methods, will return the object ID of
Empl_Form, but unlike the others it starts at the Current_Object and, by way of delegation, will ask
each object if it has a child called Empl_Form.
Would the examples just covered using the Full Access Method and the Name_Object Method still
operate if I add another object around the Empl_Form? ___________________________________
Would the example using the Current_Object Access Method continue to operate if a new object was
added around the Empl_Form and Time_Card_Table? __________________________________
______________________________________________________________________
______________________________________________________________________
End_Object //Cust_View
...
As demonstrated above the current_object access method has benefits. It allow us to make
modifications to our code without making modification to our access method (both the full-access
method and the name_object requires modifications). It also will allow us to send messages to sibling
objects. It however will not allow us to send a message to nested objects of a sibling object or to a
grandchild object. This may sound like a bad thing at first, but in reality it is enforcing encapsulation.
Which is a good thing! We should not be sending messages to these encapsulated objects (only to
sibling objects, our children objects, or objects in our delegation path).
Parent
Messages should NOT flow Child
in these paths
Grandchild
Sibling
Like all great rules there are occasions when this rule must be broken. When this happens we ask the
parent object to ask it’s child to ask the grandchild to do something. This isn’t as bad as it sounds!
Example:
In our example the grandchild is an edit object displaying a large text field. If the parent object wanted
the grandchild to jump to the top of the text field the Beginning of Data message would be sent to the
grandchild.
Object Parent
...
Send Update_Your_Child to (Child(current_Object))
...
Object Child
...
Procedure Update_Your_Child
Send Beginning_of_Data to (Grandchild(current_object))
End_Procedure
Object Grandchild
....
End_Object
End_Object
End_Object
Lesson 5 Lab:
Description:
In this lab we’ll practice adding procedures. In the Journal View, the transaction table was added to
allow the users to see the transactions made to a General Ledger account. Since this object is for
viewing only, we need to change the behavior of the Save_Row and Delete_Row messages. Then, in
the Ledger View, we will also change the behavior of the F5 (clear) key when in the table. In
TYPE.VW we’ll add the procedures that we covered in the lesson. Since we do not have any
transaction records at this time, we will only be able to test our TypeEnt view.
Tasks:
Ledger Modifications:
• Open the Ledger View in an Editor
• The Request_Delete procedure in the GL_Accounts_EF will correct the problem that we
pointed out in Lesson 3. This is a good programming technique that all OOP programmers
should follow.
• Make the modifications as shown. The property that you are setting will stop the cursor from
entering a blank row below the last entry in the table.
Procedure Request_Delete
Local integer OldState This will stop the clearing on
Get Auto_Clear_DEO_State to OldState
Set Auto_Clear_DEO_State to True saves, but it will also stop it on
Forward Send Request_Delete
Set Auto_Clear_DEO_State to OldState
deletes. This Request_Delete
End_Proceudre will correction this problem.
Item_List
Entry_Item GL_ACCTS.GL# { AutoClear, AutoFind, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item TYPE.CODE { AutoFind, Capslock, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.GL_DESCRIPTION { AutoClear, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.CURRENT_BALANCE { AutoClear, ;
IPrompt=(GL_List_SL(Current_object)) }
End_Item_List
...
...
Procedure Row_Save
Error 300 “No Changes allowed to Transaction Records”
End_Procedure // Save_Row
Procedure Request_Delete
Error 300 “No Deletions allowed to Transaction Records”
End_Procedure // Delete_Row
Begin_Row
• Save / Compile Mainprog.SRC (we’ll test this in another lesson as soon as we add transaction
records)
Note: An easier method of stopping the saving and deleting of records within an object is
accomplished by setting the Table’s Read_Only_State to True.
Journal Modifications:
Procedure Request_Clear
Send Request_Clear_All
End_Procedure
• We are
(augmenting/overriding/canceling/adding) the Request_Clear message.
• Save /Compile Mainprog.SRC (we’ll test this in another lesson as soon as we add transaction
records)
TypeEnt Modifications:
• Within the TYPE_EF (right below the Set Location property) type the
Augment/Cancel/Override and Adding procedures that were covered in this lesson. The new
“Adding” procedure will have to be changed in order to operate. If you want to be creative you
may modify any or all these procedures.
5 - 2. If within an Entry_Form Object the Request_Clear is canceled, how will this affect saves?
5 - 3. When Adding a message you have to do one extra step that is not normally needed when
Overriding, Augmenting, or Canceling a message
End_Object // MyTable
L esso n 6
Procedures
Functions and
Properties
This lesson covers Procedures and Functions, also referred to as message handles. It shows how to
pass arguments along with a message handler and how to return a value. Properties are also explored,
showing how to get and set their values.
• Properties
• Procedures
• Functions
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Properties are attributes of an Object or Item that can be set or retrieved. You can think of properties
as a variable that contains a value that the object needs.
Procedure Do_enter
Set Object_Color to 112 112 // set object color to gray/black letters
End_procedure
Procedure Do_Exit
Set Object_Color to 31 31 // set object color to blue/white letters
End_procedure
...
End_Object // My_Form
Procedure pay_raise
Local Number old_pay new_pay
Get value item 1 to old_pay
Calc (old_pay * 1.10) to new_pay
Set value item 2 to new_pay
Set Item_Changed_State item 2 to True
End_procedure
Entry options are added after an entry_item and are listed in {} braces. If more then one option is listed
they are separated with a comma.
These entry options give us the ability to send a message at the item level.
Syntax: { ientry=msg_procedure_name }
{ iexit=get_function_name }
/Empl_Image
┌────────────────────────────────────────┐
│ Employee# ___. │
│ Name ______________________________ │
│ Number of Dependents _. │
│ Date of Birth __/__/__ │
│ Age ___. │
│ Wage ______.__ │
└────────────────────────────────────────┘
/*
Object Empl_EF is an Entry_Form Empl_Image Using (EMPL_DS(Current_Object))
Set Location to 5 10 Relative
Item_List
Entry_Item EMPL.EMPL# { AutoClear, AutoFind }
Entry_Item EMPL.NAME { AutoClear }
Entry_Item EMPL.DEP# { AutoClear, Ientry=msg_Default_Dep }
Entry_Item EMPL.DATE_BIRTH { AutoClear, Iexit=msg_Calc_Age }
Entry_Item EMPL.AGE { AutoClear, Ivalidate=get_Check_Age }
Entry_Item EMPL.WAGE { AutoClear }
End_Item_List
End_Object // Empl_EF
End_Object // EMPL_View
Procedures
Procedures and Functions are very similar. The main difference is that a Function will always return a
value (procedures can return a value). Procedures also have a “set” option that allows a property to be
set at the same time the procedure is called.
Syntax:
Procedure {set} procedure_name {for class} {type1 arg1 ... ... typeN argN}
{forward send procedure_name arg1 ... argN}
: // statements to perform when this procedure is executed
End_Procedure
Procedure Authorize
If user_ID EQ "SUPERVISOR" send Activate to System_EF
End_Procedure
...
Functions
Syntax:
Function function_name {for class} {type1 arg1 ... ... typeN argN} returns return_type
Local variable_type name ...
{forward get function_name arg1 ... argN to value}
: // statements to perform when this function is called
Function_return value
End_Function
Sample:
Register_Function Wage_Increase // if using a function
// procedure or object
// before it is declared
...
Get Wage_Increase Empl.Wage to Wage_Incr
...
Function Wage_Increase Number Wage Returns Number
Local Integer After_Raise
Calc ( Wage * 1.10 ) to After_Raise
Funtion_Return After_Raise
End_Funtion
Note: (prior DataFlex Users) Many of your Macro commands can be easily converted into
Functions.
The property, procedure, and function charts in the Reference manual have lines shaded. This shading
indicates if the property, procedure, or function is Public, Protected or Private.
Public messages are the most commonly used messages and are intended to be sent or altered in
typical programs
Protected messages are available for special uses, but not likely to be sent or altered in typical
programs
Private messages are used by the class internally to accomplish a goal. They are not meant to be sent
nor intercepted!
Lesson 6 Lab:
Description:
Practice using procedures, functions & properties
Tasks:
• The function long_year will accept a date argument. If the year is only two digits, it will
convert it to a four digit year. This function will be used in another lab, but for now fill in the
blanks. This function requires you to pass a date argument that will be stored in a variable
called In_Date, and it will return a date argument.
With relationships it is extremely important never to allow a child record to be saved without a parent
record (creating orphan records). Here we augment the procedure Activate. The Journal view is
dealing with a table, in which it is handled more eloquently, and explained in detail.
• Open the Ledger view in an editor and set the following properties.
...
Object GL_Accounts_EF is an Entry_Form GL_Accounts_EF_Image Using (GL_ACCTS_DS(Current_Object))
Item_List
Entry_Item GL_ACCTS.GL# { AutoClear, AutoFind, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item TYPE.CODE { AutoFind, Capslock, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.GL_DESCRIPTION { AutoClear, ;
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.CURRENT_BALANCE { AutoClear, ;
IPrompt=(GL_List_SL(Current_object)) }
End_Item_List
...
As you enter the test data, experiment with the Save, Clear and Delete operations and fill in the
remainder of the table. The save portion of the table is filled in for you. “Saves propagate up” this
means that I must save the child while in the child DEO and then the parent will also be saved, but if I
save in the parent DEO then only the parent will be saved.
Remember we have set the Auto_Clear_DEO_State to False on both GL_Accounts_EF and the
Yearly_Summary_EF, this is so you can experiment with saves and clears and see how they operate
when dealing with multiple files.
Test Data:
CURRENT 1996 BUDGET
GL# TYPE DESCRIPTION BALANCE MEMO JAN - DEC
410 I Wages 0 2500
420 I Misc. Income 0 50
430 I Part Time Computer Income 0 200
510 E Misc. Expenses 0 200
515 E Groceries 0 350
520 E Entertainment 0 250
530 E Clothes/Laundry 0 100
535 E Household Expenses 0 100
540 E Pet Expenses 0 100
550 E Auto Expense 0 250
555 E Monthly Exp.(phone/util/cable) 0 300
560 E Computer Expense 0 100
580 E Mortgage Interest Expense 0 500
We would not want the user to enter the table without having a Tran_Hdr record. This would allow
detail records to be saved to a blank header (GIGO, garbage-in garbage-out). We need to prevent this
from happening.
We know we must have the header record saved before allowing entry into the table. We want it to do
the right thing no matter what situation might occur, but we need to determine what the right thing is!
1. If the header is new, just automatically save it
2. If the header is edited, just automatically save it
3. If the header is blank, - disallow entry into table
4. If the header failed to save, - disallow entry into table
...
Object Header_EF is an Entry_Form Header_EF_Image Using (Tran_Hdr_DS(Current_Object))
Item_List
Entry_Item TRAN_HDR.TRANS# { AutoClear, AutoFind }
Entry_Item TRAN_HDR.DATE { AutoClear }
Entry_Item TRAN_HDR.EXPLANATION { AutoClear }
End_Item_List
End_Object // Header_EF
// Called when entering the table. Checks with the header to see
// if it is saved. If not, disallow entry
//
Function Child_Entering
Local integer rVal
Get Save_Header of (Header_EF(current_object)) to rVal
Function_Return rVal
End_Function
// Properties you might need to set. These reverse the default settings.
// Remove what you do not need.
Procedure Request_Clear
Send Request_Clear_All
End_Procedure
Begin_Row
Entry_Item GL_ACCTS.GL# { AutoClear }
Entry_Item GL_ACCTS.GL_DESCRIPTION { AutoClear, NoEnter }
Entry_Item Tran_Dtl.DC { AutoClear, Capslock }
Entry_Item Tran_Dtl.AMOUNT { AutoClear }
End_Row
End_Object // Detail_TBL
...
• Save/Compile Mainprog.SRC/Test
Total Debit & Credit fields will be updated in the Lesson on Data_Set Classes.
L esso n 7
Image
Manipulation
This lesson covers item (window) manipulation. We will be looking at multiple ways to address an
item window, and also how to change the default navigational flow between windows.
• Images Zero-Based
• Item# Reference
• Entry_Name_Item Reference
• Defaulting Current_Item
• Entry_Default
• Sub_Page
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Images Zero-Based
There are times when a programmer must address an item window. Since there are numerous ways to
do this, let’s look at a few of them to see the advantages and pitfalls among them.
Items are zero based, meaning that the first item in an image is item 0, numbering the remaining
windows from left to right and from top to bottom.
____0___ ___1____
____5___
____6____
Payroll Example 1:
Use Allentry
Open Payroll
/Payroll_Screen
=====================================
=====================================
/*
Procedure Calc_Pay
Local Number Hours Rate Pay
Get value Item 0 to Hours
Get value Item 1 to Rate
Calc ( Hours * Rate ) to Pay
Set Value Item 2 to Pay // see note for short-cut
Set Item_Changed_State Item 2 to True
End_Procedure
End_Object
Note: Changed_Value will set the value & toggle the item_changed_state to true.
E.g., Set Changed_Value Item 2 to Pay
Item# Reference
When using any of our Ientry, Iexit, Ivalidate entry options, the current item number is always passed
as an argument along with the message. We can retrieve it if desired, by simply declaring a local
variable (type = integer) on the procedure command line. This can be a big benefit over hard coding an
item number that would have to be changed every time we added another item to our image.
Payroll Example 2:
...
/Payroll_Screen
=====================================
Employee Number ______
=====================================
/*
Item_List
Entry_Item Payroll.Empl_Number
Entry_Item Payroll.Hours
Entry_Item Payroll.Rate
Entry_Item Payroll.Pay { ientry=msg_Calc_Pay }
End_Item_List
End_Object
Entry_Name_Item Reference
We can create variables to reference the item numbers by using the entry_name_item. This makes your
code more readable. The standard for naming these variables is to end them with double pound
symbols (##).
Payroll Example 3:
...
/Payroll_Screen
=====================================
Employee Number ______
=====================================
/*
Item_List
Entry_Item payroll.Empl_Number
Entry_Name_Item Hours## Payroll.Hours
Entry_Name_Item Rate## Payroll.Rate
Entry_Name_Item Pay## Payroll.Pay { ientry=msg_Calc_Pay }
End_Item_List
Procedure Calc_Pay
Local Number Hours Rate Pay
Get Value Item hours## to Hours
Get Value Item rate## to Rate
Calc ( Hours * Rate ) to Pay
Set Value Item pay## to Pay
Set Item_Changed_State Item Pay## to True
End_Procedure
End_Object
Note: (for DataFlex procedural programmers) This is similar to the Name command
Defaulting Current_Item
The item reference can be left blank and it will default to the current item, which is very helpful in
some cases, allowing us to send the same message from multiple items.
Object Order_Header is an Entry_Form
...
Item_List
Entry_Item Order.Number
Entry_Item Order.Order_Date { ientry=msg_default_date }
Entry_Item Order.Cust_no
Entry_Item Order.Delivery_Date { ientry=msg_default_date }
...
End_Item_List
Procedure Default_Date
Local Date Input_Date
Get Value to Input_Date // will default to current_item
If Input_Date EQ "" Begin
Sysdate Input_Date
Set Value to Input_Date // will default to current_item
Set Item_Changed_State to True // will default to current_item
End
End_Procedure
End_Object
Both item reference and current object can be left blank and it will default to the current item and
current object. There are times in which we must reference an item outside the current object.
Object Order_Header is an Entry_Form
...
Item_List
Entry_Item Order.Number
Entry_Item Order.Order_Date { ientry=msg_default_date }
Entry_Item Order.Cust_no
...
End_Item_List
End_Object
Procedure Default_Date
Local Date Input_Date
Get Value of (Order_Header(current_object)) item 1 to Input_Date
If Input_Date EQ "" Begin
Sysdate Input_Date
Set Value of (Order_Header(current_object)) item 1 to Input_Date
Set Item_Changed_State of (Order_Header(current_object)) item 1 to True
End
End_Procedure
Payroll Example:
use allentry
open payroll
...
/payroll_screen
=====================================
Hours * Rate = Pay
___.__ ___.__ ______.__
___.__ ___.__ ______.__
___.__ ___.__ ______.__
___.__ ___.__ ______.__
___.__ ___.__ ______.__
=====================================
/*
Procedure Calc_Pay
local number hours rate pay
local integer BI
get base_item to BI
get value item (BI + 0) to hours
get value item (BI + 1) to rate
calc ( hours * rate ) to pay
set changed_value item (BI + 2) to pay
End_Procedure
End_Object
Entry_Defaults Procedure
Entry_Defaults Procedure is another method of setting default values in DEOs. The entry_default
message is sent during the clear. This is a “hook” message and does nothing by default.
The following two examples will compare the Ientry entry option and Entry_Defaults procedure.
Procedure Default_Date
Local Integer BI
Local Date Input_Date
Get Base_Item to BI
Get Value Item (BI + 0) to Input_Date
If Input_Date EQ "" Begin
Sysdate Input_Date
Set Changed_Value Item (BI +0) to Input_Date
End
End_Procedure
Procedure Calc_Pay
Local Number Hours Rate Pay
Local Integer BI
Get Base_Item to BI
Get Value Item (BI + 0) to Hours
Get Value Item (BI + 1) to Rate
Calc ( Hours * Rate ) to Pay
Set Changed_Value Item (BI + 2) to Pay
End_Procedure
End_Object
When using this code you will notice some negative results that are not present with Entry_Defaults
• Just cursoring in & out of a blank row will create a record with only the date.
• If you use the mouse to jump into the second column, the Ientry default is not called.
Use Allentry
Open Payroll
...
/Payroll_Screen
=============================================
Date Empl# Hours * Rate = Pay
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
=============================================
/*
Procedure Entry_Defaults
Local Date Input_Date
Local Integer BI
Get Base_Item to BI
Sysdate Input_Date
Set Changed_Value Item (BI + 0) to Input_Date
End_Procedure
Procedure Calc_Pay
Local Number Hours Rate Pay
Local Integer BI
Get Base_Item to BI
Get Value Item (BI + 0) to Hours
Get Value Item (BI + 1) to Rate
Calc ( Hours * Rate ) to Pay
Set Changed_Value Item (BI + 2) to Pay
End_Procedure
End_Object
Note: The Entry_Defaults procedure demonstrates the importance of Base_Item, since we can no
longer pass the current_item as an argument.
Sub_Page
Sub_Page has been included so you are aware that it exists, but it is suggested that you try to avoid
using it. Your code will be easier to convert to a Windows application if this command is not used.
You can obtain the same results by creating multiple objects.
Normal navigation is from left to right and from top to bottom, as indicated by the numbers.
/Customer_Image
=============================================
Name 1 ______ Phone 2 _______
Address 3 ______
City 4 ______ Fax 5 _______
State 6 ____
============================================
/*
Item_List
entry_item customer.name
entry_item customer.phone
entry_item customer.address
entry_item customer.city
entry_item customer.fax
entry_item customer.state
End_Item_List
End_Object
If I wish my navigation to flow differently, as indicated by the letters, the sub_page command will
allow this.
Since we cannot set properties (location or color) of a sub_page image, we solve this by adding a client
around the object that will display the correct image and set the image properties.
/Customer
============================================
Name 1 __a___ Phone 2 ___e___
Address 3 __b___
City 4 __c___ Fax 5 ___f___
State 6 __d_
============================================
/*
Item_List
entry_item customer.name
entry_item customer.address
entry_item customer.city
entry_item customer.state
entry_item customer.phone // notice order of
entry_item customer.fax // fields have changed
End_Item_List
End_Object
End_Object
Sometimes it is easier to leave an image together instead of breaking it apart and setting the location of
all the parts. Three different objects may use the same image by using the Sub_Page command to
divide up the image easily. Again a client (container) object is used to set the location and color of the
image.
/Big_Image
================================================
1___ 2____________ 3___ 4______ 5____
6________
7________
8________
9________
10________
================================================
/*
//**************** fill in the blanks below **************************
End_Object
Note: When using Vertical and Rectangular options, all column items must start in the same
position.
Lesson 7 Lab:
Description:
Modify Journal View by adding entry options to default and verify data entry. In this exercise not all of
the modifications are shown. Try to create these procedures and functions as far as possible, before
using the samples in Appendix A.
We’ll also make sure that the Transaction header date is not changed. This will be accomplished by
toggling the entry options.
Tasks:
• We never want the user to find an existing record and change the Transaction Number. To
guard against this, we’ll use the VLD_Key package.
//********************************************************************************
// JOURNAL
//
// Author : Student's Name
// Originally created : 03/03/96
// Last Update : 03/03/96
//
//********************************************************************************
Use ALLENTRY
Use CONFIRM
Use VLD_KEY // support package with extra auto-prompting features
...
...
Item_List
Entry_Item TRAN_HDR.TRANS# { AutoClear, AutoFind, ;
iValidate=get_validate_key_field }
Entry_Item TRAN_HDR.DATE { AutoClear }
Entry_Item TRAN_HDR.EXPLAINATION { AutoClear }
End_Item_List
• Since most of the time the transaction date will be today’s date, let’s default the date into this
window (if it is blank). Don’t forget to add the Ientry option! The procedure is not complete,
see if you can complete it before looking up the answer in Appendix A.
//********************************************************************************
// JOURNAL
//
// Author : Student's Name
// Originally created : 03/03/96
// Last Update : 03/03/96
//
//********************************************************************************
Use ALLENTRY
Use CONFIRM
Use VLD_KEY // support package with extra auto-prompting features
...
...
Item_List
Entry_Item TRAN_HDR.TRANS# { AutoClear, AutoFind, ;
iValidate=get_validate_key_field }
Entry_Item TRAN_HDR.DATE { AutoClear; Ientry=msg_Default_Date }
Entry_Item TRAN_HDR.EXPLAINATION { AutoClear }
End_Item_List
Note: The procedure was inserted above the ientry option. Forward Reference Compiler Error can
be caused by referencing an Object, Procedure, or Function before it is created. The Register
commands can solve these compiler Errors. See the following commands; Register_Object;
Register_Procedure; Register_Funtions.
We do not want the user to add any dates with a 2 digit year. We’ll guard against this with the
Ck_Year procedure. This procedure use the Long_Year function that was created in Lab 6. We
are making this a two step process because Iexits only pass the current item number, so we’ll
pass the date as an argument of the Long_Year function.
• Save/Compile/ &Test
//********************************************************************************
// JOURNAL
//
// Author : Student's Name
// Originally created : 03/03/96
// Last Update : 03/03/96
//
//********************************************************************************
Use ALLENTRY
Use CONFIRM
Use VLD_KEY // support package with extra auto-prompting features
...
...
Item_List
Entry_Item TRAN_HDR.TRANS# { AutoClear, AutoFind, ;
iValidate=get_validate_key_field }
Entry_Item TRAN_HDR.DATE AutoClear, Ientry=msg_Default_Date, Iexit=msg_Ck_Year }
Entry_Item TRAN_HDR.EXPLANATION { AutoClear }
End_Item_List
...
We need to enter the Tran_Hdr.Date window when creating a new record but we do not want the user
in this window any other time. We need to toggle the entry options for this item. The Refresh
message is a very important message. It will be called on finds and clears.
...
Object Header_EF is an Entry_Form Header_EF_Image;
Using (Tran_HDR_DS(current_object))
...
End_Object // Header_EF
...
Note: The use of the Procedure Set, in the code above could have just as easily been incorporated in
the Procedure Refresh. The use of the procedure set was only for demo purposes.
L esso n 8
Using Predefined
Classes
This lesson covers creating objects outside DFAuto. There are many predefined objects to choose from
and sometimes it is a matter of shopping for the one that meets your needs best. But you must be
aware of what is available!
• Creating Buttons
• Activate_View Command
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
The Item_List / End_Item_List structure is used by many different classes. There are two types of
items that can be listed within this structure. They are Entry items and Standard items (on_items).
Item_List Item_List
entry_item Payroll.Empl# {AutoFind} on_item "Save" send Request_Save
entry_item Payroll.Name {CapsLock} on_item "Delete" send Request_Delete
End_Item_List End_Item_List
Format:
Creating Buttons
Buttons are another method of triggering a message, giving the user visual clues to available options.
The button object below is nested within an Entry_Form object, therefore the messages will be
delegated to the correct object. Fill in the 8 blanks so we have 3 buttons, a Save, a Delete and a
Print_Label button.
/Button_Image
__________ ________________ ___________________
/*
Item_List
// What to Display: What to Send:
On_Item ___________________ ______________________
On_Item ___________________ ______________________
On_Item ___________________ ______________________
End_Item_List
Procedure Print_Label
...
End_Procedure
End_Object
Note: The default appearance of the checkbox and radios can be changed by running DFRun
DFConfig.
Many times it is better to create a small test program when using a class for the first time, in order to
experiment with the properties, procedures and functions. This will give you a better understanding of
the class before including it into a large program.
To do this we look up the class in our online help and under the usage section it will describe the
requirements to make an object functional.
/Marital_Status
Since this is a predefined class we Use UI.
_____________ Many classes will have a .PKG file.
_____________
_____________ E.g., Entry_Form would Use EntryFrm
_____________
/*
// Note the image window requires the addition of three extra underscores for the Radio
integer sin mar div wid //create & initialize 4 global variables
move 0 to sin
move 0 to mar
move 0 to div
move 0 to wid
Procedure Process_Status
Local Integer item#
Get Current_Item to item#
If item# EQ 0 increment sin // OR if we wanted to check the Select_State
If item# EQ 1 increment mar // these If statements would be changed like this:
If item# EQ 2 increment div // If (Select_State(current_object, 0))increment div
If item# EQ 3 increment wid
Gotoxy 24 0
Show "Single = " sin " Married= " mar " Divorced= " div " Widowed= " win
End_Procedure
End_Object
If we have a background we do not need
the Clearscreen command. The Start_UI
Clearscreen
Start_UI (Marital_Status(current_object)) starts the user interface and gives the focus
to the object Marital_Status
Note: The “Process_Status” is not sent when you select with the space bar, but when you exit the
item by pressing return.
There are also the Checkbox_Item_State and Radio_State properties, which can be set in numerous
classes at the item level.
Example:
/Employ_Ins
┌─────────────────────────────────────┐
│ Employee Number __ │
│ Name ________________________ │
│ │
│ Health Ins? ___ │
│ Dental Ins? ___ │
│ │
└─────────────────────────────────────┘
/*
Object Employ_Ins is an Entry_Form
Set Select_Mode to Multi_Select
Item_List
Entry_Item Employ.Number
Entry_Item Employ.Name
Entry_Item Employ.Health
Set Checkbox_Item_State to True
Set Entry_State to False
entry_item Employ.Dental
Set Checkbox_Item_State to True
Set Entry_State to False
End_Item_List
End_Object
When stored to a database, both Checkboxes and Radios are stored as an ASCII field.
______________ if selected
______________ if not selected
Warning: If you are canceling and overriding a lot of messages in an object . . . maybe you are
using the wrong class!
Message Example:
Use UI
/My_Message
┌─────────────────────────────────┐
│ │
│ ___________________________ │
│ │
└─────────────────────────────────┘
/*
Form Example:
Use UI
/Which_Dept
┌────────────────────────────────────────┐
│ │
│ Print Labels for which Dept? ____ │
│ │
└────────────────────────────────────────┘
/*
Procedure Print_Label
local string dept_code
get value item 0 to dept_code
chain wait LabelRpt dept_code
send refresh_screen
End_Procedure
End_Object
Within DFAuto, if we select Object | New | Prompt from the pull-downs, we are not creating an object
from the prompt class. There is no prompt class! The code generated will build an object from the
Selection_List Class. Here are some general grouping terms for classes.
Popup Objects are designed to be activated only when requested by the user.
Two popup examples are:
Zoom Objects are popups that are activated by the izoom key, Alt+F9.
DFAuto uses the Entry_Form class to build Zooms,
normally used from a table to display the rest of the fields.
Prompt Objects are popups that are activated by the iprompt key, F4.
Two prompt examples are:
Note: Popup is a property that can be set in many classes. This means many classes can act like a
popup.
______________________________
______________________________
______________________________
______________________________
____________________
End_Object
Activate_View Command
Question: How can we “Send Activate_Employee to Desktop” when we did not code a procedure
Activate_Employee at the Desktop?
//MainProg.SRC
...
Create_Menu
On_Item
On_Item "Employee View Alt+1" Send Activate_Employee to Desktop
...
Answer: The Activate_View Command creates a procedure for us and places it at the desktop. Our
pull-downs from MainProg.SRC or Test.SRC will locate these special procedures created especially to
activate views from the desktop
The Activate_View command is a special command that can be confusing at first. The diagram below
shows all the parts of this command.
//MainProg.SRC File
...
Create_Menu
On_Item
On_Item "Ledger View" Send Activate_Ledger to Desktop
...
Procedure to Build
Use Ledger.VW Must be the same in both locations
// Ledger.VW File
...
Activate_View Activate_Ledger for Ledger_View
View to Activate
Must be the same in
both of these locations.
Object Ledger_View is an Entry_View_Client
...
Lesson 8 Lab:
Description:
Change the code in Type.SL file from a Selection_List to a Pick_List and use the new Pick_List in the
Ledger view. Also we will be modifying the Ledger to calculate the Differ column (Budget from
Actual monthly figures ).
Tasks:
• With an editor change the Type.SL from a Selection List to a Pick List, save it as Type.PL.
Open Type.SL and make modify to look like code below.
//********************************************************************************
// Pick List Definition for TYPE
//
// Author : Student's Name
// Originally created : 03/13/96
// Last Update :
//
//********************************************************************************
Use ALLENTRY
Use PickLIST
//Open TYPE
/GLTYPE_PL_image
╔══════════════════════════╗
║ GLTYPE ║
╠══════════════════════════╣
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
╚══════════════════════════╝
/*
Set Location to 11 27
Set Auto_Locate_State to TRUE // locate automatically
Set Export_Item_State to TRUE // If non-related lists.
Set Select_Mode to Auto_Select
Item_List
On_Item "Assets"
On_Item "Liabilities"
On_Item "Capital"
On_Item "Income"
On_Item "Expenses"
End_Item_List
End_Object // GLTYPE_PL
• Save as Type.PL
• Open the Ledger Views and make the following changes to use our new pick_list when on the
GL_Accts.Type window.
• Modify window:
Entry_Item GL_Accts.Type {iprompt=(GL_Type_PL(current_object))}
• We will no longer be using the Type file, so go into DFFILE and clear the relationship from the
GL_ACCT file to Type file.
At the start of the lesson we learned that entry_items do not have to be file.fields. They can be
expressions. We will insert an expression in the Ledger view to calculate the difference between
budget and actual figures.
• Add the modifications shown and also create the Calc_Diff procedure.
...
/Yearly_Summary_EF_Image
┌─ Yearly Summary: ────────────────────┐
│ ___. Budget: Actual: Differ: │
├──────────────────────────────────────┤
│ Jan ______.__ ______.__ ______.__ │
│ Feb ______.__ ______.__ ______.__ │
│ Mar ______.__ ______.__ ______.__ │
│ Apr ______.__ ______.__ ______.__ │
│ May ______.__ ______.__ ______.__ │
│ Jun ______.__ ______.__ ______.__ │
│ Jul ______.__ ______.__ ______.__ │
│ Aug ______.__ ______.__ ______.__ │
│ Sep ______.__ ______.__ ______.__ │
│ Oct ______.__ ______.__ ______.__ │
│ Nov ______.__ ______.__ ______.__ │
│ Dec ______.__ ______.__ ______.__ │
└──────────────────────────────────────┘
...
Item_List
Entry_Item YR_HIST.YEAR { AutoClear, AutoFind }
Entry_Item YR_HIST.BUDGET_01 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_01 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_01 - YR_HIST.ACTUAL_01) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_02 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_02 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_02 - YR_HIST.ACTUAL_02) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_03 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_03 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_03 - YR_HIST.ACTUAL_03) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_04 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_04 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_04 - YR_HIST.ACTUAL_04) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_05 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_05 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_05 - YR_HIST.ACTUAL_05) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_06 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_06 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_06 - YR_HIST.ACTUAL_06) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_07 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_07 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_07 - YR_HIST.ACTUAL_07) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_08 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_08 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_08 - YR_HIST.ACTUAL_08) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_09 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_09 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_09 - YR_HIST.ACTUAL_09) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_10 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_10 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_10 - YR_HIST.ACTUAL_10) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_11 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_11 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_11 - YR_HIST.ACTUAL_11) { DisplayOnly }
Entry_Item YR_HIST.BUDGET_12 { AutoClear, iexit=msg_calc_diff }
Entry_Item YR_HIST.ACTUAL_12 { DisplayOnly }
Entry_Item (YR_HIST.BUDGET_12 - YR_HIST.ACTUAL_12) { DisplayOnly }
End_Item_List
• Save/ Compile / and Test (the actual column will start to fill after the next few lessons)
8 - 3. Look up the property Checkbox_Item_State in the Reference Manual and discover the Defining
Class(es).
L esso n 9
Data Set Objects
This lesson covers Data Set Objects and their Procedures and Functions. In the next lesson we will
create a subclass from the Data_Set Class for file. Many of the items that we learn here are added to
the subclass instead of inserting them in the Object.
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Data_Set Objects
Data Sets provide database services to Data Entry Objects (DEOs). When we create a Data Set
structure we create a powerful tool.
In a prior lesson we saw that the data_set structure mimicked the file relationship structure. The BIG
difference is the flow between these two structures.
Employ
Employ
These procedures are always called in a locked state. Therefore so it is safe to access the record
buffers.
Normally
Mirror Images
of each other
Note: Outside a lock state reference item windows. Inside a lock state reference file.field buffers,
and never code for user intervention.
Procedure Creating Creating is only called if saving a New Record. Sample usage may be for the
automatic assignment of numbers.
Procedure Creating
Forward Send Creating
Add 1 to SysFile.Employee_Number
Move SysFile.Employee_Number to Empl.Employee_Number
SaveRecord SysFile
End_Procedure
Note: (prior DataFlex 3.1 Object Oriented Programmers) The destroying procedure is obsolete,
with the new transaction processing feature.
Procedure Update & Backout Update is called during a new save and Backout is called during a
delete. Both procedures are called during an edit save. These procedures can be used to maintain
running totals. Typically the code will be mirror images of each other. Update adding to the running
total and Backout subtracting from the total.
Procedure Update
Forward Send Update
Add Timecard.Pay to Empl.YTD_Pay
End_Procedure
Procedure Backout
Forward Send Backout
Sub Timecard.Pay from Empl.YTD_Pay
End_Procedure
To fully understand how these two procedures work so harmoniously together during an edit save, we
must remember that both are called during the same locked state and that Entry_Update (which moves
the data from the image to the record buffer) is called between these two procedures.
STEPS:
• ReRead Locks files and Refreshes the buffer
• Backout Subtracting the original timecard amount from the running total
(this is like deleting out the edited record)
• Entry_Update Moves the data from the windows to the buffer
• Update Adds new timecard amount in the running total
These functions are intended to check for possible data-integrity violations. Return a zero if
saving/deletion is allowed, else return non-zero or generate an error to prevent the operation.
// Will give an error if the inventory is not sufficient to cover the order.
// This function would normally go inside the Order detail Data Set
// before deleting employee record, check if needed for end of year taxes via an active field
// To save an unrelated file(s) such as a system file when the main_file is saved.
Procedure Save_Main_File
SaveRecord SysFile
Forward Send Save_Main_File
End_Procedure
// before deleting an employee record, save part of the data to a history file
Procedure Delete_Main_File
// clear, move the fields into the history file & save
clear Hist
Move Employ.ID to Hist.ID
Move Employ.Name to Hist.Name
...
SaveRecord Hist
Forward Send Delete_Main_File
End_Procedure
Lesson 9 Lab:
Description:
Fine tune the DSO and start thinking about the business rules that we will add in the next lesson at the
class level. We’ll also create a System file (SysFile) that we will use in the next lesson.
Tasks:
Constraint Blocks are only added when required in a view. Since they are not always required, they are
added when needed in the Data_Set Object not in the class.
Ledger View
GL_Accts Tran_Hdr
Relate Relate
Constraint Constraint
Yr_Hist Tran_Dtl
Journal View
GL_Accts Tran_Hdr
Relate Relate
Constraint Constraint
Yr_Hist Tran_Dtl
The Yr_Hist record has an unusual field, the Year field. When we are in the Ledger view, we would
want to enter the year field when creating a new field, but when in the Journal view, the Yr_Hist record
is used to maintain monthly running totals as the transactions are saved. If the Yr_Hist record is not
found, then one is created with the year field filled in from the Tran_Hdr.Date field.
Since the Journal view will need a special Creating procedure that is not required in the Ledger view,
we will create this procedure in the Yr_Hist object, not the class. We’ll be modifying the DS classes in
the next lesson.
...
Object TRAN_DTL_DS is a TRAN_DTL_Data_Set No_Image ;
Updating (TRAN_HDR_DS(Current_Object)) (GL_ACCTS_DS(Current_Object))
set constrain_file to tran_hdr.file_number
End_Object // TRAN_DTL_DS
Procedure Creating
Forward Send Creating
Move(Mid(Tran_Hdr.Date, 4, 7)) to Yr_Hist.Year
End_Procedure
End_Object // YR_HIST_DS
...
We’ll need a System File in the next lesson in order to assign Transaction Numbers. The SysFile.DEF
is located in your OOP_Class sub-directory.
• Business Rules for our files. Without coding, simply jot down ideas (rules that would
require the use of Creating/Update/Backout/Deleting procedures) that must be followed
whenever saving or deleting records in each of the files. Hint: We’ll need to auto assign
numbers and maintain running totals.
GL_ACCT
• Should deletions to this record be allowed if child records exist, (deleting this record and
all child records below it)? __________
TRAN_HDR
• Should deletions to this record be allowed if child records exist, (deleting this record and
all child records below it)? __________
TRAN_DTL
• Creating (new record saves)
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
YR_HIST
• This creating procedure was just completed and added in the Journal view.
9 - 1. If I wished to automatically assign the next available ID number, which procedures would I
augment?
9 - 2. If I was adding / subtracting to Quantity on Hand in the Inventory file whenever an Order was
placed, which procedures would I augment?
L esso n 1 0
Creating New
Classes
This lesson covers the creation of new subclasses. Although many of the examples use the Data Set
class as the superclass it is not the only class that you can build from. It is very beneficial to build your
own private library of classes from the standard DataFlex Classes that come with your Full
Development License. The Lab codes the business rules in one file (ACCTS.DS). Here is where we
will store all the important operations for the files.
• Business Rules
• Class Structure
• Properties (creating)
Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.
Classes are our tools from which we create our objects. If we are modifying an object every time we
use it this indicates that we need to create another class.
The Entry_Form class is a very useful class (tool), but if we find that our users/employee wish the
screen to automatically save the record when leaving the last window – then we need to subclass this
class so this is the normal behavior to the class that we build our objects from.
Use_Allentry
Use Customer.DS
Use EFSave.PKG
ClearScreen
Start_UI (Customer_Form(current_object))
Business Rules
Business Rules are rules that you wish to follow before changes are allowed to the database.
Examples:
• Verify important facts before allowing saves and deletes.
• Do not allow a parent record to be deleted if it has related child records.
• Auto assign a number for all new records being saved.
Since these are things that happen during saves and deletes, we subclass the Data_Set Class and add all
these rules in our new class.
Business Rules are built into the class so they affect ALL views. If the rule should only affect one view
then that rule should NOT be in the class, but in the Data Set Object within the view that it should
affect.
Class structure
Class sub_Class is a{n} Super_Class
End_Class
Application Framework suggests that we subclass the Data_Set class for each file. This allows us to
have one centralized file that holds all the rules required by a file. If all our programs (views) use this
new subclass, then we will have consistent behavior throughout our application. A new business rule
added to the class will affect all views!
The .DS file created by DFAuto has the basic class structure needed and with many of the most used
procedures, functions and properties commented out, this structure allows you to very quickly add the
needed business rules for each of your files.
//********************************************************************************
//
// Data Set Definition for EMPL
//
// Author : T.M. Arnett
// Originally created : 11/09/95
// Last Update : 11/09/95
//
//********************************************************************************
Use ALLENTRY
Open EMPL
// Other Messages:
// Save_Main_file, Delete_Main_File, Clear_main_file are much less
// likely to be used. Remember to forward send them.
End_Class
The Smart_File_Mode_State property attempts to reduce the amount of locking and rereading
performed during Save and Delete operations. This optimization will only work if all Data_Sets
participating in the save or delete operation have this property set to true. When
Smart_FileMode_State is turned on and you manually save/delete a record that is NOT in the data_set
structure (ex: a system file), then you will also need to add the procedure Reset_FileModes_for_Lock
// Procedure Reset_FileModes_for_Lock
// Forward Send Reset_FileModes_for_Lock
// File_Mode SysFile Default // the unrelated file
// End_Procedure
If you try to delete a parent record which has a related child records, this is the error that will be
generated:
Properties (creating)
Syntax
Property type property_name [public | private] initial value
Note: Instead of procedures or functions that pass many arguments – it may be better to create a
new class that has new properties then with the set and get command these properties can be easily
stored and altered, replacing the need of arguments passing.
Many times we have a key field in a file which we don’t want to be able to change. It would be nice if
we could use validate_save to protect against this. The problem is that validate_save is called with the
new data already in place. We have no way of knowing if the key field was changed.
The solution is to:
1. create a property to maintain the old key field value
2. move the value of this field into this property after every find
3. make sure in validate_save that the key field was not changed.
// augmented for customized error messages (errors generated from the DS)
Procedure operation_not_allowed integer err#
If err# EQ 301 error err# "Cannot change a GL number"
Else if err# 4140 error err# "Cannot Delete -Account has child records"
Else Forward Send operation_not_allowed err#
End_Procedure
....
The above example shows how to create a property that will not allow the index field to be changed.
The code for this business rule should be added to the class so it will applied everywhere not just in
one view. This is great but it will not inform the user of a problem until the save operation. Therefore
we also utilize a Vld_Key.PKg that is more user friendly because it is checked during navigation and
pre-saves and because it shows you where the error occurs.
Example:
Use VLD_KEY //support package with extra validation & auto prompting features
...
Lesson 10 Lab:
Description:
Instead of multiple .DS files (one for each file), we have combined them all in one ACC.DS file. If this
was a very large application, in which different combinations of class .DS files were needed in each
view, then it would be beneficial to keep the subclass .DS files separate.
Tasks:
Use ALLENTRY
Open GL_ACCTS
Open YR_HIST
Open TRAN_HDR
Open Tran_DTL
Open SYSFILE
//********************************************************************************
// Data Set Definition for GLACCTS
//********************************************************************************
End_Class
//********************************************************************************
// Data Set Definition for TRAN_HDR
//********************************************************************************
Procedure Creating
Add 1 to SYSFILE.Last_Trans#
Move SYSFILE.Last_Trans# to Tran_Hdr.Trans#
SaveRecord SYSFILE
End_Procedure // Creating
Procedure Reset_Filemodes_for_Lock
Forward Send Reset_Filemodes_for_Lock
File_Mode SYSFILE Default
End_Procedure //Reset_Filemodes_for_Lock
End_Class
//********************************************************************************
// Data Set Definition for TRAN_DTL
//********************************************************************************
Procedure Creating
Forward Send Creating
// assign next detail number
Add 1 to Tran_Hdr.last_detail#
Move Tran_Hdr.last_detail# to Tran_Dtl.Detail#
End_Procedure
Procedure Update
Forward Send Update
// maintain Yr_Hist running monthly total
Move ((Mid(Tran_Hdr.Date, 4, 7)) - 1) to fieldindex
Add Tran_Dtl.Amount to Yr_Hist.Actual_01&
// maintain Tran_Hdr running total
If Tran_Dtl.DC EQ "D" Add Tran_Dtl.Amount to Tran_Hdr.Total_Debits
Else Add Tran_Dtl.Amount to Tran_Hdr.Total_Credits
End_Procedure
Procedure Backout
Forward Send Backout
// maintain Yr_Hist running monthly total
Move ((Mid(Tran_Hdr.Date, 4, 7)) - 1) to fieldindex
sub Tran_Dtl.Amount from Yr_Hist.Actual_01&
// maintain Tran_Hdr running total
If Tran_Dtl.DC EQ "D" Sub Tran_Dtl.Amount from Tran_Hdr.Total_Debits
Else Sub Tran_Dtl.Amount from Tran_Hdr.Total_Credits
End_Procedure
End_Class
//********************************************************************************
// Data Set Definition for YR_HIST
//********************************************************************************
End_Class
Journal Test Data: (donot add Tran#, the system will assign it automatically)
DEBIT/
DATE EXPLANATION GL# CREDIT AMOUNT
04/11/96 Purchased Gas C 15.00
D 15.00
04/12/96 Shopping 105 C 400.00
530 D 50.00
560 D 200.00
550 D 150
04/29/96 Savings Deposit 110 D 150.00
105 C 150.00
Open the Ledger View and verify that the running totals are correct and the Transaction table is filling.
The VLD_Key package was added to the Ledger view. We’ll also want it in the Journal view, to stop
the Transaction Number from being changed.
• Open Journal.VW
10 - 1. If I find I’m constantly changing the behavior of a class, it may mean that I should create a new
class to meet my special needs. Create a new class that would act like an Entry_Form but
would not allow deletions.
10 - 2. If Validate_Save returns a Zero, does this mean the save passed or failed?
Lesson 11
Reporting
This lesson covers the new reporting classes and how to quickly create a report using the updated
DFQuery.
Who could Skip?: Persons proficient in all lesson topics. Although a quick review is suggested.
DFQuery will generate code using the new report classes. This code will be in two files, a .SRC and a
.RPT. This is similar to the idea of the Test.SRC and View.VW files that we have been using.
This code (just as in procedural DFQuery code) can be modified to create breaks giving subheaders and
subtotals on specified fields, variables, window values, expressions, or functions
Database | Query
Database
Figure 125
[ GL_Accts
[ OK
Figure 126
The Print Field Definition View is broken into parts. Tab & Shift+Tab will navigate around the screen,
or use the mouse to jump to the point desired.
Figure 127
Figure 128
DFQuery is written in the DataFlex Language. The Index screen uses a property called Select_Mode,
its value is set to Auto_Select, meaning you simply point to an index and it is selected.
[ GL#
Figure 129
View | Parameters
Figure 130
Figure 131
Run | Screen
Figure 132
Figure 133
File | Generate
Figure 134
Printable report
Rep_COA
[ OK
Figure 135
File | Save as
Figure 136
Chart
[ OK
Figure 137
File | New
File | Open
Figure 138
GL_Accts
[ OK
Figure 139
When we select fields (pressing enter or mouse clicking) from the DBMS Fields Section they are
always inserted at the bottom of the Printed Fields List. If we wish to insert a field in the middle of the
list, here are the steps to take:
• From Printed Fields list, click on the line where you wish a new field inserted
• From DBMS Fields list, click on the field you wish to insert
• Click <Ins=Insert> button
Figure 140
View | Selections
Figure 141
/ GL#
400
[ OK
Figure 142
Figure 143
Figure 144
[ GL#
Figure 145
View | Parameters
Figure 146
Figure 147
Run | Screen
Figure 148
File | Generate
Figure 149
Printable report
Rep_Bal
[ OK
Figure 150
File | New
File | Open
Figure 151
Yr_Hist
[ OK
Figure 152
Figure 153
View | Selections
Yr_Hist.GL#
400
[ OK
Figure 154
Yr_Hist.Year
= (equal)
1996
[ OK
Figure 155
Figure 156
View | Order
GL#, -Year
Figure 157
View | Parameters
Figure 158
File | Generate
Figure 159
Printable report
Rep_Inc
[ OK
Figure 160
File | Exit
Figure 161
Use REP_BAL.rpt
Inherit_Screen
Send Activate_REP_BAL_Report
// REP_BAL.rpt
// 03/06/96 23:08:49
// Balance Sheet Similar to a
//
//
Data Access Corporation
XXX.VW
// Package generated by DFQuery 3.1
Use QryRpt
/REP_BAL_Header
__/__/____ Page ___.
Data Access Corporation
Balance Sheet
/REP_BAL_Subheader1
____________________
/REP_BAL_Body Resident
____. ___________________________________ ____ ______.__
/REP_BAL_Total
/REP_BAL_Selection_Form
Select records by:
GL# less than ___.
/REP_BAL_Selection_Client
╔════════════════════════════════════════════════════════════════════════════╗
║ QC-8 ║
║ Balance Sheet ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*
Report_Index By Index.1
Report_Breaks GL_ACCTS.TYPE
Begin_Constraints
Constrain GL_ACCTS.GL# LT (Constraint_Value(Current_Object,0))
End_Constraints
Note: (prior DataFlex users) this structure is VERY similar to the Report Macro, even the report
breaks and subheader/subtotals.
// REP_COA.rpt
// 03/06/96 22:23:44
// Chart of Accounts
// Data Access Corporation
//
// Package generated by DFQuery 3.1
Use QryRpt
/REP_COA_Header
__/__/____ Page ___.
Data Access Corporation
Chart of Accounts
GL# GL DESCRIPTION
/REP_COA_Body Resident
____. ___________________________________
/REP_COA_Subheader1
____________________
/REP_COA_Total
Records printed = _______.
/*
/REP_COA_Selection_Client
╔════════════════════════════════════════════════════════════════════════════╗
║ Data Access Corporation ║
║ Chart of Accounts ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*
Output_Pagecheck REP_COA_Subheader1
End_Procedure
Remember if you wish to compile this report, Compile Rep_COA.SRC not Rep_COA.Rpt.
• We’ll need a running total of Debits and Credits that we’ll print in the total section
// REP_BAL.rpt
// 03/06/96 23:08:49
// Balance Sheet
// Data Access Corporation
//
// Package generated by DFQuery 3.1
Use QryRpt
/REP_BAL_Header
__/__/____ Page ___.
Data Access Corporation
Balance Sheet
/REP_BAL_Subheader1
____________________
/REP_BAL_Body Resident
____. ___________________________________ ____ ______.__
/REP_BAL_Subtotal1
-----------
________.__
===========
/REP_BAL_Total
Total Debits Total Credits
________.__ ________.__
=========== ===========
/REP_BAL_Selection_Form
Select records by:
GL# less than ___.
/REP_BAL_Selection_Client
╔════════════════════════════════════════════════════════════════════════════╗
║ Data Access Coorporation ║
║ Balance Sheet ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*
Open GL_ACCTS Index.1
Number TDebits TCredits
Begin_Constraints
Constrain GL_ACCTS.GL# LT (Constraint_Value(Current_Object,0))
End_Constraints
• Break on GL_ACCTS.TYPE
// REP_INC.rpt
// 03/06/96 23:04:00
// Income Statement
// Data Access Corporation
//
// Package generated by DFQuery 3.1
Use QryRpt
/REP_INC_Header
__/__/____ Page ___.
Data Access Corporation
Income Statement
/REP_INC_Subheader1
_____________________
/REP_INC_Body Resident
____. ____________________________________ ____ ____. ______.__
/REP_INC_Subtotal1
-----------
________.__
===========
/REP_INC_Total
Total Debits Total Credits
________.__ ________.__
=========== ===========
/REP_INC_Selection_Form
Select records by:
YEAR equal to ___.
GL# greater than or equal to ___.
/REP_INC_Selection_Client
╔════════════════════════════════════════════════════════════════════════════╗
║ QC-8 ║
║ Income Statement ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*
Begin_Constraints
Constrain YR_HIST.YEAR EQ (Constraint_Value(Current_Object,0))
Constrain YR_HIST.GL# GE (Constraint_Value(Current_Object,1))
End_Constraints
Lesson 11 Lab:
Description:
The three reports were created in the lesson, all we’ll need to do is create a new Report pull-down.
Tasks:
• Open the Mainprog.SRC in an editor
//----------------------------------------------------------------------
// Mainprog.Src: Personal Accounting System
//
//
//----------------------------------------------------------------------
Use AllEntry
Use ExitApp // Smarter exit. Checks and warns of changes.
/Main_Menu
______ ____ _______ ____ ________ ____
/View_Pull_Down
┌─────────────────────────────┐
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
├─────────────────────────────┤
│ ___________________________ │
└─────────────────────────────┘
/Report_Pull_Down
┌─────────────────────────────┐
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
├─────────────────────────────┤
│ ___________________________ │
└─────────────────────────────┘
/*
#INCLUDE RECDE_PD.INC
#INCLUDE TXTW_PD.INC
#INCLUDE NAVI_PD.INC
#INCLUDE HELPA_PD.INC // modified help pulldown. Includes about.
End_Menu
Workshop
Description:
Create an employee data application. Only two files will be needed; Employee and Dept file. There
should be a relationship between these two files.
Tasks:
• Create two files: Employee File and Dept File. Add as many fields that you would like to track
in your databases and create a relationship between these files.
• Create three views; Employee Entry View; Dept Entry View, and a View that shows the Dept
in an Entry Form with all the Employees assigned to that department in a table.
• Create the business rules in the Data_Set Classes that will automatically assign Employee
Numbers and will automatically increment a field in the Dept file that will indicate the number
of employees.
• Be sure that Employee Number is not altered (VLD_Key & Validate_Save Properties). Also do
not allow the user to enter the table in the third view without finding/saving the parent Dept
record.
• Save as WorkShop.src
A p p en d i x A
“Did you Discover
Answers”
File Relationships
This “rule” is really another way of stating rule #2. DataFlex does not support many to many
relationship. DataFlex supports one parent record to many child records, or a one to one
relationship.
Rule #3 __Both Parent & Child related fields MUST be the same length and type.__
DFFile and DFAuto to create a file. Only DFFile allows you to change an active file.
2 - 2. Within DFAuto, what is the difference between a Dialog Title and a Popup
Title?
Dialog titles will place the Object title in the upper left corner of the border
Popup Titles appear centered on the first line within the border of the Object
2 - 3. In Lab #2, when creating the Type.Code field, if a mistake was made and this
field was created as a numeric field instead of an ASCII field, could this be
altered without leaving DFAuto? If so, How?
YES, You can make changes to files, if no records have been added (because restructuring would not
be needed). Changes are done from the Database | Field pull-down. If the field has been
placed in an object, you will have to remove it before you will be allowed to alter the field type.
Changes such as correcting the field name can be done without removing the field.
2 - 4. You were hired to write an application for a college and you have two files:
Classes and Students. What type of relationship is this? How should these
two files relate?
Bridge Relationship. Create a new file with two fields one that relates to Class_ID and one that
relates to Student_ID.
2 - 5. Can you select a pull-down from the Action Bar if a prompt is displayed?
No. This is because prompts are modal objects. Modal objects have their Block_Mouse_State
property set to True. This turns the mouse off anywhere outside the prompt object.
3. - 1. Within DFAuto, can I use the “Load Text” option to read in more than one
image at a time? (If not sure, create a .TXT file with multiple images and use
this file in the Load Text option of DFAuto.)
Yes, if multiple images are in the imported file, then a separate object is created for each image. The
only limitation is that all images will be created as the same class, if this is not desirable, then
separate the images into different files or import the file multiple times using different classes,
and delete the unwanted objects.
DFFile or DFMaint
Changing the About.TEM file, you can quickly create a custom About Pop-up that is called from the
Help Pull-Down.
3. - 5. When using the USE command can you leave off the file extension?
Yes, but only if the extension is .PKG (the default).
End_Object // Memo_EC
End_Object // GL_Accounts_EF
End_Object // Transactions_View
Tasks:
Journal View:
• Fill in the Using Clauses
• Fill in the Updating Clauses
• Create Constraint Blocks in the DSOs that require them
Object Journal_View is an Entry_View_Client
End_Object
End_Object // Tran_Hdr_DS
End_Object // Header_EF
End_Object // Detail_TBL
End_Object // Transactions_View
4 - 2 Write a constraint block that would not show records from the Employee file if
they have a “Y” in the Terminated field
Begin_Constraints
Constrain EMPLOY.TERMINATED NE “Y”
End_Constraints
4 - 3. If I add a Constraint Block, I know I can no longer find a record outside the
constraint, but can I save a record that does not meet the constraint? Take
your TypeEnt.VW and add a constraint block that limits Type.Code GE “I”
and then try saving a new record that has a code of “B”.
Constraint Blocks only limit the viewing (finding) of records, therefore you are allowed to save
records outside the constraint, you would just not be able to find them after the save, even
though they would be saved in the database.
4 - 4. In the below example the Entry Form references the Customer file, the
OrdHead file and the OrdType file. Which file should the using clause
reference?
Ordhead. The using clause should reference the main file data set. This is the child most file
from the data set structure that the object references (similar to the Entry Macro in procedural
code). Since the Data Set Structure is linked by referencing the Ordhead Data Set it will inform
all the DSO above it during a Save operation and because it is aware of the OrdDetail below it
will also complete deletes and clears correctly.
If we would NOT have had the procedure Request_Clear in the current_object then the message would
have been __Forwarded__. And found in which class? __Entry_Form Class__
Would the examples just covered using the Full Access Method and the Name_Object Method still
operate if I add another object around the Empl_Form? __no, both would have to be modified_
Would the example using the Current_Object Access Method continue to operate if a new object was
added around the Empl_Form and Time_Card_Table? __yes, no modification needed________
__yes_____________________
__no, because of encapsulation, Time_Card_Table should not know about a child of Empl_Form__
5 - 1 Can you see an advantage of coding the On_Key command using Accelerator
Key Function names over Physical Key names?
Example: Function On_Key Ksave_record send My_Save
Physical On_Key Key_F2 send My_Save
If defconfig.cfg was modified for the key mapping of the Request_Save message from the default F2 to
F10 then the Function Accelerator would still work
Since Request_Save cascades sending many messages, one of them being Request_Clear, the
canceling of Request_Clear will change the operation of saves by the screen NOT clearing
when saving occurs.
5 - 3 When Adding a message you have to do one extra step that is not normally
needed when Overriding, Augmenting, or Canceling a message. What is this
step?
Adding a message has no way of triggering the message – where the other 3 are all predefined
messages. When adding a new message you need to add some method of triggering this
message. (such as On_Key command or a timer event)
End_Object // MyTable
Yes, When MyTable object uses
Kdownarrow it will find the On_Key command and send the message Print_Label, which it will
find directly in the MyTable object. No, When MyEdit object uses the Kdownarrow key the
Accelerator Key definition will be found in the Edit Class and sends the message Key
Kdownarrow.
Both can
Creating a property
6________
7________
8________
9________
10________
================================================
/*
//**************** fill in the blanks below **************************
End_Object
7 - 1 “Set Value Item 3 to MyVar?” This would set the value of item 3 (the 4th
window of the current object) to whatever the variable MyVar contained. How
would you set the value of item 3 if the current_object is employee_EF and the
object you want to change is called Totals_EF
The button object below is nested within an Entry_Form object, therefore the messages will be
delegated to the correct object. Fill in the 8 blanks so we have 3 buttons, a Save, a Delete and a
Print_Label button.
/Button_Image
__________ ________________ ___________________
/*
Item_List
// What to Display: What to Send:
On_Item __"<F2=Save>"__ __Send Request_Save__
On_Item __"<Shift+F2=Delete>"__ __Send Request_Delete__
On_Item __"<Alt+P=Print_Label>"__ __Send Print_Label__
End_Item_List
procedure print_label
...
End_Procedure
End_Object
Both checkboxes and radios are stored in the database as an ASCII field, with the length being one.
_____1______ if selected
_____0______ if not selected
/Marital_SL_Image
┌──────────────┐
│ ________ │
│ ________ │
│ ________ │
│ ________ │
└──────────────┘
/*
Pick
Object Marital_SL is a Selection_List ;
Marital_SL_image popup ;
Main_File CODES by recnum
for Account.MStatus
Set Location to 5 16
Set Auto_Locate_State to true
Set Auto_Index_State to true
Set Export_Item_State to true
Set Select_Mode to Auto_Select
__Item_List__
entry_item ACCOUNTS.GL#
__On_Item "Single"_____
__On_Item "Married"___
__On_Item "Divorced"__
__On_Item "Widowed"___
__End_Item_List__________________
End_Object
Use UI
Object My_Edit is an Edit
Set size to 5 20
End_Object
Start_UI my_edit
Client or Entry_Client
Check/CheckList/Radio/RadioList/Menu
Menu?
• Business Rules for our files. Without coding, simply jot down ideas (rules that would require
the use of Creating/Update/Backout/Deleting procedures) that must be followed whenever
saving or deleting records in each of the files. Hint: We’ll need to auto assign numbers and
maintain running totals.
GL_ACCT
• Should deletions to this record be allowed if child records exist, (deleting this record and
all child records below it)? ___No_____
TRAN_HDR
• Should deletions to this record be allowed if child records exist, (deleting this record and all
child records below it)? __Yes_____
TRAN_DTL
• Creating (new record saves)
_____Assign next Detail number from Tran_Hdr.next_detail#_______________________
_____Maintain Yr_Hist’s running totals adding to correct year record and monthly fields_
________________________________________________________________________
Creating
10-1 If I find I’m constantly changing the behavior of a class, it may mean that I
should create a new class to meet my special needs. Create a new class that
would act like an Entry_Form but would not allow deletions.
Procedure Request_Delete
End_Procedure
End_Class
10-2 If Validate_Save returns a Zero, does this mean the save passed or failed?
Passed
11-1 Are there other report classes that DFQuery does not use?
Yes, There are report classes that allow easier modifications for selection criteria. There is a
Slctify.zip file on the startup diskette. This is an undocumented utility therefore is not
supported at the present time, but it is a handy utility to quickly change your DFQuery code to
classes that will be documented in future versions of DataFlex. The documentation on how to
use the Slctify utility is in a straight text file (WDFQ.TXT) or if you have Microsoft Word use
the Workin~1.DOC file.
A p p en d i x B
Problems &
Solutions
• Problem: I would like to be able to make multiple selections from a list and then process
the selected items.
• Solution: By default the Pick_List has its Select_Mode set to Single_Select. The
Select_Mode property has 4 settings (no_select, single_select, multi_select, and
auto_select). If you set this property to multi_select in both the pick_list then multiple
selection via the space bar is allowed.
Pick_List Example:
/Discount_Image
╔═══════════════════════════╗
║ Available Discounts ║
╠═══════════════════════════╣
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
╚═══════════════════════════╝
/*
integer hold_total
Procedure Process_Selections
move 0 to hold_total
If (select_state(current_object,0)) send add_it 3
If (select_state(current_object,0)) send add_it 5
If (select_state(current_object,0)) send add_it 10
If (select_state(current_object,0)) send add_it 15
End_Procedure
Item_List
on_item “Non-Human discount = 3%” send none
on_item “Non-Drinker discount = 5%” send none
on_item “Non-Smoker discount = 10%” send none
on_item “Non-Programmer discount = 15%” send none
End_Item_List
End_Object
• Problem: From a selection list I wish to bring back more then related fields. My selection
list is a pop up for the inventory code from the parent file (inventory) in the detail line of an
order. I not only wish to have the product code brought back to the detail line but I would
also like the unit price and description filled into the table as defaults. The unit price and
description fields are reference as fields in the detail file so the user has the ability to type in
anything they wish without affecting the parent (inventory file). But I do wish these two
fields to default with the values from the inventory file whenever the inventory part is
changed.
• Solution: The Move_Value_Out procedure is the message that is sent to move the needed
data into the image, we can augment this procedure and move additional fields. Another
method is within the Selection_List set the Display_buffer_msg property. This property is
called from the selection_List to the invoking object, therefore moving the data from the
found record buffer into the DEO windows as default values is easier.
AutoGen.INI
• Problem: I don’t like how DFAuto indents the code that it generates, it only uses 4 spaces
for tabbing and I find it much easier to read if it is indented 6 spaces. Every time I use it I
have to change the indents to match my old style of coding.
• Solution: DFAuto (AutoGen) has source code options that can be changed. From the
Source Code Generation screen select options.
Figure 162
Figure 163
Auto-Prompting
• Problem: I’ve used the auto prompting feature that brings up the prompt automatically
every time you entry an item window, but this flashing of prompts is hard on the eyes and
my advanced users would prefer to have it turned off. E.g., {iEntry=MSG_Auto_Prompt,
iPrompt=(Customer_LKUP(current_object)) }
Pre-compiling
• Solution: Yes, you can pre-compile code. Module code in view packages has help the
compiling time by allowing us to test each view separately but pre-compiling is still helpful
in some cases. This is done in many packages. AllEntry.PKG is a precompile section of
code that had an #HEADER and #ENDHEADER added at the top and bottom of the code
and then compiled using the -P option. This option creates up to three files ALLEntry.PKI
(package include file) ALLEntry.FLP (like a .FLX of the pre-compile section, and
AllEntry.PRP (like a .PRN, if the -f option was used). Then when your first command in
your code is USE AllEntry the compiler will use the pre-compile version instead of having
to compile the same code over and over again.
• Problem: I use many Selection Lists my filelist is getting full of small files.
Employee Screen
Male
Name _______________ Female
Mail List _
Yes
No
Sample Data:
TYPE CODE DESCRIPTION
These pop-ups are easy. Setting properties will allow you CCard M Master
to quickly create the pop-up to meet your needs. CCard V Visa
CCard A American Express
Marital M Married
Marital S Singled
Marital D Devorice
Marital W Widowed
Response Y Yes
Response N No
Sex M Male
Sex F Female
Status A Active
Sample Code: (check the Handbook for other examples) Status I Inactive
Table Optimizing:
• Problem: My tables seem slow and the users do not like the constant re-ordering that
happens when they add a new row in a table.
• Solution: When a user adds a new record in a table, it can confuse them when the table
rows above and below changes as the table reorders itself, this can be stopped by setting the
Auto_Regenerate property to FALSE. Also only allow additions at the bottom of the table.
This is accomplished with the Append_A_Row property and setting three properties:
Allow_Bottom_Add_State (to default-true); Allow_Top_Add_State (to default false);
Allow_Insert_Add_State (default true, change it to FALSE).
Object MyTable is a Table MyTable_Image
:
Set Auto_Regenerate_State to False //do not reorder the table after additions
Set Allow_Insert_Add_State to False // do not allow additions in the middle of table
On_Key kAdd_Mode Send Append_a_Row //instead of inserting a blank row jump to end
End_Object
A p p en d i x C
Extra Notes:
message
client
entry_client
data_set
entry_view_client
selection_list_client
view_client
client_window
error
error_type_c
help
title
scroll_b
vconsole
report
report_ds
standard_report
Accelerator Keys
Function S+ C+ A+
Key Function Key Function Key Function Key Function Key
1 Help User Key 1
2 Save Record Delete Record User Key 2
3 Exit Function Trace Mode * Trace on/off *
4 Prompt Print Screen Exit Application
5 Clear Panel Refresh Screen Clear all Panels Calculate
6 Switch to Next Area Switch to Prev.Area Switch Prev. Panel * Switch Next Panel *
7 Find Previous Superfind Previous
8 Find Next Superfind Next
9 Find Superfind Zoom
0 Switch to Action Bar Add Mode on/off *
R Accept Clear and Return
F Next item Previous item
Z Insert/Overtype Toggle
X Delete Character
l Cursor Left Skip Word Left
r Cursor Right Skip Word Right
t Cursor Up Beginning of Panel
b Cursor Down End of Panel
s Selection Toggle
B Destructive Backspace Erase to End of Line Non-WP Bksp
h Beginning of Line Beginning of Data
e End of Line End of Data
u Scroll Page Up Scroll Page Left
d Scroll Page Down Scroll Page Right
E Cancel
/ Mark
+ Paste
- Copy Cut
Transaction Processing is a group of database operations that must all complete, or fail, together to
maintain database integrity.
Version 3.1 has incorporated two previously separate products, Data Access Corporation’s Database
Application Program Interface (API) and DataFlex Application Framework (DAF).
Application Framework is a methodology that is the foundation to good coding in object oriented
DataFlex language. This methodology has been incorporated within this version, classes have been
modified and both AutoCreate and Query Utilities conform with framework coding structure.
Following the Framework methodology result in consistent results from all your program views and
code that is easier to maintain and modify.
Below are only a few of the enhancements, see the Update to 3.1 manual for complete list.
• New Commands:
call_driver copy_records create_field create_index
declare_datafile delete_field delete_index field_map
fill_field get_attribute get_channel_size get_field_value
get_filelist get_resource_type include_resource load_def
load_driver output_aux_file read_hex register_resource
set_attribute set_field_value set_filelist sort
structure_abort structure_copy structure_end structure_start
unload_driver vconstrain write_hex
Compiler (DFComp)
Takes source code files and compiles them into .FLX files that can be run from DFRUN. Many
options are available to aid in debugging and recompiling sections of code.
DFRun DFBrowse
This utility will allow you to browse and edit your data files. This is very helpful for the programmer
to verify the data, but since our Data_Set Business Rules are not in force here, beware that you do not
corrupt the data.
Things to Standardize
There are a few items that need to be kept constistant or you application and code will not be as easy to
use or debug.
We now know that the user has more control over his interaction with the programs that we, as
programmers code. In order for us to effectively code we have to be able to send messages – We
cannot be good object oriented programmers if we cannot get our procedures executed. We must know
how to trigger these messages.
List ways that will cause a messages to be sent! Here are a few that may have been covered in the
conversations in class:
Commands
• Send
• Forward Send
• Delegate Send
• Broadcast Send
• Set_Timer
• On_Key
User Interface
• Predefined Accelerator Keys
• Keyboard
• Mouse
Entry Options
• Iexit
• Ientry
• Ivalidate
Properties
• Set Entry_msg to procedure_name
• Set Exit_msg to procedure_name
• Set Verify_Delete_msg to procedure_name
• Set Verify_Save_msg to procedure_name
• Set Verify_Data_Loss_msg to procedure_name
• Set Verify_Exit_msg to procedure_name
Student Notes:
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
G l o ssar y
Terms Definitions
Acrobat Reader A program by the Adobe Corporation that allows you to read files. This is the
prefect tool to use for reading and searching our online documentation.
Application Frame Is the methodology to construct and connect object oriented sections together
Work correctly.
Class Package A .PKG file that contains the source code for a class definition. This code is
included in the program at compile time through the use command. Examples:
Table.PKG, AllEntry.PKG
Current_Object Is the object that is currently processing. This means when one message starts a
cascading of other messages to be sent, that through delegation the
current_object may change many times from the original object in which the
message was sent.
.DAT files The .DAT files are the data files where DataFlex stores the raw data entered,
unless compression is used in which case the data is stored in the .VLD file and
the .DAT is used as a pointer to locate the correct record in the .VLD file
.DEF files The .DEF files have an entire file structure of a database described in an ASCII
format. These ACSII files can be created from DFFile or DFMaint and can be
used in DFFile to create a duplicate file structure.
DEO Data Entry Objects are objects that allow data entry.
DSO Data Set Objects are objects that are built from the Data_Set class or a subclass
built from this important class. Data Sets Objects are the servers of data to the
DEOs, for finds, clears, saves, and deletes.
Encapsulation A section of code that can operate alone This does not mean it needs no
external connections. An object is an encapsulated code segment; it is a black
box whose makeup you need not know exactly, just the interfaces that allow
you to interact with it (i.e. what properties and messages can be sent to it). The
object may have external dependencies, such as a DEO being connected to a
Data_Set Object.
Entry Item Options Options that are connected to an item window that will perform a desired action
when the user enters or leaves a window. Example: {Capslock} will force the
contents of the window to only be capital letters: {ientry=msg_default_state}
will send the message default_state just prior to entering the window.
Filelist.CFG Filelist.CFG contains a list of all the filenames (Rootname, DataFlex name,
User name) for each file that is accessible.
Focus Tree UIMS applications organize objects in a manner allowing logical navigation
paths between objects. As objects activate and deactivate, this tree is updated
to reflect the object’s position in relation to other active objects. Four
properties indicate the object’s position: Prior_Focus, Next_Focus,
Prior_Level, and Next_Level.
Model Navigation: Users are required to finish one task before moving to the next
Object Package: A .PKG file that contains a predefined structure of objects that may be used in
programs. Example: Confirm.PKG
Superclass: The class from which the object inherits its principal properties and procedures.
User Interface The method of communication between a computer and its operator.
Additional
Training
New classes are always under consideration, check with your distributor for the up to the
minute status.
Additional
Related Products:
∗ D for Windows
DataFlex for Windows is an extremely powerful application development environment that combines
the power of the DataFlex object-oriented 4GL with the highly praised intuitive user-interface of
Microsoft Windows.
∗ D Debugger
The DataFlex Debugger provides you with the facilities needed to quickly and efficiently debug
DataFlex object-oriented and procedural applications. The DataFlex debugger allows you to
explore the inner workings of DataFlex program interactively, at a level of detail you never
dreamed possible.
∗ FlexQL
FlexQL is a powerful professional report writer (for DOS environments) that allows you to create
great-looking reports quickly simply by pointing and selecting. It is an important tool for anyone
who manipulates data, as it allows the user to integrate multiple file formats and combine the
information into a single, more meaningful report. non-window environments.
Learning Object Oriented has many avenues to help you. Log onto DataFlex’s Compuserve Form by
typing GO DACCESS. This will get you in touch with lots of developers, and free support by just
leaving a message to the System operator. Purchase a support contract and receive voice support. The
Developing Applications with DataFlex is a great source of knowledge.
Students completing a class, please fill out both parts A and B. Students using the manual as a self
taught course, please answer only part B. When complete, simply pull this page out, fold on dotted
line, tape where indicated, stamp and drop in the mail.
Part A:
Date: ________________________
Location: ________________________
Instructor: ________________________
Please rate the following on a scale from 1 to 10 (10 being the best)
• Class overall? ____
• Instructor? ____
• Training manual? ____
• Handouts and other training media? ____
Part B:
-----------------------------------------------------------------
tape here
Instructor’s
Notes
Discovering Object Oriented DataFlex was created to be used as a 3-5 day course and also be sold as a
self-taught study guide. If all everything is covered including the Workshop it may take a full 5 days, if
the workshop and Appendix is left off this will shorten the class by over a day. Class will move along
faster if the students have done some reading before they attend class. The recommended reading list
located at the beginning of the manual in the “How to use the Manual” section can be sent to the
students before class so they can get a head start on their reading.
The lessons are designed with hands on learning in mind. A lot of information is covered in a short
amount of time. Instructors must keep their class motivated and focused in order to complete all the
lessons. The Table of Contents shows an estimated time for each of the lessons. This is a total lesson
time which includes the basic lesson, the Student’s Lab, and the time spent on the Did you Discover
questions. Every class will differ on time requirements, use this number only as an estimate. It should
give you an idea of how much time you can allow for labs, and as a guide to the speed that you conduct
the class.
Basic Lesson: Lessons should be covered by the instructor. When appropriate the use of a LCD
projector panel should be used, with the students following along on their computers..
Labs: Labs allow the students time to practice & reinforce topics what you have just taught. To keep
the class on track always state the time allowed for each lab, some instructors may find it beneficial to
use a timer that will add focus to the class and alert the class that it is time to move on when the buzzer
goes off. Labs are also the time that you move about the class and give one on one help and
encouragement. There are times that a lab may add code(not covered yet) in order for the program to
operate, if this is the case I have tried to indicate the future lesson when the topic will be covered.
Did you Discover: This is not a quiz but a “buffer “that will keep the fast student challenged after they
finish their lab, but at the same time give the slower student sufficient time to complete the lab without
feeling rushed. Very seldom are you fortunate enough to have a class where all students are at the
same expertise. Many of the questions are not directly covered in the lesson whereby the student will
have to experiment, and even test results in order to Discover the answer. This extra discovery time
spent will led to more learning and efficiency in the language. Instructors are encouraged to add your
own topics/questions in this section, adding their own personal touch to their class. These additions
can also be mailed back to Data Access to be incorporated into the next printing of the manual. Make
sure students are aware that they should complete this section if they complete a lab early, but if they
do not have the time to complete the section, the answers will be provided to them. This section can
also improve student interaction. The instructor should encourages students to help each other and
interact during this Discover section. When Lab time is over ask if there are any questions on the lab
and then cover the Did you Discover section. Covering may be as quick as reading the answers from
Appendix A or demonstrating the answer on your computer.
Workshop: Instructors can have the entire class do the workshop in the manual or allow students to
create an application that they know will be needed back at work. Allowing each student to work on
their own project can sometimes be taxing on the instructor, but it provides the best learning
atmosphere for the student. It will allow their creative juices to flow and they will run into all sorts of
real life obstacles. If time is a factor, or if you have a large class, using the workshop project is
suggested, but if time permits this self creating lab will make your class a success.
Appendix A: This appendix lists answer to the Did you Discover sections, plus all fill in the blank
questions in the lesson. Some instructor’s may prefer to remove this appendix before their class.
Appendix B: Appendix B is a collection of problems with sample solutions. If you find that your
class is finishing early you may wish to include one or more of these examples in your class.
Appendix C: This appendix is a reference with charts and summary information (tid bits). It was not
intended to be covered in class. Pages have also been added for student notes.
Evaluation: The student evaluation was designed so it can be removed from the manual at the end of
the class and returned to our Miami office in an effort to improve our classes.
A Classroom environment is never the same twice. Based on the students in the class you will find you
teach the same class a little different each time. Here are some ideas that may help customizing the
class around the students to make the class more enjoyable.
I find sometimes an active class will enjoy covering extra topics themselves. Look though the manuals
(the handbook is a good one) and find small topics that each student could cover in a short time like
common properties, procedure or functions (ex: auto_prompting, auto_reorder_list in Selection Lists,
export_item_state, popup, move_value_out). List each topic (with the page# of where to find the
topic) on a small piece of paper and everyone draws a topic! The next day they explain their property
(etc.) to the class and where/how to use it. This works good when you are training a group that is all
from the same company. If the programmer later is having problems with this topic he knows that he
can get help from his co-worker that covered this topic in class. You’ll also find that the students will
discover other topics in their reading, so be sure you are ready for lots of extra questions. Let the
student give his presentation in front of the class or right in his chair, whatever makes him feel
comfortable.
If an overhead is available make transparencies of the fill-in the blanks; Discover Questions; and any
code that will need explaining (like Save_Header Procedure). This is a real time saver!
Contests are also nice, with a small prize such as a DataFlex T-Shirt or mouse pad. One idea is to have
students list methods of triggering a message. (Remove the “How to trigger a message” page from the
manual. This contest can be started on the first day and the students can be adding to the list
throughout the class and totaled on the last day of class.
A three day course will include the eleven basic lessons that you will guide the students through and
then allowing them to accomplish the labs as much on their own as possible. The “Did You
Discover?” questions should only be added if time permits and even lesson 11 on reporting could left
as an extra exercise that the students do on their own after class. An estimated pacing for these three
days:
• Day One Somewhere in Lesson 3
• Day Two Lesson 7
• Day Three Hopefully Completing Lesson 11
As you can see the class must move along quickly. Stress to the students that you wish them to review
the next day’s lessons each night because even thought you will explain the code modifications that
you will be adding, you will not have enough time to linger on any topic!