0% found this document useful (0 votes)
6 views

discovering_object_oriented_dataflex

The 'Discovering Object Oriented DataFlex' training guide is designed to introduce users to object-oriented programming using DataFlex version 3.1. It includes lessons on class setup, programming basics, and advanced topics, with a focus on hands-on learning in a classroom environment. The manual emphasizes the importance of prior knowledge in DOS or Windows and provides resources for further study and support through the Data Access Corporation forum on CompuServe.

Uploaded by

Roberto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

discovering_object_oriented_dataflex

The 'Discovering Object Oriented DataFlex' training guide is designed to introduce users to object-oriented programming using DataFlex version 3.1. It includes lessons on class setup, programming basics, and advanced topics, with a focus on hands-on learning in a classroom environment. The manual emphasizes the importance of prior knowledge in DOS or Windows and provides resources for further study and support through the Data Access Corporation forum on CompuServe.

Uploaded by

Roberto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 312

Discovering

Object Oriented
D
Training Guide

Copyright 1995 Data Access Corporation


DATA ACCESS CORPORATION
14000 S.W. 119 Avenue
Miami, Florida 33186
USA

Revision Date: January 1, 1996

PN: 917000
COPYRIGHT NOTICE

Copyright 1996 DATA ACCESS CORPORATION. All rights reserved.

No part of this publication may be reproduced, or distributed, transmitted, transcribed, stored in a


retrieval system, or translated into any human or computer language, in any form or by any means,
electronic, mechanical, magnetic, optical, manual, or otherwise, or disclosed to third parties without the
express written permission of Data Access Corporation, 14000 SW 119 Avenue, Miami, Florida,
33186, USA.

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

DataFlex is a registered trademark of Data Access Corporation.


WinQL is a registered trademark of Core Software, Inc.
Microsoft Windows is a registered trademark of Microsoft.
All other brand and product names are trademarks or registered trademarks of their respective
companies.
For More Information on Object Oriented Programming (OOP)

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!

Also visit us on the internet at www.dataaccess.com


Table of Contents

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.

Data Access Corporation 9


Introduction Discovering Object Oriented DataFlex

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.

Here is a list of recommended reading to start your learning program:

Developing Application with DataFlex is a tutorial. Reading this manual before attending class
will increase the knowledge obtained from this course.

The following list is from the UIMS Handbook:

• Read Before Class


Chapter 2 - DF UIMS
Chapter 4 - DAF
Chapter 5 - Using DAF
• Read Right After (or during) Class (wouldn’t hurt to read it before)
Chapter 3 - Using the UIMS
Chapter 6 - Using Data-sets
Chapter 7 - Using DEOs
Chapter 8 - Reporting
• Read to properly complete their Advanced DF/OOP Education
All remaining Chapters.

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.

10 Data Access Corporation


Discovering Object Oriented DataFlex Introduction

How to use the Manual


Classroom Environment:
A hands-on classroom setting is the recommended method of using this manual. The self study method
is possible but students will find that the classroom interaction and the aid of the instructor to be of
great importance.

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.

Self Taught Method:


This manual can also be used as a hands on tutorial. Check the next few pages to ensure you have all
needed equipment/software before you begin. As you work through the lessons if problems arise, you
may find it helpful to unzip the current lesson, (Lesson??.ZIP file) and compare your work with the
corresponding file. Unzip these files in another directory so your work is not overwritten. The lessons
end with a “Did you Discover?” section, the answers to these sections (along with any fill-in questions)
are located in Appendix A. The Did you Discover sections are NOT Quizzes! Some of the topics are
not even covered in the lesson. They are intended as extra information and/or reinforcement learning
to challenge the students. Do not use them as tests of your knowledge, but as an additional learning
tool to cover more information. Remember there is also a glossary to help you.

Data Access Corporation 11


Introduction Discovering Object Oriented DataFlex

How Items will be Displayed

• Commands that require action will be displayed like this:

Commands to be performed will be in this font with a bold


top and bottom line. They are as brief and precise as
possible, sometimes using symbols.

The command below means select “File” from the menu


bar and then select “Options” from the pull down.

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.

• Symbols: Many look very similar—attention to detail is a must!


Symbol Description
] Click the right mouse button.
[ Click the left mouse button.
/ Double click the left mouse button.
E Press the Escape Key.
T Press the Tab Key
u Press the Page Up Key
d Press the Page Down Key
w Right Dragging: Hold the right mouse key down while moving
the mouse to a new location and then releasing.
(DFAuto uses to resize & move objects)
; Left Dragging: Hold the left mouse key down while moving the
mouse to a new location and then releasing.
(DFAuto uses to Block an area for cut/copy operations)

12 Data Access Corporation


Discovering Object Oriented DataFlex Introduction

• Program code will be displayed like this:

Use UI

// Areas that are shadowed are areas of interest,


// or to show where code has been added or modified.

Object My_Editor is an Edit


Set Location to 5 12
Set Size to 45 5
... // Three dots are used to show the code has been
// abbreviated and some code has been skipped.
End_Object

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 Available = TestCode.SRC *****


...
program code listing
...

• 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.

Object One is an Entry_Form

End_Object

Object Two is an Entry_Form Segment of Code Available


Procedure XYZ in XYZ.INC file
End_Procedure

End_Object

Data Access Corporation 13


Introduction Discovering Object Oriented DataFlex

DataFlex Manuals
The purchase of a DataFlex license really buys two languages, a Procedural and an Object Oriented
Language. The manuals available are:

• User’s Guide (on line)


The basic concepts of DataFlex that impact both languages are found
here. Concentrates mainly on the procedural coding style. A sample
of the topics are: Error List, Language Specifications, Reserved
Word List, and Use of DataFlex Utilities.

• Encyclopedia (on line)


Alphabetic listing of DataFlex’s commands, functions, and predefined
variables (UIMS commands have been incorporated and are no
longer found in the Reference manual).

• UIMS Handbook (on line & printed form)


This manual will instruct you in developing in the object oriented
language, using the application framework method. The manual has
been updated with MANY great examples! These is a very important
learning resource even for the advanced programmer.

• UIMS Reference (on line)


This is your reference to the Object Oriented Language! An alphabetic
list of all Classes, showing their use, description and the properties,
procedures and functions that are defined in the class. Charts located
in the front of the manual will help you learn & find all the
properties, procedures and functions.

• Developing Applications with DataFlex (on line & printed form)


A hands-on tutorial for the Object Oriented Language. This is a great
book with good examples. It is highly recommended reading!

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.

* UIMS (User Interface Management System)

14 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 1 Setup

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.

Topics in this Chapter:

• Equipment Requirements

• Copying Class Files

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.

Data Access Corporation 15


Lesson 1 Setup Discovering Object Oriented DataFlex

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

DataFlex Installation Directories


The manual is assuming that
DataFlex 3.1 has been installed and FLEX
no modifications have been made to BIN
AutoGen.INI; DFConfig.INI, LIB
DFEnv.CFG, or Setpath.BAT SRC
PKG
Source
USR
Help
Examples
Data
Expense
Ordentry
DAR
Big
Report
Tutorial
Handbook
Checks
Misc
Order

16 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 1 Setup

Copying Class Files

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.

If working from a network, please adjust OS commands accordingly.

at the OS command prompt type:

MD C:\FLEX\ClassOOP
Copy A:*.* C:\FLEX\ClassOOP

Setpath

DFRun

Data Access Corporation 17


Discovering Object Oriented DataFlex Lesson 2 The Basics

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.

Topics 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.

Data Access Corporation 19


Lesson 2 The Basics Discovering Object Oriented DataFlex

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

620 Rent E 650.00


1278 02/13/1995 Christmas Gift
130 Vehicle-Ford 1994 A 18000
1277 02/12/1995 Sold Car
100 Cash A 500.00
1276 02/12/1995 Refund Check
GL_ACCTS FILE
TRAN_HDR FILE

620 1995 0.00 187.34 1278 101 D 45.00

100 1994 0.00 235.67 1278 130 C 12000.00


100 1995 0.00 582.11 1276 101 D 20.00

YR_HIST FILE TRAN_DTL FILE

20 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

A look at the File Definitions: (these are partial .DEF files).


These ASCII files show the file structure.

-------------------------------------------------------------------
DATE: 01/25/96 TIME: 13:49 PAGE: 1
FILE DEFINITION FOR FILE: TYPE (# 5)
-------------------------------------------------------------------
...

NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD


--- --------------- ---- ----- ----- -- -----------------------
1 TYPE ASC 1 1 1
2 DESCRIPTION ASC 20 2 2

INDEX# FIELDS DES U/C LENGTH LEVELS SEGMENTS MODE


------ --------------- --- --- ------ ------ -------- -------
1 TYPE NO NO 1 2 1 ON-LINE

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)
...

NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD


--- --------------- ---- ----- ----- -- -----------------------
1 GL# NUM 4.0 1 1 GL_ACCTS.GL#
2 YEAR NUM 4.0 3 1
3 BUDGET_01 NUM 6.2 5
4 BUDGET_02 NUM 6.2 9
5 BUDGET_03 NUM 6.2 13 -------------------------------------------------------------------
6 BUDGET_04 NUM 6.2 17 DATE: 01/25/96 TIME: 13:49 PAGE: 1
7 BUDGET_05 NUM 6.2 21 FILE DEFINITION FOR FILE: GL_ACCTS (# 1)
8 BUDGET_06 NUM 6.2 25 -------------------------------------------------------------------
9 BUDGET_07 NUM 6.2 29 ...
10 BUDGET_08 NUM 6.2 33
11 BUDGET_09 NUM 6.2 37 NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD
12 BUDGET_10 NUM 6.2 41 --- --------------- ---- ----- ----- -- -----------------------
13 BUDGET_11 NUM 6.2 45 1 GL# NUM 4.0 1 1
14 BUDGET_12 NUM 6.2 49 2 GL_DESCRIPTION ASC 35 3 2
15 ACTUAL_01 NUM 6.2 53 3 CURRENT_BALANCE NUM 6.2 38
16 ACTUAL_02 NUM 6.2 57 4 TYPE ASC 1 42 3 TYPE.TYPE
17 ACTUAL_03 NUM 6.2 61 5 MEMO TEX 320 43
18 ACTUAL_04 NUM 6.2 65
19 ACTUAL_05 NUM 6.2 69
20 ACTUAL_06 NUM 6.2 73 INDEX# FIELDS DES U/C LENGTH LEVELS SEGMENTS MODE
21 ACTUAL_07 NUM 6.2 77 ------ --------------- --- --- ------ ------ -------- -------
22 ACTUAL_08 NUM 6.2 81 1 GL# NO NO 2 2 1 ON-LINE
23 ACTUAL_09 NUM 6.2 85 2 GL_DESCRIPTION NO NO 35 3 1 ON-LINE
24 ACTUAL_10 NUM 6.2 89 3 TYPE NO NO 3 2 2 ON-LINE
25 ACTUAL_11 NUM 6.2 93 GL# NO NO
26 ACTUAL_12 NUM 6.2 97

INDEX# FIELDS DES U/C LENGTH LEVELS SEGMENTS MODE


-------------------------------------------------------------------
------DATE:
---------------
01/25/96 ---TIME:
--- 13:49
------ ------ -------- -------
PAGE: 1
1 FILEGL# DEFINITION FOR
NO FILE:
NO TRAN_HDR
4 (# 22) 2 ON-LINE
YEAR YES NO
-------------------------------------------------------------------
...

NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD


--- --------------- ---- ----- ----- -- -----------------------
1 TRANS# NUM 6.0 1 1
2 DATE DAT 3 4 2
3 EXPLANATION ASC 50 7
4 TOTAL_DEBITS NUM 8.2 57
5 TOTAL_CREDITS NUM 8.2 62
6 LAST_DETAIL# NUM 6.0 67

INDEX# FIELDS DES U/C LENGTH LEVELS SEGMENTS MODE


------ --------------- --- --- ------ ------ -------- -------
1 TRANS# NO NO 3 2 1 ON-LINE

2 DATE YES NO 6 2 2 ON-LINE


TRANS# NO NO

Data Access Corporation 21


Lesson 2 The Basics Discovering Object Oriented DataFlex

-------------------------------------------------------------------
DATE: 01/25/96 TIME: 13:49 PAGE: 1
FILE DEFINITION FOR FILE: TRAN_DTL (# 3)
-------------------------------------------------------------------
...

NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD


--- --------------- ---- ----- ----- -- -----------------------
1 TRANS# NUM 6.0 1 1 TRAN_HDR.TRANS#
2 DETAIL# NUM 6.0 4 1
3 GL# NUM 4.0 7 2 GL_ACCTS.GL#
4 DC ASC 1 9
5 AMOUNT NUM 6.2 10

INDEX# FIELDS DES U/C LENGTH LEVELS SEGMENTS MODE


------ --------------- --- --- ------ ------ -------- -------
1 TRANS# NO NO 6 2 2 ON-LINE
DETAIL# NO NO
RECNUM NO NO
2 GL# NO NO 8 2 3 ON-LINE
TRANS# YES NO
RECNUM NO NO

-----------------------------------------------------------------------------
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
-----------------------------------------------------------------------------

NUM FIELD NAME TYPE SIZE OFFST IX RELATES TO FILE.FIELD


--- --------------- ---- ----- ----- -- ---------------------------------
1 LAST_TRANS# NUM 6.0 1

22 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Our project will be made of modual parts. Here is an overview:

Figure 1

Data Access Corporation 23


Lesson 2 The Basics Discovering Object Oriented DataFlex

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.

Un-related Files (duplication of data):

Saving Account Checking Account Car Loan Safe Deposit Box


address address address address

Related Files (no data duplication):


Customer File
Parent file address

Saving Account Checking Account Car Loan Safe Deposit Box


Child files

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.

24 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Types of Relationships

Chain Relationships: Publishers Grandparent


Relate files in a single chain, child
related to parent, parent related to
grandparent. Authors Parent

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

Data Access Corporation 25


Lesson 2 The Basics Discovering Object Oriented DataFlex

Related fields during a save


The parent and child related fields must be the same in order for the link between records to operate
correctly. We wouldn’t want the user to enter the data twice (once in parent and once in the child).
DataFlex solves this by moving the related parent field into the related child field during the save
operation. This means that when displaying a related field, it is almost always the parent related field.

File Relationship Rules?:

Rule #1 Many to N relationship .

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 * _________________________________________________________

What happens if we break this rule?

Rule #3 * _________________________________________________________

What happens if we break this rule?

* Answers to all fill-ins are located in Appendix A.

26 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

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).

at the OS command prompt type:

CD\Flex\ClassOOP

DFRUN

Database | File Definition


Utility

Figure 2

Data Access Corporation 27


Lesson 2 The Basics Discovering Object Oriented DataFlex

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

28 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

A field list appears. Notice the


scroll bar will allow us to scroll
down the list. Also note the “1” in
the upper right corner. To rotate
back to this screen we press Alt+1
or select Fields from the View pull
down.

Figure 5

Alt+2 takes us to the Index


View

Figure 6

Data Access Corporation 29


Lesson 2 The Basics Discovering Object Oriented DataFlex

x will display the next


Index

In this file there is only one


Index

Figure 7

Alt+3 displays the


Parameter View

Figure 8

Note the following in the screen above :

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.

Transaction Type (a new feature in 3.1)


• Client Atomic Roll Back if transaction is not complete, but not safe if workstation crashes.
• Server Atomic Roll Back if transaction is not complete, and workstation crash safe
Your server must be capable of TTS (Transaction Tracking System)

30 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Creating a new file in DFFile

File | New

Figure 9

Type GL_Accts for the


rootname

[ OK

Figure 10

Data Access Corporation 31


Lesson 2 The Basics Discovering Object Oriented DataFlex

Alter Record Length to 384

[ 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

Alt+1 and enter fields as


indicated

Prompt (F4) available in


type column

Figure 12

32 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Alt+2

F4 will bring up a prompt


list

Enter GL# as the First


Index

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.

Enter GL_Description for


Index 2

[ U/C (uppercase)

Figure 14

Data Access Corporation 33


Lesson 2 The Basics Discovering Object Oriented DataFlex

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.

F7 switches to Yr_Hist file

Alt+1

Figure 15

On the row of GL# field,


move to the Relates to
column (not the index
column!)

F4

[ Attach to Field

Figure 16

34 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

GL_Accts

[ OK

Figure 17

[ GL#

[ OK

Figure 18

Note: Only fields of the same length and type are displayed.

Data Access Corporation 35


Lesson 2 The Basics Discovering Object Oriented DataFlex

Verify that the relationship


looks like this:

Figure 19

File | Save

Figure 20

36 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

[ OK

Figure 21

File | Exit

Figure 22

Data Access Corporation 37


Lesson 2 The Basics Discovering Object Oriented DataFlex

Warning screen appears. We only


saved the Yr_Hist file. Our new
GL_Accts file was not saved.

[ Yes

Figure 23

[ OK

Figure 24

38 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Classes and Objects


The two fundamental key terms in Object Oriented Language are Classes and Objects. AutoCreate
introduces the term Object, so let’s briefly describe these terms so we have a basic concept of them.

Classes are the tools


and

Objects are instances of using such tools

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:

Use Entryfrm Use Table


... ...
/Employee_Entry_Form /Employee_Table
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Name _________________________ ³ ³ Name State Date Hired ³
³ Address _________________________ ³ ³ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄij
³ City, St ____________________, __ ³ ³____________________ __ __/__/____ ³
³ Zip __________ ³ ³____________________ __ __/__/____ ³
³ ³ ³____________________ __ __/__/____ ³
³ Date Hired __/__ ____ ³ ³____________________ __ __/__/____ ³
³ Eval __/__/____ ³ ³____________________ __ __/__/____ ³
³ Terminated __/__/____ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
³ ³ /*
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
/* Object Employee_Table is a Table

Object Employee_Entry_Form is an Entry_Form Begin_Row


Item_List entry_item Employ.Name
entry_item Employ.Name entry_item Employ.St
entry_item Employ.Address entry_item Employ.Hired
entry_item Employ.City End_Row
entry_item Employ.St
entry_item Employ.zip End_Object
entry_item Employ.Hired
entry_item Employ.Eval ...
entry_item Employ.Term
End_Item_List
End_Object

...

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.

Data Access Corporation 39


Lesson 2 The Basics Discovering Object Oriented DataFlex

DataFlex provides a full set of classes (tools). These are the most common, high level classes.

Class: Tool Use:


Entry_Client a container for objects
Entry_View_Client a container specially suited as the outer container of a
view
Data_Set the tool that provides database services (finds, saves,
deletes, and clears) to the data entry objects
Entry_Form data entry for a single record
Table multiple-column data entry tool for multiple records
Text_Window data entry tool for text fields
Selection_List a pop-up list providing users a choice from a database file
Pick_List a pop-up list providing users a choice from static data

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.

40 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

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

Data Access Corporation 41


Lesson 2 The Basics Discovering Object Oriented DataFlex

Fill in the Name as Ledger

Press F4 in main file and


select Yr_Hist

Figure 27

Note: The main file cannot be changed! Therefore, be sure it is the child-most file needed in the
view.

Fill in the Style dialog box


as indicated, substituting
your name as the author

[ OK

Figure 28

42 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Object | New | Form

Figure 29

Yearly Summary as the


form name

F4 and select any color for


window & text color

Figure 30

Data Access Corporation 43


Lesson 2 The Basics Discovering Object Oriented DataFlex

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.

Fill in the Form as


indicated

[ OK

Figure 31

44 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Moving & Resizing Objects


Moving and resizing is done by right-dragging the mouse. Left-dragging is used for highlighting an
area for cut/copy operations. To turn off the blocking highlighting, simply single click the left mouse
button.

Press and hold the right


mouse button on the top
border to move the object

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.

Practice moving and


resizing and then position
object in upper right corner

Figure 33

Data Access Corporation 45


Lesson 2 The Basics Discovering Object Oriented DataFlex

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.

Type in the static


data

(Insert & Delete lines


are explained below)

Figure 34

Use the Edit pull


down if you need to
insert or delete a line

Leave a blank line


just above “Jan”

Figure 35

46 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

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.

Click on left border of the


blank row

Edit | Lines | Single

Right side of status bar will


indicate line mode, Press
Ctrl F1 until Line mode is
off
Figure 36

Data Access Corporation 47


Lesson 2 The Basics Discovering Object Oriented DataFlex

Fields | Field Toolbox

Figure 37

From the Field Toolbox,


hold down the right mouse
button over YEAR field

Notice the cursor changes


to underscores

Drag and drop the year off


on the 1st line in the image

Figure 38

48 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Drag the budget


(Budget_01 - Budget_12)
and actual (Actual_01-
Actual_12) fields into the
image

The Differ column will be


added later

Figure 39

Database | Open

Figure 40

Data Access Corporation 49


Lesson 2 The Basics Discovering Object Oriented DataFlex

[ Open Related Button

Notice, when you open another


file, the toolbox will show all the
fields for that file.

Figure 41

50 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Building Multiple Objects

Object | New | Form

Figure 42

Fill in the form as indicated

[ OK

Figure 43

Data Access Corporation 51


Lesson 2 The Basics Discovering Object Oriented DataFlex

Position the new object at


the top of the screen

Add label & fields from the


GL_Accts file

Figure 44
Description Field

Object | New | Editor

Figure 45

52 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Fill in the New Editor


Dialog as indicated

Figure 46

Move and resize the editor


so it is totally inside the GL
form

An object can totally hind behind


another larger object. Objects |
Switch To will allow you to
switch to a hidden object.

Figure 47

Data Access Corporation 53


Lesson 2 The Basics Discovering Object Oriented DataFlex

Position the memo field


within the editor

Figure 48

54 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Switching between Objects

Press the TAB key


multiple times & watch the
status bar.

Notice as you rotate from object to


object . Sometimes one object can
totally disappear behind another!

Figure 49

The three lines in the upper left


corner of the Field Toolbox
dialog are called a System Icon.

[ System Icon & Close


the Dialog

Figure 50

Data Access Corporation 55


Lesson 2 The Basics Discovering Object Oriented DataFlex

Entry Options

Position the cursor on the


GL# field

GL_Accts.GL# should be
displayed in the middle of
the status bar

Fields | Field Entry Options

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

56 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

A short cut to bringing up the Entry Option Dialog is to use the (F4) Key

Position cursor on TYPE


field

F4

Check Capslock

[ OK

Add the entry options from


the table
Figure 53

FIELD ENTRY OPTION


Yr_Hist.Year AutoFind, AutoClear
GL_ACCTS.Current_Balance AutoClear
Yr_Hist.Actual_01 DisplayOnly
Yr_Hist.Actual_02 DisplayOnly
Yr_Hist.Actual_03 DisplayOnly
Yr_Hist.Actual_04 DisplayOnly
Yr_Hist.Actual_05 DisplayOnly
Yr_Hist.Actual_06 DisplayOnly
Yr_Hist.Actual_07 DisplayOnly
Yr_Hist.Actual_08 DisplayOnly
Yr_Hist.Actual_09 DisplayOnly
Yr_Hist.Actual_10 DisplayOnly
Yr_Hist.Actual_11 DisplayOnly
Yr_Hist.Actual_12 DisplayOnly

Data Access Corporation 57


Lesson 2 The Basics Discovering Object Oriented DataFlex

Object | Object Toolbox

Figure 54

Notice the positioning of the


objects. We will change it later
but for now let us see how the
program runs with this object
structure

Figure 55

58 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Generating Code

Application | Generate

Figure 56

[ OK

Figure 57

Data Access Corporation 59


Lesson 2 The Basics Discovering Object Oriented DataFlex

[ OK

[ OK (again for next


dialog)

Figure 58

[ Compile after Generate

[ OK

[ OK to overwrite

[ OK to complete

Figure 59

60 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Application | Exit

Figure 60

Data Access Corporation 61


Lesson 2 The Basics Discovering Object Oriented DataFlex

Running a New Program

File | Run a DataFlex


Program

Type: Test

[ OK

Figure 61

View | Test Program

Figure 62

62 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

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

Note that the program starts in the


Yearly Summary Object instead of
General Ledger Object

Also note, when in the


GL_Accounts Object, the Memo
Object disappears!
Figure 63

NAVIGATION KEYS
Tab Next item
Shift Tab Back item
F6 Switch
Shift F6 Switch Back

Record | Exit

[ OK

Note: The Actual column is blue


because the DisplayOnly entry
option is used on this field.
Figure 64

Data Access Corporation 63


Lesson 2 The Basics Discovering Object Oriented DataFlex

Development | Auto
Definition Utility

Figure 65

Application | Open

Figure 66

64 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

[ Ledger

Figure 67

Data Access Corporation 65


Lesson 2 The Basics Discovering Object Oriented DataFlex

Object Toolbox (correcting navigation problems)

Object | Object Toolbox

Figure 68

Before making our first correction


we need to learn about another
Class and a Framework rule.

Remember we described Classes


as tools. The Data_Set Class gives
database services (finds, clears,
saves and deletes of the records).
A Framework rule requires that we
create a Data Set Object for every
open file. Since we are using
another file, we need another data
set object for the GL_Accts file.
Figure 69

66 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Object | New | DataSet

Figure 70

[ OK

Since GL_ACCTS is the only


other file used it is defaulted into
the entry window, but F4 prompt
is available to list other related
files.

Figure 71

Data Access Corporation 67


Lesson 2 The Basics Discovering Object Oriented DataFlex

Notice: The Data_Set of a Parent


file comes before the Data_Set of a
Child file.

These Data Sets are the tools that


will service the Data Entry Objects
(Forms, Editors) for finds, clears,
saves, & deletes.

Figure 72

To solve the problem of keeping the memo object on top, we nest it inside the GL_Account Form.

ww Memo editor (by


holding down the right
mouse button)

Drag & Drop it in the box to


the right of GL_Accounts

When dropping in the box to the


right, your cursor must be inside
the [ ] box.
Figure 73

68 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Notice that the editor is now


indented (Nested) to the
GL_Accounts Form

Figure 74

Data Access Corporation 69


Lesson 2 The Basics Discovering Object Oriented DataFlex

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

Verify the object structure


is correct

Figure 76

70 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Application | Generate

[ OK

[ OK

Figure 77

[ Compile after
generation

[ OK

[ OK to overwrites

Figure 78

Data Access Corporation 71


Lesson 2 The Basics Discovering Object Oriented DataFlex

Application | Exit

Figure 79

File | Run a DataFlex


program

Type: Test

[ OK

Figure 80

72 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

View | Test Program

Figure 81

Enter Test Data (see next


page)

Get acquainted with some


of the Accelerator Keys

KEY OPERATION
F2 Save
Shift F2 Delete
F7 F8 F9 Prev/Next/Find
Figure 82 F5 Clear
F6 Switch

Data Access Corporation 73


Lesson 2 The Basics Discovering Object Oriented DataFlex

Some of the Accelerator Keys


(such as F2 and Shift+F2) will
display a popup confirmation.

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.

Enter Test Data:


or create your own records!
(make at least one record for each of the types; Assets, Liabilities, and Capital)
(press F2 to save each record) Do not create Yearly Summary records at this time.
CURRENT
GL# TYPE DESCRIPTION BALANCE MEMO
100 A Petty Cash (pocket cash) 500
105 A Check Book 3000 Account #01-11121112
110 A Savings Account 3500 Account #02-45454545
120 A Computer Equipment 5000
130 A Vehicle - 1990 Chev Truck 5000 bought Jul 1994,
Vehicle ID JE23-431xs
180 A House 95000 bought Nov 1989
new roof Sept 1992
210 L Charge Cards 4500
280 L Mortgage - House 43000 1st National Mortgage Co. 233-1111
310 C Owner’s Net Worth 64500

74 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Creating Selection Lists (Prompts)


Our next task will be adding a Selection List (a prompt which displays a list of GL account records
from which to choose).

Return to DFAuto

Application | Open

Ledger

Figure 84

Object | New | Prompt List

Figure 85

Data Access Corporation 75


Lesson 2 The Basics Discovering Object Oriented DataFlex

Fill in the form

Remember prompts (F4)


are available on File and
Index windows

[ OK

Figure 86

Field | Field Toolbox

Figure 87

76 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

w GL_Accts fields from


the toolbox

Position and resize the


object

Add column headings and


lines

If you need to redraw


borders select Edit |
Redraw Border
Figure 88

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.

[ GL# field in the


GL_Accounts form

F4 (for entry options)

Move to prompt window

F4 & select GL_List

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).

Data Access Corporation 77


Lesson 2 The Basics Discovering Object Oriented DataFlex

Generate the code

Figure 90

Run the program

Notice: the prompt is only


available from the GL#
window

Figure 91

78 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Connecting Prompts at Item level & Object level


We will be disconnecting our prompt at the item level and re-connecting it at the object level.

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.

Return to DFAUTO &


Open the Ledger
Application

[ GL# field

F4

Move to prompt window

F4 select None (uparrow)


Figure 92
[ OK

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.

Data Access Corporation 79


Lesson 2 The Basics Discovering Object Oriented DataFlex

Click on the Ledger object

Object | Style

move to prompt window

F4 select GL_List

[ OK

Figure 93

Generate the new code

Run the program and


verify that the prompt
works in all windows of the
GL object

Figure 94

80 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

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

• Bring up DFAuto and create a NEW application, called TypeEnt,


TypeEnt
using TYPE as the main file

• Add an Entry Form object (resize and center the object)


Namethe Entry Form Object TypeEnt

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.

• Fields | New Field Toolbox

• Create and place the two fields

FIELD
FIELD NAME TYPE LENGTH
Code ASCII 1
Description ASCII 20

Figure 95

Data Access Corporation 81


Lesson 2 The Basics Discovering Object Oriented DataFlex

• Create Indexes, from the pull-down (Database | Index)


(to leave press E or use the System icon)
INDEX # SEGMENTS UPPER CASE
1 Code Yes
2 Description Yes

• Add entry options FIELDS OPTIONS


Code CapsLock
AutoFind

• 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

• Save / Compile & Generate Code as a View test program.

• 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)

Note All the built in feature:


• Mouse Support
• Auto Validate_Save
• Auto Validate_Delete
Figure 96
• Easily created Selection Lists
• Auto Validates on Data_Loss
(smart enough to know changes exist)
• Much more yet to come ...

82 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 2 The Basics

Did You Discover?:


2 - 1. What utility(ies) will allow you to create a file?

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.

For answers, see “Lesson 2 - Discover Answers” page 265

Data Access Corporation 83


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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.

Topics in this Chapter:

• The Big Picture

• Procedural Programming vs Object Oriented Programming

• Connecting Views

• Loading a file from a .DEF file

• Sibling Files in DFAuto

• Loading Images with DFAuto

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 85


Lesson 3 Code Changes Discovering Object Oriented DataFlex

The Big Picture

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ö

// Standard Action Bar using Main_Menu Macro //BackGnd.PKG


/Main_Menu
______ ____ ____ ________ ____
/View_Pull_Down

/*

Create_Menu Main_Menu Location 1 0 Absolute


Set Action_Bar_Keys_Msg To Main_Menu_Keys
...
End_Menu

// Define Accelerator Keys (Hot keys) support


Procedure Main_Menu_Keys For Desktop Integer Act_Obj
On_Key KEY_ALT+KEY_R Send Activate To (Record_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_V Send Activate To (View_Pull_Down(Act_Obj)) Private
...
On_Key KEY_ALT+KEY_1 Send Activate_Employee_Entry to Desktop Private
On_Key KEY_ALT+KEY_2 Send Activate_TimeCard_Entry to Desktop Private
//PRAbout.VW to Desktop Private
On_Key KEY_ALT+KEY_3 Send Activate_TimeCard_Entry
... //Employee.DS
End_Procedure //Employee.VW
use Employee.DS //Empl.SL
use Empl.SL

Use PRAbout //Employee.DS


Use Employee.VW
//TimeCard.VW
use Employee.DS
Use TimeCard.VW use TimeCard.DS //TimeCard.DS
Use Report1.VW use Empl.SL
...
//Empl.SL
//Report1.VW
use Employee.DS //Employee.DS
Start_Ui (Main_Menu(Current_Object)) // starts the program

At this point the user interface is started and the


activate message is sent to the Main_Menu object,
which paints the image on screen making it the top
image and gives the focus to this object.

86 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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.

Note: The USE command assumes a .PKG extension, if no extension is given.

Data Access Corporation 87


Lesson 3 Code Changes Discovering Object Oriented DataFlex

Application Development Tasks:

1. Create your user interfaces

2. Define your data files & database rules


These rules will be accomplish in Lesson 10.
In future versions of DataFlex a new more powerful class
will be available called a Data_Dictionary class)

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.

88 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Procedural Programming vs Object Oriented Programming

There are many similarities between Procedural and Object Oriented programming. Let’s look at an
example of both:

Procedural Code Object Oriented Code

• Enter Macro is very similar to Entry_Form Objects

Enter Empl Object My_Form is an Entry_Form


... ...
... ...
EnterEnd End_Object

• Gosub Label_name is similar to Send message_name

gosub Calc_it Send Calc_it

• Subroutines are similar to Procedures and Functions

Calc_it: Procedure Calc_it


... ...
Return End_Procedure

Data Access Corporation 89


Lesson 3 Code Changes Discovering Object Oriented DataFlex

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.

Let’s look at the file Test.SRC.

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.

(We’ll discuss the Activate_View command in Lesson 8)

90 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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

Add_test "Ledger Program..." Send Activate_LEDGER to desktop


Add_test "Type Program..." Send Activate_TYPEENT to desktop
type in the code additions
// add_test command will add text to the pull down

Use LEDGER.VW
Use TYPEENT.VW
// use command will bring in View code

Start_Ui (Main_Menu(Current_Object))

Data Access Corporation 91


Lesson 3 Code Changes Discovering Object Oriented DataFlex

File | Save as
MyTest.SRC

Run | Run(and compile)


or Alt+G

Figure 98

Test that each view


activates

Record | Exit

Figure 99

92 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Loading a file from a .DEF file

.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.

Sample copy of a .DEF

-----------------------------------------------------------------------------
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

INDEX# FIELDS DES U/C LENGTH LEVELS SEGMENTS MODE


------ --------------- --- --- ------ ------ -------- -------
1 TRANS# NO NO 6 2 2 ON-LINE
DETAIL# NO NO
2 GL# NO NO 8 2 3 ON-LINE
TRANS# YES NO
RECNUM NO NO

Data Access Corporation 93


Lesson 3 Code Changes Discovering Object Oriented DataFlex

Database | File Definition


Utility

Figure 100

Def | Load .DEF

Figure 101

94 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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

Data Access Corporation 95


Lesson 3 Code Changes Discovering Object Oriented DataFlex

Verify that Relationships


are correct

This means opening the


related parent files to
verify that rules 2 & 3 are
followed

Remember F7 & F8 switches


between files and the status bar
displays the active file.
Figure 104

File | Exit

[ Yes

Figure 105

96 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Sibling Files in DFAuto

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

Data Access Corporation 97


Lesson 3 Code Changes Discovering Object Oriented DataFlex

Loading Images with DFAuto

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

Object | Load Text

Figure 106

Table (F4 = prompt)

“Strip Graphics” checkbox will


strip the Border and any other
graphics characters from the
image.

Figure 107

98 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Trans.IMG

[ OK

Figure 108

[ OK

Figure 109

Data Access Corporation 99


Lesson 3 Code Changes Discovering Object Oriented DataFlex

Move the Table to the


bottom of the screen

Notice the underscores in this


imported image are thinner then
the underscores in our objects
above. This is because there is no
file.field associated with these
positions. If the Trans_Dtl file
was available in DFAuto, we
would go to the Field | Field
Toolbox and drag the fields to
Figure 110 their corresponding position.

Generate, but do not


compile (since there are no
fields placed in the new
object, our code will not
operate correctly)

Application | Exit

Figure 111

100 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Development | Program
Development System

Ledger.VW

complete the code


modifications below

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.

Data Access Corporation 101


Lesson 3 Code Changes Discovering Object Oriented DataFlex

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.

102 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

//********************************************************************************
// 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

// Data Set Class Inclusions

//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

Use GL_ACCTS.SL // Selection list for File: GL_ACCTS

Activate_View Activate_LEDGER For LEDGER_View

Object LEDGER_View is an Entry_View_Client No_Image ;


Action_Bar (Main_Menu(Current_Object))

// Define Default Confirmation Messages


Set Verify_Save_MSG to GET_Save_Confirmation
Set Verify_Delete_MSG to GET_Delete_Confirmation
Set Verify_Data_Loss_MSG to GET_Data_loss_Confirmation
Set Verify_Exit_MSG to GET_Exit_loss_Confirmation

Object GL_ACCTS_DS is a GL_ACCTS_Data_Set No_Image


End_Object // GL_ACCTS_DS

Object YR_HIST_DS is a YR_HIST_Data_Set No_Image ;


Updating (GL_ACCTS_DS(Current_Object))

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

Object TRAN_DTL_DS is a TRAN_DTL_Data_Set No_Image ;


Updating (GL_ACCTS_DS(Current_Object)) (TRAN_HDR_DS(Current_Object))

Set Constrain_File to GL_ACCTS.file_number // covered in Lesson 4


End_Object // TRAN_DTL_DS

/GL_Accounts_EF_Image
┌─ General Ledger Accounts: ───────────┐
│ GL# ___. Type _ │
│ │
│ ___________________________________ │
│ │
│ Current Balance ______.__ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────┘
/Memo_EC_Image
┌─ Memo: ────────────────────────────┐
│ │

Data Access Corporation 103


Lesson 3 Code Changes Discovering Object Oriented DataFlex

│ │
│ │
│ │
│ │
│ │
└────────────────────────────────────┘
/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
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
│ __/__/____ _ ______.__ _______________________________________________ │
└───────────────────────────────────────────────────────────────────────────┘
/*

Object GL_Accounts_EF is an Entry_Form GL_Accounts_EF_Image Using (GL_ACCTS_DS(Current_Object))

Set Location to 2 0 Relative

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

Object Memo_EC is a Entry_Client Memo_EC_Image

Set Location to 6 1 Relative

Object Memo_TW is a Text_Window for GL_ACCTS.MEMO


Set Location to 1 2 Relative
Set Size to 6 34
End_Object // Memo_TW

End_Object // Memo_EC

End_Object // GL_Accounts_EF

Object Yearly_Summary_EF is an Entry_Form Yearly_Summary_EF_Image ;


Using (YR_HIST_DS(Current_Object))

Set Location to 2 40 Relative


Set Object_Color to 41 32

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 }

104 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Entry_Item YR_HIST.ACTUAL_04 { DisplayOnly }


Entry_Item YR_HIST.BUDGET_05 { AutoClear }
Entry_Item YR_HIST.ACTUAL_05 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_06 { AutoClear }
Entry_Item YR_HIST.ACTUAL_06 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_07 { AutoClear }
Entry_Item YR_HIST.ACTUAL_07 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_08 { AutoClear }
Entry_Item YR_HIST.ACTUAL_08 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_09 { AutoClear }
Entry_Item YR_HIST.ACTUAL_09 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_10 { AutoClear }
Entry_Item YR_HIST.ACTUAL_10 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_11 { AutoClear }
Entry_Item YR_HIST.ACTUAL_11 { DisplayOnly }
Entry_Item YR_HIST.BUDGET_12 { AutoClear }
Entry_Item YR_HIST.ACTUAL_12 { DisplayOnly }
End_Item_List

End_Object // Yearly_Summary_EF

Object Transactions_TBL is a Table Transactions_TBL_Image ;


Using (TRAN_DTL_DS(Current_Object)) by Index.2

Set Location to 17 2 Relative

// Properties you might need to set. These reverse the default settings.
// Remove what you do not need.

// Set wrap_state to TRUE // keeps NEXT within table


// Set child_table_state to TRUE // DAF - Saves when exit object
// Set Auto_Fill_State to TRUE // bug work-around (set in data-set)

// Set Auto_Regenerate_State to TRUE // Faster, only if lists stay in order.


// Set Allow_Top_Add_State to TRUE // Allow additions to top of table.
// Set Allow_Bottom_Add_State to FALSE // No additions to bottom.
// Set Allow_Insert_Add_State to FALSE // No insertions in table.
// Set Init_From_top_State to FALSE // Fill from end of database -
// Set Initial_Row to FILL_FROM_BOTTOM // Fill from bottom of table.

// Define Default Confirmation Messages


Set Verify_Save_MSG to GET_NO_Confirmation
Set Verify_Delete_MSG to GET_NO_Confirmation
Set Verify_Data_Loss_MSG to GET_NO_Confirmation
Set Verify_Exit_MSG to GET_NO_Confirmation

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

Data Access Corporation 105


Lesson 3 Code Changes Discovering Object Oriented DataFlex

File | Save

Our editor is capable of opening


multiple files. To jump between
them, select File | Pick. Having
multiple files open at the same
time is very convenient, since
there are numerous files in every
application.

Figure 113

File | Open
TypeEnt.VW

Make Modification

Add Use ACCT.DS and File | Save


Comment out Type.DS

Figure 114

106 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

File | Open
Mytest.SRC

Alt+G

If you have compilation errors,


select File | Pick to jump to the
needed file.

Figure 115

Note: We must always Compile the .SRC file NOT the .VW or .DS files.

Run & test program

Do not enter data into the table


(Lab 3 will create a view to enter
transaction records). The table
was created for viewing only!
Modifications in future lessons
will ensure that no data entry is
allowed in the table.

Figure 116

Data Access Corporation 107


Lesson 3 Code Changes Discovering Object Oriented DataFlex

File | Exit

Figure 117

108 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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.

• Create these three objects with single borders and no titles.

TYPE OF OBJECT OBJECT FOR FILE /BY


NAME INDEX FIELDS TO PLACE
Form (entry_form) Header Tran_Hdr.Trans#
Tran_Hdr.Date
Tran_Hdr.Explanation
Table Detail TRAN_DTL GL_Accts.GL#
Index 2 GL_Accts.GL_Description
Tran_Dtl.DC
Tran_Dtl.Amount
Form (entry_form) Totals Tran_Hdr.Total_Debits
Tran_Hdr.Total_Credits

Remember: You must open


related files before all the
fields will be displayed in the
field toolbox. (Database |
Open | Related)

Figure 118

Data Access Corporation 109


Lesson 3 Code Changes Discovering Object Oriented DataFlex

• Add the following FILE.FIELD ENTRY OPTION


Entry options: Tran_Hdr.Trans# AutoFind
GL_Accts.GL# AutoFind
GL_Accts.GL_Description NoEnter
Tran_Dtl.DC Capslock
Tran_Hdr.Total_Debits NoEnter
Tran_Hdr.Total_Credits NoEnter

• Object | Object
Toolbox and make
the necessary
changes/additions

To create Tran_Hdr
Data Set select:
Object | New |
Data_Set

• Save / Generate (do not compile)


(no test data will be entered at this time)

110 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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

// Data Set Class Inclusions

//Use GL_ACCTS.DS
//Use TRAN_HDR.DS
//Use TRAN_DTL.DS
Use Acct.DS

Activate_View Activate_JOURNAL For JOURNAL_View

Object JOURNAL_View is an Entry_View_Client No_Image ;


Action_Bar (Main_Menu(Current_Object))

Data Access Corporation 111


Lesson 3 Code Changes Discovering Object Oriented DataFlex

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.

• Modify Ledger view by changing the GL_Accts.TYPE to Type.Code

Object GL_Accounts_EF is an Entry_Form GL_Accounts_EF_Image Using (GL_ACCTS_DS(Current_Object))

Set Location to 2 0 Relative This will stop the


Set Auto_Clear_DEO_State to False // will not clear after save clearing on saves,
Item_List but it will also
Entry_Item GL_ACCTS.GL# { AutoClear, AutoFind, ;
IPrompt=(GL_List_SL(Current_object)) }stop it on deletes.
Entry_Item TYPE.CODE { AutoFind, Capslock, ;
IPrompt=(GL_List_SL(Current_object)) }
We will correct
Entry_Item GL_ACCTS.GL_DESCRIPTION { AutoClear, ; this in lesson 5.
IPrompt=(GL_List_SL(Current_object)) }
Entry_Item GL_ACCTS.CURRENT_BALANCE { AutoClear, ;
IPrompt=(GL_List_SL(Current_object)) }
End_Item_List

112 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

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.

Set Application_name to "Accounting" // this is useful for the help system

//************************* create backdrop ***************************

Use BackGnd // Standard background and title...creates object


Send Paint_Desktop to (Background(Current_Object)) ;
"Personal Accounting System" // You set the title

//************************* create main menu ***************************

/Main_Menu
______ ____ ____ ________ ____
/View_Pull_Down
┌─────────────────────────────┐
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
├─────────────────────────────┤
│ ___________________________ │
└─────────────────────────────┘
/*
Create_Menu Main_Menu Location 1 0 Absolute

Set Action_Bar_Keys_Msg To Main_Menu_Keys


Right justification of
the Alt shortcut Keys
#INCLUDE RECDE_PD.INC
is accomplished by
On_Item "View" Begin_Pull_Down View_Pull_Down
On_Item "Ledger
adding “\a”.
\aAlt+1" Send Activate_Ledger to desktop
On_Item "Journal \aAlt+2" Send Activate_Journal to desktop
On_Item "TypeEnt \aAlt+3" Send Activate_TypeEnt to desktop
On_Item "Close \aF3" Send Exit_Function
End_Pull_Down

#INCLUDE TXTW_PD.INC
#INCLUDE NAVI_PD.INC
#INCLUDE HELPA_PD.INC // modified help pulldown. Includes about.

End_Menu

// Hot key support


Procedure Main_Menu_Keys For Desktop Integer Act_Obj
On_Key KEY_ALT+KEY_R Send Activate To (Record_Pull_Down(Act_Obj)) Private

Data Access Corporation 113


Lesson 3 Code Changes Discovering Object Oriented DataFlex

On_Key KEY_ALT+KEY_V Send Activate To (View_Pull_Down(Act_Obj)) Private


On_Key KEY_ALT+KEY_T Send Activate To (Text_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_N Send Activate To (Navigate_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_H Send Activate To (Help_Pull_Down(Act_Obj)) Private
//
On_Key KEY_ALT+KEY_1 Send Activate_Ledger to Desktop Private
On_Key KEY_ALT+KEY_2 Send Activate_Journal to Desktop Private
On_Key KEY_ALT+KEY_3 Send Activate_TypeEnt to Desktop Private
//
End_Procedure

//************************* View Packages/Objects ***************************

Use MyAbout.PKG // about - Send about


Use Ledger.VW // View title 1 - Send Activate_Ledger to Desktop
Use Journal.VW // View title 2 - Send Activate_Journal to Desktop
Use TypeEnt.VW // View title 3 - Send Activate_TypeEnt to Desktop

Start_Ui (Main_Menu(Current_Object)) // start the program

• Save As Mainprog.SRC

• Compile, Run, & Test

114 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 3 Code Changes

Did You Discover?


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.)

3 - 2. Which utility will create a new .DEF file?

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?

For answers, see “Lesson 3 - Discover Answers” page 266

Data Access Corporation 115


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

L esso n 4
DEOs And DSOs
This lesson divides classes into their two major groups. Describing the most important features in
both.

Topics in this Chapter:

• Differences between DEOs and DSOs

• Object Nesting

• Constraint Blocks

• Linking DEOs to DSOs

• Connecting DSOs to DSOs

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 117


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

Differences between DEOs and DSOs

Computer glossaries are full of acronyms. Here are two new ones: DEOs and DSOs.

Entry_Form Data Entry Objects, (DEOs) are any objects


that allow data entry, such as Entry_Forms,
Tables, Edits, Text_Windows, etc.
DEO = Data Entry Object
Table
Text_Window

Data Set Objects, (DSOs), are objects that Data_Set

act as an interface between the database files


and the Data Entry Objects. They are objects DSO = Data Set Object
built from the Data_Set class or any of the
subclasses built directly from this important Customer_DSO
OrderHdr_DSO
class.

118 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 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.

Object Entry_View_1 is an Entry_View_Client

Object Customer_DS1 is a Customer_Data_Set No_Image


End_Object // Customer_DS1

Object Customer_EF1 is an Entry_Form


Using (Customer_DS1(current_Object))
...
End_Object // Customer_EF1

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.

Reasons for nesting DEOs:


• Navigation
• Delegation of Messages (This will be discuss in another lesson.
Think of it for now as the handling of a message)

* Note: DataFlex Application Framework (or framework) is the methodology / guidelines for
writing object oriented DataFlex applications.

Data Access Corporation 119


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

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.

Sample File Structure:

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

120 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

Does Not need a Constraint


Here we do not wish to limit the
viewing of child records to only
the children of the found parent
record.

If we did constrain the Employee


file, then after finding this record
all other finds on any employee
indexes would only find Tech
Employee records.

Figure 120

Data Access Corporation 121


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

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.

Object Emp_DS is a Empl_Data_Set

Begin_Constraints
Constrain EMPL relates to DEPT
End_Constraints

// the three lines above can be substituted as:


// Set Constrain_File to Dept.file_number

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

122 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

You might be thinking . . . Hey, this sounds great, but I want to change these constraints on the fly in
my running program!

Methods of accomplishing this:


⇒ use a global variable
⇒ use a property (properties will be explained in Lesson 5)

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.

Standard Constraint Block:

Begin_Constraints
Constrain Customer.State EQ "FL"
End_Constraints

Constraint Block using a global variable. Good Method:


Integer Limit_View //global variable

...
Begin_Constraints
If Limit_View Constrain Customer.State EQ "FL"
End_Constraints

Constraint Block using a property (explained in Lesson 5) Better Method


Property integer Limit_View public False
...
Begin_Constraints
Local Integer LimitIt
Get Limit_View to LimitIt
If LimitIt 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.

Data Access Corporation 123


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

Linking DEOs to DSOs

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

Object Customer_EF is an Entry_Form Customer_EF ;


Using (Customer_DSO(current_object))

Object memo is an Edit // here there is no need for a Using clause


End_Object // if left off children objects will inhert the parent's server

End_Object

124 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

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!

***** Code Available = DSO.SRC *****


Correct Data_Set Linkage:
...
Object DSO1_View is an Entry_View_Client
DEOs Using the Same DSO
If I find Sally Smith’s record in
Object Empl_DS is a Empl_Data_Set No_Image
End_Object // Empl_DS Entry_Form Object 1, Entry_Form
Object 2 will also show Sally Smith!
Object EmplA1_EF is an Entry_Form ;
Using (Empl_DS(current_Object)) Both Objects are using the same DSO,
...
End_Object // EmplA1_EF1
and both will display the same record.
Object EmplB1_EF is an Entry_Form ;
Using (Empl_DS(current_Object))
...
End_Object // EmplB1_EF

End_Object // DSO1_View

***** Code Available = DSO.SRC *****


Incorrect Data_Set Linkage
DEOs Using Different DSO
...
If the objects are using different DSOs, then Object DSO2_View is an Entry_View_Client
each will work independently of the other. Object Empl1_DS is a Empl_Data_Set No_Image
Finding a record in one object will not affect End_Object // Empl_DS
the other. Object Empl2_DS is a Empl_Data_Set No_Image
End_Object // Customer_DS2

Object EmplA2_EF is an Entry_Form ;


Using (Empl1_DS(current_Object))
...
End_Object // EmplA2_EF1

Object EmplB2_EF is an Entry_Form ;


Using (Empl2_DS(current_Object))
...
End_Object // EmplB2_EF

End_Object // DSO2_View

Data Access Corporation 125


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

Connecting DSOs to DSOs

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.

File Relationship Structure

Dept Ins_Group Ret_401K

Employee

Relate Relate
Constraint Constraint

History Time Card

126 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

Data-Set Structure:
Object Dept_DS is a Dept_Data_Set no_image
End_Object

Object Ins_Group_DS is a Ins_Data_Set no_image


End_Object

Object Ret_401K_DS is a 401K_Data_Set no_image


End_Object

Object Empl_DS is a Empl_Data_Set no_image ;


Updating (Dept_DS (current_object)) ;
(Ins_Group_DS (current_object)) ;
(Ret_40-1K_DS (current_object))
End_Object

Object Payroll_History_DS is a Payroll_History_Data_Set no_image ;


Updating (Empl_DS (current_object))

Begin_Constraints
Constrain PayHist Relates to Empl
End_Constraints

End_Object

Object Timecard_DS is a Timecard_Data_Set no_image ;


Updating (Empl_DS (current_object))

Begin_Constraints
Constrain Timecard Relates to Empl
End_Constraints

End_Object

Steps to Create a Data Set Structure:

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.

Data Access Corporation 127


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

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

128 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

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

Object GL_ACCTS_DS is a GL_ACCTS_Data_Set


End_Object GL_ACCTS_DS

Object TRAN_HDR_DS is a TRAN_HDR_Data_Set


End_Object // Tran_Hdr_DS TRAN_HDR_DS

Object YR_HIST_DS is a YR_HIST_Data_Set


YR_HIST_DS

End_Object // Yr_Hist_DS

Object TRAN_DTL_DS is a TRAN_DTL_Data_Set


TRAN_DTL_DS

// End_Constraints
End_Object // Tran_Dtl_DS

Object GL_Accounts_EF is an Entry_Form

Object Memo_EC is an Entry_Client


// Nested child DEOs will GL_Accounts_EF
// use the DSO of the parent
// if using clause ommited Memo_EC
Object Memo_TW is a Text_Window
End_Object // Memo_TW Memo_TW
End_Object // Memo_EC

End_Object // GL_Accounts_EF

Object Yearly_Summary_EF is an Entry_Form


Yearly_Summary_EF
End_Object // Yearly_Summary_EF

Object Transaction_TBL is a Table


Transaction_TBL
End_Object // Transaction_TBL

End_Object // Transactions_View

Data Access Corporation 129


Lesson 4 DEOs & DSOs Discovering Object Oriented DataFlex

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

Object GL_ACCTS_DS is a GL_ACCTS_Data_Set


GL_ACCTS_DS
End_Object

Object TRAN_HDR_DS is a TRAN_HDR_Data_Set


TRAN_HDR_DS
End_Object // Tran_Hdr_DS

Object TRAN_DTL_DS is a TRAN_DTL_Data_Set


TRAN_DTL_DS

End_Object // Tran_Dtl_DS

Object Header_EF is an Entry_Form


Header_EF

Object Totals_EF is an Entry_Form Totals_EF


// Nested child DEOs will
// use the DSO of the parent
// if using clause ommited
End_Object // Totals_EF

End_Object // Header_EF

Object Detail_TBL is a Table


Detail_TBL
End_Object // Detail_TBL

End_Object // Transactions_View

130 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 4 DEOs and DSOs

Did You Discover?:


4 - 1. Constraint Blocks can be coded in all objects. True or False

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?

Object OrdHead is an Entry_Form OrdHead_Image ; Customer OrdType


Using (_____________(current_object)) File File
Item_List
Entry_Item OrdHead.Order_Number
Entry_Item OrdHead.Date
Entry_Item OrdType.Code
Entry_Item Customer.Customer_Number
Entry_Item Customer.Name OrdHead
End_Item_List File
End_Object

Object OrdDetail_Table is a Table ;


Using (OrdDetail_DSO(current_object)) Constrained
...
End_Object

OrdDetail
File

For answers, see “Lesson 4 - Discover Answers” page 270

Data Access Corporation 131


Discovering Object Oriented DataFlex Lesson 5 Messages

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.

Topics in this Chapter:

• Procedures and Functions

• Forwarding and Delegating

• Reading Online Documentation

• Augmenting

• Canceling

• Overriding

• Adding (creating)

• Accelerator Keys (On_Key command)

• 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.

Data Access Corporation 133


Lesson 5 Messages Discovering Object Oriented DataFlex

Procedures and Functions

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.

Event Message Sent triggers other messages

Pressing Sends
F2 key Request_Save Procedure Request_Save
Which Sends
other messages

Defaulting to the Current_Object

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

Directing to a specific object

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))

134 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

New Terms:

Current_Object and the Focus Object are often confused, mainly because they are often the same.

• Focus Object is the object that the user is interacting with.

• 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.

Data Access Corporation 135


Lesson 5 Messages Discovering Object Oriented DataFlex

Forwarding and Delegating

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:

1. Look within the current object

2. Forward the message (forward the message up the inheritance path, through classes)

3. Delegate the message (pass the message to the parent object)


(delegation does not happen automatically in other OOP languages. DataFlex’s default is to
automatically delegate)

Found within the current_object:


use UI

...
Object MyBackground is an Entry_Client

Object Employee_DS is a Data_Set


End_Object // Employy_DS

Object My_Client is an Entry_View_Client

Object My_EntryForm is an Entry_Form Message Request_Clear sent


On_Key Key_Alt+Key_C send Request_Clear

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

136 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

Found within a Class (though Forwarding):

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

Object My_EntryForm is an Entry_Form


On_Key Key_Alt+Key_C send Request_Clear
Object Class
UI_Object Class
Procedure Request_Clear
Send Bell Menu Class
End_Procedure
...
Entry Class
End_Object //My_Entry_Form Entry
Object My_Table is a Table
...
End_Object //My_Table
End_Object // MyClient Message Bell sent
End_Object // MyClient

Start_UI MyClient

Note: Normally a message is resolved in the first two steps

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.

Data Access Corporation 137


Lesson 5 Messages Discovering Object Oriented DataFlex

Reading Online Documentation

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

138 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

Click on Drives and


select the drive
where your CD is
installed

Open the DACDOC


\ DF31 folder

Select UIMS
Ref.PDF file

Figure 122

If Index to
Messages is not
expanded then click
on the icon

scroll down and


select Bell
message

Figure 123

Data Access Corporation 139


Lesson 5 Messages Discovering Object Oriented DataFlex

Bell icon will show


us that the Bell
message is
described in the
Object Class

Clicking on the
Object icon will
switch us to the
page where the bell
message is
described.

Figure 124

140 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

use UI

Object MyBackground is an Entry_Client

Object Employee_DS is a Data_Set


End_Object // Employy_DS

Object My_Client is an Entry_View_Client

Object My_EntryForm is an Entry_Form


On_Key Key_Alt+Key_C send Request_Clear

// Procedure Request_Clear //If Request_Clear was removed Where


// Send Bell // would the message be resolved (found)?
// End_Procedure
...
End_Object //My_Entry_Form

Object My_Table is a Table


...
End_Object //My_Table
End_Object // MyClient

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? ________________

Data Access Corporation 141


Lesson 5 Messages Discovering Object Oriented DataFlex

This time we’ll send a message that will not be found!


The message waltz: 1 2 3, 1 2 3, 1 2 3, Error! OR
Check current_object, Forward, Delegate;
Check current_object, Forward, Delegate;
Check current_object, Forward, Delegate; Error

Step 1D Runtime Error!


Step 2C
Message ### send to Desktop Forwarding
not resolved Object Class
UI_Object Class
// Desktop
Step 3C use UI Message Class
Delegation Entry_Client Class
Object MyBackground is Entry_Client
Step 1C Step 2B
current_object Forwarding
Object Employee_DS is a Data_Set Object Class
End_Object // Employee_DS
UI_Object Class
Step 3B
Delegation Object My_Client is an Entry_View_Client Message Class
Entry_Client Class
Step 1B Entry_View_Client Class
current_object Object My_EntryForm is an Entry_Form
On_Key Key_Alt+Key_C send Do_It
Step 2A
... Forwarding
Object Class
Step 3A End_Object //My_Entry_Form
Delegation UI_Object Class
Object My_Table is a Table
Procedure Do_it Menu Class
Step 1A ...
End_Object //My_Table
Entry Class
current object Entry_Form Class
End_Object //My_Client

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.

142 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

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

Data Access Corporation 143


Lesson 5 Messages Discovering Object Oriented DataFlex

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

Adding (creating) a Message


The above methods alter pre-existing procedures. Adding a message is creating a totally new
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

144 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

Accelerator Keys (On_Key command)

On_Key key_name send message {to object} {private}


Stops child objects
from inheriting

Messages may not


have arguments

Accelerator key function name


or a
physical key combination

Accelerator Key Functions:

On_Key Kcancel Send Exit_Application // request_cancel is normally sent on kcancel


// this command added to low level class
// (such as FORM & EDIT) will allow you
// to exit the program by pressing cancel
On_Key Kuparrow Send Previous

Physical Keys: (three Prefixes Key_Alt+ Key_Ctrl+ Key_Shift+)

On_Key Key_Shift+Key_P Send Print_it

On_Key Key_Alt+Key_V Send Activate to ((View_Pull_Down)(Act_obj)) Private

Note: Children will inherit accelerator keys (just like messages) through normal delegation unless
the Private option is used.

Data Access Corporation 145


Lesson 5 Messages Discovering Object Oriented DataFlex

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

Set_Timer My_clock periodic Background_title Update_time 6000

When to send message


Timer Name that 1/100 of second
you assign
Message 6000 = 60 seconds
Type:
to send
Periodic
One_shot
Idle Receiving
Timer_Delete Object of the
message

146 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

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.

Three basic types are


• Full
• Name_Object
• Current_Object

Sample Code used to demonstrate Access methods:


Use UI

Object Payroll_View is an Entry_View_Client

Object Empl_Form is an Entry_Form


Object Empl_Comments is a Text_Window
End_Object
End_Object

Object Time_Card_Table is a Table


End_Object

End_Object //Cust_View
...

Full Access Method:


This method involves listing the full nesting structure of the objects. Using this method is lengthy and
not used very often.

Send Calc_It to (Empl_Form(Payroll_View(Desktop)))

This command is read: Send Calc_it to Empl_Form child of Payroll_View child of the Desktop

Data Access Corporation 147


Lesson 5 Messages Discovering Object Oriented DataFlex

Name_Object Access Method:


You may see this method if you look at old code, so we will briefly cover it, but its use is NOT
recommended. The Name_Object commands describe the nesting of the objects. If these are incorrect,
a runtime error will occur when the message is sent.

...
// 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

Current_Object Access Method:


We finally come to the access method that we strongly recommend you use!

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.

If the current_object is Empl_Comments, here is what would happen:

• Empl_comments do you have a child called Empl_Form? No, then delegate


• Empl_Form do you have a child called Empl_Form? No, then delegate
• Payroll_View do you have a child called Empl_Form? Yes, then return the Object ID
• Send Calc_It to Object ID

Send Calc_It to (Empl_Form(Current_Obect))

148 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

Comparing Access Methods:

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? __________________________________

Could Empl_Form send the message: Send do_it to (Time_Card_Table(current_object))?

______________________________________________________________________

Could Time_Card_Table send the message: Send do_it to (Empl_Comment(current_object))?

______________________________________________________________________

Sample Code used to demonstrate Access methods:


Use UI

Object Payroll_View is an Entry_View_Client

Object Empl_Form is an Entry_Form


Object Empl_Comments is a Text_Window
End_Object
End_Object

Object Time_Card_Table is a Table


End_Object

End_Object //Cust_View
...

Data Access Corporation 149


Lesson 5 Messages Discovering Object Oriented DataFlex

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

150 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

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.

• We are (augmenting/overriding/canceling/adding) the Row_Save & Request_Delete messages.


Object GL_Accounts_EF is an Entry_Form GL_Accounts_EF_Image Using (GL_ACCTS_DS(Current_Object))

Set Location to 2 0 Relative


Set Auto_Clear_DEO_State to False // will not clear after save

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

...

Data Access Corporation 151


Lesson 5 Messages Discovering Object Oriented DataFlex

...

Object Transactions_TBL is a Table Transactions_TBL_Image ;


Using (TRAN_DTL_DS(Current_Object)) by Index.2

Set Location to 17 2 Relative

Set Allow_Bottom_Add_State to FALSE // No additions to bottom.

// Define Default Confirmation Messages


Set Verify_Save_MSG to GET_NO_Confirmation
Set Verify_Delete_MSG to GET_NO_Confirmation
Set Verify_Data_Loss_MSG to GET_NO_Confirmation
Set Verify_Exit_MSG to GET_NO_Confirmation

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:

• Open the Journal View in an Editor

• Within the Detail_TBL object add this procedure:

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:

• Open the TypeEnt view in an editor

• 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.

152 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 5 Messages

• Save / Compile Mainprog.SRC / Run & Test

Data Access Corporation 153


Lesson 5 Messages Discovering Object Oriented DataFlex

Did You Discover?:


5 - 1. Can you see an advantage of coding the On_Key command using Accelerator Key Function
names over Physical Key names?

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

5 - 4. If the accelerator key Kdownarrow is Object MyTableis a Table


used in object MyTable will the
On_Key Kdownarrow Send Print_Label
Print_Label procedure shown be
executed? Will it be executed if Procedure Print_Label
...
Kdownarrow is used in MyEdit End_Procedure
Object? Object MyEdit is an Edit
...
End_Object // MyEdit

End_Object // MyTable

For answers, see “Lesson 5 - Discover Answers” page 272

154 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 6 Procedures Functions & Properties

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.

Topics in this Chapter:

• Properties

• Entry Options (Ientry, Iexit & Ivalidate)

• Procedures

• Functions

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 155


Lesson 6 Procedures Functions & Properties Discovering Object Oriented DataFlex

Properties (Set & Get commands)

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.

Syntax: Set property_name {of object}{item item_number} to value {value 2 ...}

Get property_name {of object}{item item_number} to return_value


DFAuto was setting properties for you such as ...
Local String app_name
Location, and Application_Name. ...
Set Application_Name to “Ledger”
If we leave off the {of object }, it will default to ...
the current_object. Get Application_Name to app_name

Object Property Example:


Many times we wish to send a message when exiting or entering an object. Two properties which
trigger these messages are entry_msg and exit_msg.
Object My_Form is an Entry_Form ...
...
Set Entry_msg to Do_enter
Set Exit_msg to Do_exit

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

Item Property Example:


An important item property is Value. Items are zero-based, so the second item is referenced as item 1.
/payroll
Employee # _____
Old Salary ______ New Salary ______
/*
...

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

*Lesson 7 will be showing many item level properties

156 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 6 Procedures Functions & Properties

Entry Options (Ientry, Iexit & Ivalidate)

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.

AutoCreate Entry Options are:


AutoBack Back up a window on left arrow
AutoClear Clear the window if new data is entered
AutoFind Find EQ a record automatically
AutoFind_GE Find GE a record automatically
AutoReturn Advance to next window on a full window
Capslock Uppercase all data in window
DisplayOnly No entry and no put to record buffer
ForcePut Force data from window to record buffer
FindReq Found indicator must be true to continue
NoEnter Entry of data to window not allowed
NoPut No put of data to record buffer
points= n Decimal points set to (0 1 2...n)
Required Requires an entry
Retain Keep data in window (clearable)
RetainAll Keep data in window (not clearable)
SkipFound Skip entry if found indicator is true
Iprompt= VIA the prompt key pops-up listed object
Izoom= VIA the zoom key pops-up listed object
Other entry options that can be manually added:
Range= Numeric or Date Entry must be within specified range
Check=”” Alpha Entry must match substring of specified string
Thousands Inserts commas in numbers fields

These entry options give us the ability to send a message at the item level.

ENTRY OPTION TRIGGERS THE MESSAGE RETURNING A NON-ZERO


Ientry before entering an item stops item entry
Iexit before exiting an item stops item exiting
Ivalidate on forward navigation and stops forward navigation or the save
when saving

Syntax: { ientry=msg_procedure_name }
{ iexit=get_function_name }

Data Access Corporation 157


Lesson 6 Procedures Functions & Properties Discovering Object Oriented DataFlex

***** Ioptions.SRC *****


...

/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

Procedure Default_Dep // on Entering Default to one if blank


Local Integer Dependents
Get Value Item 2 to Dependents
If Dependents EQ "" Begin
Set Value Item 2 to 1
Set Item_Changed_State Item 2 to True
End
End_Procedure

Procedure Calc_Age // on Exiting birthday, calc age


Local Integer Age
Local Date Today Birthday
Sysdate Today
Get Value Item 3 to Birthday
Calc ((Today - Birthday) / 365) to Age
Set Value Item 4 to age
Set Item_Changed_State Item 4 to True
End_Procedure

Function Check_Age // Validate Age is less then 100


Local Integer Age // note we are allowed to shift tab off this window
Get Value Item 4 to Age
If Age GT 100 Function_Return 1
Else Function_Return 0
End_Function

End_Object // Empl_EF

End_Object // EMPL_View

158 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 6 Procedures Functions & Properties

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

Send procedure_name {to (object_name (current_object))} arg1 ... argN to value

Procedure Authorize
If user_ID EQ "SUPERVISOR" send Activate to System_EF
End_Procedure
...

Data Access Corporation 159


Lesson 6 Procedures Functions & Properties Discovering Object Oriented DataFlex

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

Get function_name {of (object_name (current_object))} arg1 ... argN to value

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!

160 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 6 Procedures Functions & Properties

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.

Function Long_Year Date In_Date Returns _______


If In_Date LT 01/01/100 Begin
// If 2 digit year is > 49 default year to 19xx
// If 2 digit year is <= 49 default year to 20xx
If In_Date GT 12/31/49 Calc (In_date + 01/01/1900) to In_Date
Else Calc (In_Date + 01/01/2000) to In_Date
End
Function_Return __________
End_Function

Data Access Corporation 161


Lesson 6 Procedures Functions & Properties Discovering Object Oriented DataFlex

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))

Set Location to 2 0 Relative


Set Auto_Clear_DEO_State to False // will not clear after save
segment of code
Function Save_Header Returns integer
Local Integer NewRec Changed Srvr Oldmsg available in
// we must temporarily shut off the save verify message
// we keep track of the old message so we can restore it.
ChildEnt.INC file
Get verify_save_msg to oldmsg
Set verify_save_msg to Get_No_Confirmation
// request_save_no_clear does a save without clearing
send request_save_no_clear
set verify_save_msg to oldmsg
// we now need to determine if the save was successful.
// current_record property is 0 there was nothing to save
// should_save will still be true if the save failed
Get Server to Srvr // object_id of data_set
Get Current_Record of Srvr to NewRec // if 0, its a new record
Get Should_Save to changed // If true, changes exist, save is needed
If (NewRec=0 or changed) Begin
Error 300 "Create & Save Parent Record First"
Function_Return 1 // no record or save failed, disallow entry
End
Else ;
Function_Return 0 // an old unchanged record, allow entry
End_Function

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
...

Object Yearly_Summary_EF is an Entry_Form Yearly_Summary_EF_Image ;


Using (YR_HIST_DS(Current_Object))

Set Location to 2 40 Relative


Set Object_Color to 41 32
Set Auto_Clear_DEO_State to False // will not clear after save
Set Auto_Fill_State to TRUE // if record exist it will display it

Procedure Activate Returns Integer


Local Integer Rval
Get Save_Header of (GL_Accounts_EF(current_object)) to Rval
If Rval EQ 0 Forward Get Msg_Activate to Rval
Procedure_Return Rval
End_Procedure

• Save / Compile Mainprog.SRC/ enter Test data below

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.

162 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 6 Procedures Functions & Properties

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.

Based on constrained Child to Parent DSO Structure:


In a DEO serviced by In a DEO serviced by
Operation Parent File-GL_Accts Child File - Yr_Hist Operation Flows
Saves (F2) Saves only Parent Saves Both Saves Propagate Up
Clears (F5)
Deletes (Shift+F2)

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

Data Access Corporation 163


Lesson 6 Procedures Functions & Properties Discovering Object Oriented DataFlex

• Open Journal view in an editor

• Modify the code as shown

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))

Set Location to 2 10 Relative


Set Auto_Clear_DEO_State to False // we will not want the header clearing when saving

Function Save_Header Returns integer


Local Integer NewRec Changed Srvr Oldmsg segment of code
// we must temporarily shut off the save verify message available in
// we keep track of the old message so we can restore it .
Get verify_save_msg to oldmsg ChildEnt.INC file
Set verify_save_msg to Get_No_Confirmation
// request_save_no_clear does a save without clearing
send request_save_no_clear
set verify_save_msg to oldmsg
// we now need to determine if the save was successful.
// current_record property is 0 there was nothing to save
// should_save will still be true if the save failed
Get Server to Srvr // object_id of data_set
Get Current_Record of Srvr to NewRec // if 0, its a new record
Get Should_Save to changed // If true, changes exist, save is needed
If (NewRec=0 or changed) Begin
Error 300 "Create & Save Header Record First!"

Function_Return 1 // no record or save failed, disallow entry


End
Else ;
Function_Return 0 // an old unchanged record, allow entry
End_Function

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

Object Detail_TBL is a Table Detail_TBL_Image Using (Tran_Dtl_DS(Current_Object)) by Index.1

Set Location to 8 10 Relative

// Called when entering the table. Checks with the header to see
// if it is saved. If not, disallow entry

164 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 6 Procedures Functions & Properties

//
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.

Set wrap_state to TRUE // keeps NEXT within table


Set child_table_state to TRUE // DAF - Saves when exit object
// Set Auto_Fill_State to TRUE // bug work-around (set in data-set)

// Set Auto_Regenerate_State to TRUE // Faster, only if lists stay in order.


// Set Allow_Top_Add_State to TRUE // Allow additions to top of table.
// Set Allow_Bottom_Add_State to FALSE // No additions to bottom.
// Set Allow_Insert_Add_State to FALSE // No insertions in table.
// Set Init_From_top_State to FALSE // Fill from end of database -
// Set Initial_Row to FILL_FROM_BOTTOM // Fill from bottom of table.

// Define Default Confirmation Messages


Set Verify_Save_MSG to GET_Save_Confirmation
Set Verify_Delete_MSG to GET_Line_Delete_Confirmation

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

TRANS# DATE DESCRIPTION GL# D/C AMOUNT


100 01/15/1996 Weekly Groceries 105 C 95
515 D 95
101 01/20/1996 Mortgage Payment 105 C 600
180 D 100
580 D 500

Total Debit & Credit fields will be updated in the Lesson on Data_Set Classes.

Data Access Corporation 165


Lesson 6 Procedures Functions & Properties Discovering Object Oriented DataFlex

Did You Discover?:


6 - 1. Can Procedures or Functions pass arguments?

6 - 2. Global Variables can usually be replaced with ___________?

For answers, see “Lesson 6 - Discover Answers” page 274

166 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

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.

Topics in this Chapter:

• Images Zero-Based

• Hard Coded Item Number

• Item# Reference

• Entry_Name_Item Reference

• Defaulting Current_Item

• Referencing Items outside the Current_Object

• Table Item Reference - Base_Item

• Entry_Default

• Sub_Page

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 167


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

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____

____2___ ___3_____ ___4____

____5___

____6____

168 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

Hard Coded Item Number


Hard coding the item number is one method of referencing the item.

Payroll Example 1:
Use Allentry
Open Payroll

/Payroll_Screen
=====================================

Hours * Rate = Pay


___.__ ___.__ ______.__

=====================================
/*

Object Payroll is an Entry_Form Payroll_Screen


Item_List
Entry_Item Payroll.Hours
Entry_Item Payroll.Rate
Entry_Item Payroll.Pay { ientry=msg_Calc_Pay }
End_Item_List

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

Data Access Corporation 169


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

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 ______

Hours * Rate = Pay


___.__ ___.__ ______.__

=====================================
/*

Object Payroll is an Entry_Form Payroll_Screen

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

Procedure Calc_Pay Integer Item#


//the value of 3 is placed in the variable item# (zero based)
Local Number Hours Rate Pay
Get Value Item (Item# -2) to Hours
Get value Item (Item# -1) to Rate
Calc ( Hours * Rate ) to Pay
Set Value Item Item# to Pay
Set Item_Changed_State Item Item# to True
End_Procedure

End_Object

170 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

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 ______

Hours * Rate = Pay


___.__ ___.__ ______.__

=====================================
/*

Object Payroll is an Entry_Form Payroll_Screen

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

Data Access Corporation 171


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

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

172 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

Referencing Items outside the Current_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

Data Access Corporation 173


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

Table Item Reference - Base_Item


If we take our Payroll example and turn it into a table, we will find that using the current item that is
passed on ientry, iexit and ivalidate still works fine, but hard coding a number into the procedure will
NOT. There are times that you will need to have access to the table items and you will not be given the
current_item. This is when Base_Item is needed. Base_item will tell you the item number of the first
column of the active row. If we need an item from another column, we just offset base_item to gain
access to the other columns.

Payroll Example:
use allentry
open payroll
...
/payroll_screen
=====================================
Hours * Rate = Pay
___.__ ___.__ ______.__
___.__ ___.__ ______.__
___.__ ___.__ ______.__
___.__ ___.__ ______.__
___.__ ___.__ ______.__
=====================================
/*

Object Payroll is a Table Payroll_Screen


Begin_Row
entry_item payroll.hours
entry_item payroll.rate
entry_item payroll.pay { ientry=msg_calc_pay }
End_Row

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

174 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

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.

Using custom defaults from an ientry:


Use Allentry
Open Payroll
...
/Payroll_Screen
=============================================
Date Empl# Hours * Rate = Pay
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
=============================================
/*

Object Payroll is a Table Payroll_Screen


Begin_Row
Entry_Item Payroll.Date {ientry=default_Date }
Entry_Item Payroll.Empl#
Entry_Item Payroll.Hours
Entry_Item Payroll.Rate
Entry_Item Payroll.Pay { ientry=msg_Calc_Pay }
End_Row

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.

Data Access Corporation 175


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

Using predefined Entry_Defaults procedure:

Use Allentry
Open Payroll
...
/Payroll_Screen
=============================================
Date Empl# Hours * Rate = Pay
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
__/__/__ ____ ___.__ ___.__ ______.__
=============================================
/*

Object Payroll is a Table Payroll_Screen


Begin_Row
Entry_Item Payroll.Date //{ientry=Default_Date }
Entry_Item Payroll.Empl#
Entry_Item Payroll.Hours
Entry_Item Payroll.Rate
Entry_Item Payroll.Pay { ientry=msg_Calc_Pay }
End_Row

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.

176 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

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.

Sub_Page command has two main uses:


• changing the default navigation around the image
• allows you to break down a single image into multiple images.

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 ____
============================================
/*

Object Customer is an Entry_Form Customer_Image

Set Object_Color to 112 112


Set location to 5 10 relative

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

Note:Sub_Page is on-based not zero-based

Data Access Corporation 177


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

Changing Default Navigation:

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_
============================================
/*

Sub_Page New_Customer from Customer_Image 1 3 4 6 2 5

Object Customer_Client is an Entry_Client Customer_Image


// add a client and
// move these object properties to the client
Set Object_Color to 112 112
Set location to 5 10 relative

Object Customer is an Entry_Form New_Customer

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

178 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

Breaking apart a single image:

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________

11____ 12_______ 13___________


14____ 15_______ 16___________
17____ 18_______ 19___________
20____ 21_______ 22___________

================================================
/*
//**************** fill in the blanks below **************************

//Sub_Page partial_image From Full_image Horizontal Start# # of Windows


Sub_Page Customer_Image from big_image horizontal ___ ___

//Sub_Page partial_image From Full_image Vertical Start# # of Windows


Sub_Page Phone_Image from big_image vertical ___ ___

//Sub_Page partial_image From Full_image Rectangular Start# Row# Column#


Sub_Page Accounts_Image from big_image rectangular ____ ____ ____

Object My_Client is an Entry_Client ___________ // full_image here


// add a client and
// move these object properties to the client
Set Object_Color to 112 112
Set location to 5 10 relative

Object Customer is an Entry_Form ____________________


Item_List
entry_item customer.number
...
End_Item_List
End_Object

Object Phones is a Picture_Form ___________________


...
End_Object

Object Accounts is a Table ___________________


...
End_Object

End_Object

Note: When using Vertical and Rectangular options, all column items must start in the same
position.

Data Access Corporation 179


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

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:

• Open the Journal View in an editor.

• 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

...

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, ;
iValidate=get_validate_key_field }
Entry_Item TRAN_HDR.DATE { AutoClear }
Entry_Item TRAN_HDR.EXPLAINATION { AutoClear }
End_Item_List

• Save/Compile & Test

180 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

• 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

...

Object Header_EF is an Entry_Form Header_EF_Image Using (TRAN_HDR_DS(Current_Object))

...

Procedure Default_Date integer item#


Local Date __________
Get Value ___________ _________ to __________
If _______ EQ "" Begin
Sysdate ____________
Calc (_________ + 01/01/1900) to _________
Set Changed_Value _______ ________ to _________
End
End_Procedure

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

• Save / Compile & Test

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.

Data Access Corporation 181


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

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.

• Add the Ck_Year Procedure & the Long_Year function

• Add { Iexit=msg_Ck_Year } Entry_Option

• 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

...

Object Header_EF is an Entry_Form Header_EF_Image Using (TRAN_HDR_DS(Current_Object))

...

Procedure Ck_Year Integer Item#


Local Date Ck_Date
Get Value Item Item# to Ck_Date
Get Long_Year Ck_Date to Ck_Date // here we pass date in Ck_Date and also return it to Ck_Date
Set Changed_Value Item Item# to Ck_Date
End_Procedure

Function Long_Year Date In_Date Returns Date


If In_Date LT 01/01/100 Begin
If In_Date GT 12/31/49 Calc ( In_Date + 01/01/1900 ) to In_Date
Else Calc ( In_Date + 01/01/2000 ) to In_Date
End
Function_Return In_Date
End_Function

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
...

182 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 7 Image Manipulation

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.

• Make Modifications as shown

...
Object Header_EF is an Entry_Form Header_EF_Image;
Using (Tran_HDR_DS(current_object))

Set Location to 2 0 Relative


...
Item_List
Entry_Item TRAN_HDR.TRANS# { AutoClear, AutoFind }
Entry_Name_Item T_Date## TRAN_HDR.DATE { AutoClear, ;
Ientry=msg_Default_Date ;
Iexit=msg_Ck_Year }
Entry_Item TRAN_HDR.EXPLANATION { AutoClear }
End_Item_List segment of code available
in Refresh.INC file
...
Procedure Set Item_Options_DisplayOnly Integer Item# Integer state
File | Include
// two things were passed the item# which in our case T_Date## =2
// and state which is Crnt (true if non_zero & false if o)
Set Item_Option Item Item# to NoPut State
Set Item_Option Item Item# to NoEnter State
End_Procedure

// If transaction header exist, disallow entry in date window


Procedure Refresh Integer mode
Local Integer Srvr# Crnt
Get Server to Srvr# // get the data_set ID
Get current_record of Srvr# to Crnt // get record in data_set
// Set DisplayOnly to Crnt (is true if non_zero)
// DisplayOnly = Noput & NoEnter
//Date## has already been defined by entry_name_item
Set Item_Options_DisplayOnly T_Date## Crnt
Forward Send Refresh mode // do normal refresh
// Don't leave us sitting on a DisplayOnly window
If ((Crnt and Current_item(current_Object)) EQ T_Date##) Send Next
End_Procedure

...

End_Object // Header_EF

...

• Save/Compile & Test

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.

Data Access Corporation 183


Lesson 7 Image Manipulation Discovering Object Oriented DataFlex

Did You Discover?:


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

For answers, see “Lesson 7 - Discover Answers” page 276

184 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Reporting

Data Access Corporation 185


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

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!

Topics in this Chapter:

• Entry Item & Standard Item Classes

• Creating Buttons

• Creating Checkboxes and Radios

• Creating Messages and Forms

• Creating Selection Lists and Pick Lists

• Using DFAuto to its FULLEST!

• Activate_View Command

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 187


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

Entry Item & Standard Item Classes

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:

// Entry Items supports entry options

Entry_Item [file.field | variable | expression] {entry options}

// Standard Items are used to send a message when selected

On_Item {value {message to send {to dest_object}}}

188 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

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
__________ ________________ ___________________
/*

Object My_Button is a Button Button_Image

On_Key _______________________ Send ______________________

Item_List
// What to Display: What to Send:
On_Item ___________________ ______________________
On_Item ___________________ ______________________
On_Item ___________________ ______________________

End_Item_List

Procedure Print_Label
...
End_Procedure

End_Object

Data Access Corporation 189


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

Creating Checkboxes and Radios


Checkbox and Radio Classes are selection devices. Checkbox are normally used for multi-selection
and Radio for single selection. If you check your Class Inheritance tree, you will also find a CheckList
and a RadioList class which utilizes a scrollbar that allows scrolling in the display.

Checkboxes use square braces [ ] for deselected


[X] for selected

Radios use parentheses ( ) for deselected


(•) for selected

Note: The default appearance of the checkbox and radios can be changed by running DFRun
DFConfig.

190 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

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.

***** Code Available = RadTest.SRC *****


Use UI

/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

Object Marital_Status is a Radio


Item_List
On_Item "Single " send process_status
On_Item "Married " send process_status
On_Item "Divorced " send process_status
On_Item "Widowed " send process_status
End_Item_List

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.

Data Access Corporation 191


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

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

192 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

Creating Messages and Forms


Classes at the top of the Class inheritance tree are referred to as low level classes (fewer abilities) and
as they are subclassed more and more they are referred to as high level classes. One common mistake
is using a high level class when a low level class would work better.

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
┌─────────────────────────────────┐
│ │
│ ___________________________ │
│ │
└─────────────────────────────────┘
/*

// message stays on screen until the user presses a key


Object My_Message is a Message
set location 20 10 absolute
set center_state item 0 to true
set value item 0 to "No Deletions Allowed"
End_Object

Form Example:
Use UI

/Which_Dept
┌────────────────────────────────────────┐
│ │
│ Print Labels for which Dept? ____ │
│ │
└────────────────────────────────────────┘
/*

Object Which_Dept is a Form


On_Item
On_Item "" send Print_Label
End_Item_List

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

Data Access Corporation 193


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

Creating Selection Lists and Pick Lists


DFAuto allows us to build objects from six major classes. This may look limiting at first, but when we
require an object outside DFAuto’s capabilities, many times we can create a similar object using
DFAuto and then modify it manually, saving much time and effort. Selection_Lists and Pick_Lists are
a perfect example.

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:

Selection Lists displays data from a ______________.

Pick Lists displays _____________data.

Note: Popup is a property that can be set in many classes. This means many classes can act like a
popup.

194 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

Using DFAuto to its FULLEST!


If we need a prompt for marital status (Single, Married, Divorced, or Widowed), we would create a
selection list in DFAuto and then modify the code, changing the object to a Pick_List. Since there are
only four static selections in the Pick_List, the image created in DFAuto should only have 4 lines.
When in DFAuto placing any field that is approximately the same length in your image will also save
time when converting to a pick list.

Selection List to  Pick List


Use Sellist

Use Sellist /Marital_SL_Image


┌──────────────┐
/Marital_SL_Image │ ________ │
┌──────────────┐ │ ________ │
│ ________ │ │ ________ │
│ ________ │ │ ________ │
│ ________ │ └──────────────┘
│ ________ │ /*
└──────────────┘
/* Object Marital_SL is a Selection_List ;
Marital_SL_image popup ;
Object Marital_SL is a Selection_List ; Main_File CODES by recnum
Marital_SL_image popup ; for Account.MStatus
Main_File CODES by recnum
Set Location to 5 16
Set Location to 5 16 Set Auto_Locate_State to true
Set Auto_Locate_State to true Set Auto_Index_State to true
Set Auto_Index_State to true Set Export_Item_State to true
Set Select_Mode to Auto_Select
Begin_Row
entry_item CODES.MSTATUS ____________
End_Row entry_item ACCOUNTS.GL#

______________________________

______________________________

______________________________

______________________________

____________________

End_Object

Look up Pick_List class in the online documentation

Change the code on the right to operate as a pick_list.


I’ve started the modification by adding a little extra room
for changes, and added some needed properties. Be
sure to cross out any unnecessary code.

Data Access Corporation 195


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

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
...

// Activate_View Command creates a procedure at the desktop

Procedure Activate_Ledger // placed on the desktop


// this procedure Activates the Ledger View
End_Procedure

196 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

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 ║
╠══════════════════════════╣
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
╚══════════════════════════╝
/*

Object GLTYPE_PL is a Pick_list GLTYPE_PL_image popup for GL_Accts.Type

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.

• Add Use Type.PL

Data Access Corporation 197


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

• 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.

• Also remove the Type_Ent view from the main program

• Save/ Compile & Test

198 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 8 Using Predefined Classes

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)

Data Access Corporation 199


Lesson 8 Using Predefined Classes Discovering Object Oriented DataFlex

Did You Discover?:


8 - 1. Create a 5 line program that contains an edit object. The online Documentation is there to
assist you!

8 - 2. Which Class is used as a container

8 - 3. Look up the property Checkbox_Item_State in the Reference Manual and discover the Defining
Class(es).

8 - 4. If I use the Checkbox_Item_State property in an Entry_Form, it would forward this property to


which class to be resolved?

For answers, see “Lesson 8 - Discover Answers page 281

200 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 9 Data Set Objects

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.

Topics in this Chapter:

• Data Set Objects

• Procedures Creating / Deleting/ Update / Backout

• Functions Validate_Save & Validate_Delete

• Procedures Save_Main_File & Delete_Main_File

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 201


Lesson 9 Data Set Objects Discovering Object Oriented DataFlex

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.

File Relationship Structure (child to parent) Dept Ins_Group Ret_401K

Employ

History Time Card

Data Set Structure (bi-directional)

Dept Ins_Group Ret_401K

Employ

History Time Card

202 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 9 Data Set Objects

Procedures Creating / Deleting/ Update / Backout


Data Sets handle the locking/rereading/unlocking of the file during the save and delete operations.
These procedures are our “hooks” to code in the needed tasks to be performed in the correct sequence
during these save and delete operations.

These procedures are always called in a locked state. Therefore so it is safe to access the record
buffers.

The events that call these Procedures are:

New Save Edit Save Delete

Procedure Procedure Procedure Procedure


Creating Update Backout Deleting

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.

Data Access Corporation 203


Lesson 9 Data Set Objects Discovering Object Oriented DataFlex

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.

204 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 9 Data Set Objects

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

Data Access Corporation 205


Lesson 9 Data Set Objects Discovering Object Oriented DataFlex

Functions Validate_Save & Validate_Delete

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

Function Validate_Save returns integer


Local integer rVal
If Invt.Qty LT 0 Begin
Error 301 "Insufficient Inventory on hand" // error message will occur after the unlock
Function_Return 1
End
Forward get Validate_Save to rVal
Function_Return rVal
End_Function

// before deleting employee record, check if needed for end of year taxes via an active field

Function Validate_Delete returns integer


Forward get Validate_Delete to rVal
If rVal <>0 function_return rVal // the delete has failed, no need to continue
If Customer.Status EQ "Y" begin
Error 302 "Cannot delete an Active Employee" // error will not show until unlock occurs
move 1 to rval // to stop the delete
End
Function_Return rval
End_Function

206 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 9 Data Set Objects

Procedures Save_Main_File & Delete_Main_File

These procedures by default performs a save/delete operation on the main_file. Intended to be


augmented or override.

// 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

Data Access Corporation 207


Lesson 9 Data Set Objects Discovering Object Oriented DataFlex

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.

• Open Both Views

• Replace constraint blocks with the Constrain_File property


Set Constrain_File to Parent.file_number
(this will make our code easier to read)

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

208 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 9 Data Set Objects

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.

• Open the Journal.VW


• Add the Yr_Hist_DS Object with the needed Creating Procedure.

...
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

Object YR_HIST_DS is a YR_HIST_DTL_Data_Set No_Image ;


Updating (GL_ACCTS_DS(Current_Object))
set constrain_file to GL_ACCTS.file_number

Procedure Creating
Forward Send Creating
Move(Mid(Tran_Hdr.Date, 4, 7)) to Yr_Hist.Year
End_Procedure

End_Object // YR_HIST_DS
...

• Save /Compile (will test in the next lesson)

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.

• Within DFFile Load the Sysfile.DEF file

Data Access Corporation 209


Lesson 9 Data Set Objects Discovering Object Oriented DataFlex

• 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)? __________

• Creating (new record saves)


________________________________________________________________________

TRAN_DTL
• Creating (new record saves)
________________________________________________________________________

• Update (new & edit saves)


________________________________________________________________________

________________________________________________________________________

• Backout (edit saves & deletes)


________________________________________________________________________

________________________________________________________________________

YR_HIST
• This creating procedure was just completed and added in the Journal view.

210 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 9 Data Set Objects

Did You Discover?:

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?

For answers, see “Lesson 9 - Discover Answers” page 283

Data Access Corporation 211


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

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.

Topics in this Chapter:

• Why create Sub-Classes

• Business Rules

• Class Structure

• Properties (creating)

Who could Skip?: Persons proficient in all lesson topics, although a quick review is suggested.

Data Access Corporation 213


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

Why create Sub-Classes

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.

// Package File EFSave.PKG


Class Entry_Form_Save is an Entry_Form
Procedure Construct_Object Integer Img
Forward Send Construct_Object Img
Set Auto_Save_State to True
End_Procedure
End_Class

Use_Allentry
Use Customer.DS
Use EFSave.PKG

Object Customer_DSO is a Customer_Data_Set No_Image


End_Object
Now all objects built from
/Customer_Form_Image our new class will save when
________________________ _________
/* leaving the last window.
Object Customer_Form is an Entry_Form_Save Customer_Form_Image
Set Location 5 10
Item_List
Entry_Item Customer.Name
Entry_Item Customer.Phone
End_Item_List
End_Object

ClearScreen

Start_UI (Customer_Form(current_object))

214 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

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.

Data Access Corporation 215


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

Class structure
Class sub_Class is a{n} Super_Class

Procedure Construct_Object { Integer image_name }


Forward Send Construct_Object { image_name }
// declare new properties
// initialize properties (with the SET command)
// define child objects (such as scroll_bar objects within list class)
// define accelerator keys / or modify them
End_Procedure

// Procedure & Functions are added here

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

Class EMPL_Data_Set is a Data_Set

Procedure Construct_Object integer Img


Forward Send Construct_Object Img
Set MAIN_FILE to EMPL.file_number
Set Smart_FileMode_State to TRUE
//To prevent deletion if child record records exist, uncomment the
//following lines and add your own client/child files.
//Set Cascade_Delete_State to FALSE
//Send Add_Client_File ????.File_Number // e.g. invoice.file_number
End_Procedure

// Create the most likely procedures and functions that will be


// required by data_set sub-classes. These are the hooks that you
// will need to create.

// Function Validate_Save - Called right before save. Return non-zero


// to stop the save.
//
//Function Validate_Save returns integer
//End_Function // Validate_Save

216 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

// Function Validate_delete - Called before delete. Return non-zero to


// stop the delete.
//
//Function Validate_Delete returns integer
//End_Function // Validate_Delete

// Procedure Update - Called during a save (new and edit)


//
//Procedure Update
//End_Procedure // Update

// Procedure Backout - Called during an edit save and a delete


//
//Procedure Backout
//End_Procedure // Backout

// Procedure Deleting - Called during a delete


//
//Procedure Deleting
//End_Procedure // Deleting

// Procedure Creating - Called when creating a new record


//
//Procedure Creating
//End_Procedure // Creating

// Procedure Destroying - Called when creating a new record if


// validate_save fails. Undo the effects of Creating.
//
//Procedure Destroying
//End_Procedure // Destroying

// Procedure Relate_Main_file - less likely to be used. Remember


// to send Request_Relate or Request_clear_File
//
//Procedure Relate_Main_File
//End_Procedure // Relate_Main_File

// Procedure New_Current_Record - less likely to be used. Sent whenever


// Current_Record property is changed.
//
//Procedure New_Current_Record Integer OldRecNum Integer NewRecNum
//End_Procedure // New_Current_Record

// Procedure Attach_Main_File - less likely to be used.


//
//Procedure Attach_Main_File
// Forward Send Attach_Main_File
//End_Procedure // Attach_Main_File

// 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

Data Access Corporation 217


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

Optimizing Saves and Deletes (Smart_FileMode_State)

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

Set Smart_FileMode_State to True

// add if any file is manually saved/deleted outside the DSO structure


// such as a sysfile in procedure creating then the following procedure is needed

// Procedure Reset_FileModes_for_Lock
// Forward Send Reset_FileModes_for_Lock
// File_Mode SysFile Default // the unrelated file
// End_Procedure

Disallow parent to be deleted if child records exist

Set Cascade_Delete_State to False


Send Add_Client_File OrderHea.File_Number

If you try to delete a parent record which has a related child records, this is the error that will be
generated:

“4140” (Cannot delete-related records exist)

218 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

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.

Data Access Corporation 219


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

Sample of creating a property:

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.

Class GL_Accts_Data_Set is a Data_Set


...
Procedure construct_object integer img#
forward send construct_object img#
set main_file to GL_Accts.file_number
:
property string old_key_id public 0
:
end_procedure

// This procedure is called whenever a new record is found


Procedure new_current_record integer oldrec# integer newrec#
Forward Send new_current_record oldrec# newrec#
Set old_key_id to myfile.key_field
End_Procedure

// This procedure is called whenever a record is saved


Function Validate_Save returns integer
Local String newid oldid
Local Integer rec# rval
Get Current_Record to rec#
Get Old_Key_ID to oldid // this is our new property!
// If an edit (existing record) and the key changed don't save
If (rec# <> 0 and myfile.key_field <> oldid) begin
Send operation_not_allowed 301 // custom error message
Function_Return 1
End
Forward get validate_save to rval
If rval function_return 1
End_Function

// 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

....

220 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

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

...

Entry_item Dept.Dept_code { AutoFind, iValidate=get_validate_key_field }

Note: The Validate_Key_Field is predefined

Data Access Corporation 221


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

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:

• Add Sysfile to DFFile. There is a Sysfile.DEF file in your ClassOOP subdirectory



• With an editor Open Acct.DS file. This file has been created for you with the basic class
structures copied for each file. All our unique business rules are shaded. Add them to your file.

Use ALLENTRY

Open GL_ACCTS
Open YR_HIST
Open TRAN_HDR
Open Tran_DTL
Open SYSFILE

//********************************************************************************
// Data Set Definition for GLACCTS
//********************************************************************************

Class GL_ACCTS_Data_Set is a Data_Set

Procedure Construct_Object integer Img


Forward Send Construct_Object Img
Set MAIN_FILE to GL_ACCTS.file_number
Set Smart_FileMode_State to TRUE
//To prevent deletion if child record records exist, uncomment the
//following lines and add your own client/child files.
Set Cascade_Delete_State to FALSE // parnets with child cannot be deleted
Send Add_Client_File YR_HIST.file_number
Send Add_Client_File TRAN_DTL.file_number
End_Procedure

End_Class

//********************************************************************************
// Data Set Definition for TRAN_HDR
//********************************************************************************

Class TRAN_HDR_Data_Set is a Data_Set

Procedure Construct_Object integer Img

222 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

Forward Send Construct_Object Img


Set MAIN_FILE to TRAN_Hdr.file_number
Set Smart_FileMode_State to True
Set Cascade_Delete_State to True // parents with child can be deleted
Send Add_Client_File TRAN_Dtl.File_Number
End_Procedure

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
//********************************************************************************

Class TRAN_DTL_Data_Set is a Data_Set

Procedure Construct_Object integer Img


Forward Send Construct_Object Img
Set MAIN_FILE to TRAN_DTL.file_number
Set Smart_FileMode_State to TRUE
End_Procedure

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
//********************************************************************************

Data Access Corporation 223


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

Class YR_HIST_Data_Set is a Data_Set

Procedure Construct_Object integer Img


Forward Send Construct_Object Img
Set MAIN_FILE to YR_HIST.file_number
Set Smart_FileMode_State to TRUE
End_Procedure

End_Class

• Save/Compile/Test changes by adding in test data

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.

224 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 10 Creating New Classes

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

• Add the Use VLD_Key command

• Add the entry Option on the Trans_Hdr.Trans# field, { ivalidate=get_validate_key_field}.

• Save\Compile\ & Test

Data Access Corporation 225


Lesson 10 Creating New Classes Discovering Object Oriented DataFlex

Did You Discover?:

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?

For answers, see “Lesson 10 - Discover Answers” page 284

226 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Lesson 11
Reporting
This lesson covers the new reporting classes and how to quickly create a report using the updated
DFQuery.

Topics in this Chapter:

• DFQuery & Reporting Classes

• DFQuery Chart of Accounts

• DFQuery Balance Sheet

• DFQuery Income Statement

• Chart of Accounts Modifications

• Balance Sheet Modifications

• Income Sheet Modifications

Who could Skip?: Persons proficient in all lesson topics. Although a quick review is suggested.

Data Access Corporation 227


Lesson 11 Reporting Discovering Object Oriented DataFlex

DFQuery & Reporting Classes

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

DFQuery Chart of Accounts

Database | Query
Database

Figure 125

228 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

[ 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.

Select GL# &


GL_Description to print

Figure 127

Data Access Corporation 229


Lesson 11 Reporting Discovering Object Oriented DataFlex

View | Output order

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

230 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

View | Parameters

Figure 130

Add title & width

Figure 131

Data Access Corporation 231


Lesson 11 Reporting Discovering Object Oriented DataFlex

Run | Screen

Figure 132

Note horizontal scrolling is


available

Figure 133

232 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

File | Generate

Figure 134

Printable report

Rep_COA

[ OK

Figure 135

Data Access Corporation 233


Lesson 11 Reporting Discovering Object Oriented DataFlex

File | Save as

Saving in this manner will create a


.QRY file, allowing us to return to
DFQuery and load/run the report
again. Although the generated
code that we will modify, is what
we will be using most of the time.

Figure 136

Chart

[ OK

Figure 137

234 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

DFQuery Balance Sheet

File | New

File | Open

Figure 138

GL_Accts

[ OK

When queries have been saved,


whenever the DataBase file is
selected again another screen
showing the available kept queries
will be displayed. Simply press
ESC to continue by this screen.

Figure 139

Data Access Corporation 235


Lesson 11 Reporting Discovering Object Oriented DataFlex

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

Select fields as indicated

Figure 140

236 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

View | Selections

Figure 141

/ GL#

[ < Less than

400

[ OK

Figure 142

Data Access Corporation 237


Lesson 11 Reporting Discovering Object Oriented DataFlex

Verify Selection is correct.

Figure 143

View | Output order

Figure 144

238 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

[ GL#

Figure 145

View | Parameters

Figure 146

Data Access Corporation 239


Lesson 11 Reporting Discovering Object Oriented DataFlex

Enter title & width

Figure 147

Run | Screen

Figure 148

240 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

File | Generate

Figure 149

Printable report

Rep_Bal

[ OK

Figure 150

Data Access Corporation 241


Lesson 11 Reporting Discovering Object Oriented DataFlex

DFQuery Income Statement

File | New

File | Open

Figure 151

Yr_Hist

[ OK

If you have been saving your


queries the query list will appear,
simply press ESC to by pass this
screen.

Figure 152

242 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

From the GL_ACCTS file


select fields:
GL#
GL_Description
From the YR_HIST file
select field:
Actual 04
Actual_04

Figure 153

Data Access Corporation 243


Lesson 11 Reporting Discovering Object Oriented DataFlex

View | Selections

Yr_Hist.GL#

>= (Greater then or equal)

400

[ OK

Figure 154

Yr_Hist.Year

= (equal)

1996

[ OK

Figure 155

244 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Verify the Selection is correct.

Figure 156

View | Order
GL#, -Year

The negative sign indicates the


year is descending order.

Figure 157

Data Access Corporation 245


Lesson 11 Reporting Discovering Object Oriented DataFlex

View | Parameters

Add title & width

Figure 158

File | Generate

Figure 159

246 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Printable report

Rep_Inc

[ OK

Figure 160

File | Exit

Figure 161

Data Access Corporation 247


Lesson 11 Reporting Discovering Object Oriented DataFlex

A Quick Look at what was generated:


This is a look at the 2nd report. Notice the two files. The .SRC (the one to compile) and the .RPT
which is similar to the .VW (view file).
// REP_BAL.src
// 03/06/96 23:08:49
// Balance Sheet Similar to a
//
//
QC-8
Test.SRC
// Program generated by DFQuery 3.1

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

GL# GL DESCRIPTION TYPE CURRENT BALANCE

/REP_BAL_Subheader1

____________________
/REP_BAL_Body Resident
____. ___________________________________ ____ ______.__
/REP_BAL_Total

Records printed = _______.


/*

/REP_BAL_Selection_Form
Select records by:
GL# less than ___.
/REP_BAL_Selection_Client
╔════════════════════════════════════════════════════════════════════════════╗
║ QC-8 ║
║ Balance Sheet ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*

Open GL_ACCTS Index.1

Number TDebits TCredits

Activate_View Activate_REP_BAL_Report for REP_BAL_Report

Object REP_BAL_Report is a Query_View No_Image


Object Report is a Standard_Report
Report_Main_File GL_ACCTS

248 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Report_Index By Index.1
Report_Breaks GL_ACCTS.TYPE

Set Constraint_Value 0 to "400" // GL_ACCTS.GL# LT

Begin_Constraints
Constrain GL_ACCTS.GL# LT (Constraint_Value(Current_Object,0))
End_Constraints

Procedure_Section Page_Top as REP_BAL_Header


Forward Send Page_Top
Send Update_Status_Page
Sysdate REP_BAL_Header.1
Print (Page_Count(Current_Object)) to REP_BAL_Header.2
Output_Pagecheck
End_Procedure

Procedure_Section Body as REP_BAL_Body


Forward Send Body
Print GL_ACCTS.GL#
Print GL_ACCTS.GL_DESCRIPTION
Print GL_ACCTS.TYPE
Print GL_ACCTS.CURRENT_BALANCE
Output_Pagecheck REP_BAL_Body
End_Procedure

Procedure_Section Total as REP_BAL_Total


Forward Send Total
Print TDebits
Print TCredits
Print (Rec_Count(Current_Object))
Output_Pagecheck
End_Procedure
End_Object

Object Selection_Client is a Query_Selection_Client REP_BAL_Selection_Client


Set Output_Selection_State to True

Object Selection_Form is a Query_Selection_Form REP_BAL_Selection_Form


Item_List
Repeat_Item 1 Times "" Send Next
End_Item_List
End_Object
End_Object
End_Object

Note: (prior DataFlex users) this structure is VERY similar to the Report Macro, even the report
breaks and subheader/subtotals.

Data Access Corporation 249


Lesson 11 Reporting Discovering Object Oriented DataFlex

Chart of Accounts Modifications

Modifications to the code are shown below:


• In this report we are adding some subheaders whenever the TYPE field changes.

// 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 ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*

Open GL_ACCTS Index.1

Activate_View Activate_REP_COA_Report for REP_COA_Report

Object REP_COA_Report is a Query_View No_Image


Object Report is a Standard_Report
Report_Main_File GL_ACCTS
Report_Index By Index.1
Report_Breaks GL_ACCTS.TYPE // When to break

Procedure_Section Page_Top as REP_COA_Header


Forward Send Page_Top
Send Update_Status_Page
Sysdate REP_COA_Header.1
Print (Page_Count(Current_Object)) to REP_COA_Header.2
Output_Pagecheck
End_Procedure

Procedure_Section Subheader1 as REP_COA_Subheader1


Forward Send Subheader1
If GL_ACCTS.TYPE EQ "A" Print "*** Assets ***" to REP_COA_Subheader1.1
If GL_ACCTS.TYPE EQ "L" Print "*** Liabilities ***" to REP_COA_Subheader1.1
If GL_ACCTS.TYPE EQ "C" Print "*** Capital ***" to REP_COA_Subheader1.1
If GL_ACCTS.TYPE EQ "I" Print "*** Income ***" to REP_COA_Subheader1.1
If GL_ACCTS.TYPE EQ "E" Print "*** Expenses ***" to REP_COA_Subheader1.1

250 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Output_Pagecheck REP_COA_Subheader1
End_Procedure

Procedure_Section Body as REP_COA_Body


Forward Send Body
Print GL_ACCTS.GL#
Print GL_ACCTS.GL_DESCRIPTION
Output_Pagecheck REP_COA_Body
End_Procedure

Procedure_Section Total as REP_COA_Total


Forward Send Total
Print (Rec_Count(Current_Object))
Output_Pagecheck
End_Procedure
End_Object

Object Selection_Client is a Query_Selection_Client REP_COA_Selection_Client


Set Output_Selection_State to True
End_Object
End_Object

Remember if you wish to compile this report, Compile Rep_COA.SRC not Rep_COA.Rpt.

Data Access Corporation 251


Lesson 11 Reporting Discovering Object Oriented DataFlex

Balance Sheet Modifications

Modifications to the code are shown below:

• We’ll want to create a break when GL_Accts.Type field changes

• We’ll need a Subheader and Subtotal Images and Sections

• 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

GL# GL DESCRIPTION TYPE CURRENT BALANCE

/REP_BAL_Subheader1

____________________
/REP_BAL_Body Resident
____. ___________________________________ ____ ______.__
/REP_BAL_Subtotal1
-----------
________.__
===========

/REP_BAL_Total
Total Debits Total Credits
________.__ ________.__
=========== ===========

Records printed = _______.


/*

/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

Activate_View Activate_REP_BAL_Report for REP_BAL_Report

252 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Object REP_BAL_Report is a Query_View No_Image


Object Report is a Standard_Report
Report_Main_File GL_ACCTS
Report_Index By Index.1
Report_Breaks GL_ACCTS.TYPE

Set Constraint_Value 0 to "400" // GL_ACCTS.GL# LT

Begin_Constraints
Constrain GL_ACCTS.GL# LT (Constraint_Value(Current_Object,0))
End_Constraints

Procedure_Section Page_Top as REP_BAL_Header


Forward Send Page_Top
Send Update_Status_Page
Sysdate REP_BAL_Header.1
Print (Page_Count(Current_Object)) to REP_BAL_Header.2
Output_Pagecheck
End_Procedure

Procedure_Section Subheader1 as REP_BAL_Subheader1


Forward Send Subheader1
If GL_ACCTS.TYPE EQ "A" Print "*** Assets ***" to REP_BAL_Subheader1.1
If GL_ACCTS.TYPE EQ "L" Print "*** Liabilities ***" to REP_BAL_Subheader1.1
If GL_ACCTS.TYPE EQ "C" Print "*** Capital ***" to REP_BAL_Subheader1.1
Output_Pagecheck REP_BAL_Subheader1
End_Procedure

Procedure_Section Body as REP_BAL_Body


Forward Send Body
Print GL_ACCTS.GL#
Print GL_ACCTS.GL_DESCRIPTION
Print GL_ACCTS.TYPE
Print GL_ACCTS.CURRENT_BALANCE
Output_Pagecheck REP_BAL_Body
End_Procedure

Procedure_Section Subtotal1 as REP_BAL_Subtotal1


Forward Send Subtotal1
Subtotal REP_BAL_Body.4
If GL_ACCTS.TYPE EQ "A" Add GL_ACCTS.CURRENT_BALANCE to TDebits
Else Add GL_ACCTS.CURRENT_BALANCE TO TCredits
Output_Pagecheck REP_BAL_Subtotal1
End_Procedure

Procedure_Section Total as REP_BAL_Total


Forward Send Total
Print TDebits
Print TCredits
Print (Rec_Count(Current_Object))
Output_Pagecheck
End_Procedure
End_Object

Object Selection_Client is a Query_Selection_Client REP_BAL_Selection_Client


Set Output_Selection_State to True

Object Selection_Form is a Query_Selection_Form REP_BAL_Selection_Form


Item_List
Repeat_Item 1 Times "" Send Next
End_Item_List
End_Object
End_Object
End_Object

Data Access Corporation 253


Lesson 11 Reporting Discovering Object Oriented DataFlex

Income Sheet Modifications


An income statement shows income and expense over a monthly time frame.

Modifications to the code are shown below:

• Break on GL_ACCTS.TYPE

• Debit and Credit Totals

• Indicate Net Loss or Net Gain

// 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

GL# TYPE YEAR ACTUAL 01

/REP_INC_Subheader1

_____________________
/REP_INC_Body Resident
____. ____________________________________ ____ ____. ______.__
/REP_INC_Subtotal1
-----------
________.__
===========
/REP_INC_Total
Total Debits Total Credits
________.__ ________.__
=========== ===========

Records printed = _______.


/*

/REP_INC_Selection_Form
Select records by:
YEAR equal to ___.
GL# greater than or equal to ___.
/REP_INC_Selection_Client
╔════════════════════════════════════════════════════════════════════════════╗
║ QC-8 ║
║ Income Statement ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
/*

254 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Open YR_HIST Index.1


Open GL_ACCTS

Number TDebits TCredits

Activate_View Activate_REP_INC_Report for REP_INC_Report

Object REP_INC_Report is a Query_View No_Image


Object Report is a Standard_Report
Report_Main_File YR_HIST
Report_Index By Index.1
Report_Breaks GL_ACCTS.TYPE

Set Constraint_Value 0 to "1996" // YR_HIST.YEAR EQ


Set Constraint_Value 1 to "400" // YR_HIST.GL# GE

Begin_Constraints
Constrain YR_HIST.YEAR EQ (Constraint_Value(Current_Object,0))
Constrain YR_HIST.GL# GE (Constraint_Value(Current_Object,1))
End_Constraints

Procedure_Section Page_Top as REP_INC_Header


Forward Send Page_Top
Send Update_Status_Page
Sysdate REP_INC_Header.1
Print (Page_Count(Current_Object)) to REP_INC_Header.2
Output_Pagecheck
End_Procedure

Procedure_Section Subheader1 as REP_INC_Subheader1


Forward Send Subheader1
If GL_ACCTS.TYPE EQ "I" Print "*** Income ***" to REP_INC_Subheader1.1
If GL_ACCTS.TYPE EQ "E" Print "*** Expenses ***" to REP_INC_Subheader1.1
Output_Pagecheck REP_INC_Subheader1
End_Procedure

Procedure_Section Body as REP_INC_Body


Forward Send Body
Print YR_HIST.GL#
Print GL_ACCTS.GL_DESCRIPTION
Print GL_ACCTS.TYPE
Print YR_HIST.YEAR
Print YR_HIST.ACTUAL_01
Output_Pagecheck REP_INC_Body
End_Procedure

Procedure_Section Subtotal1 as REP_INC_Subtotal1


Forward Send Subtotal1
Subtotal REP_INC_Body.5
If GL_ACCTS.TYPE EQ "E" Add GL_ACCTS.CURRENT_BALANCE to TDebits
Else Add GL_ACCTS.CURRENT_BALANCE TO TCredits
Output_Pagecheck REP_INC_Subtotal1
End_Procedure

Procedure_Section Total as REP_INC_Total


Forward Send Total
Print TDebits
Print TCredits
Print (Rec_Count(Current_Object))
Output_Pagecheck
End_Procedure
End_Object

Object Selection_Client is a Query_Selection_Client REP_INC_Selection_Client


Set Output_Selection_State to True

Object Selection_Form is a Query_Selection_Form REP_INC_Selection_Form


Item_List
Repeat_Item 2 Times "" Send Next
End_Item_List
End_Object
End_Object
End_Object

Data Access Corporation 255


Lesson 11 Reporting Discovering Object Oriented DataFlex

256 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

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

• Add the Modifications

• Save /Compile / Test


//======================================================================
// 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.

Set Application_name to "Accounting" // this is useful for the help system

//************************* create backdrop ***************************

Use BackGnd // Standard background and title...creates object


Send Paint_Desktop to (Background(Current_Object)) ;
"Personal Accouting System" // You set the title

//************************* create main menu ***************************

/Main_Menu
______ ____ _______ ____ ________ ____
/View_Pull_Down
┌─────────────────────────────┐
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
├─────────────────────────────┤
│ ___________________________ │
└─────────────────────────────┘
/Report_Pull_Down
┌─────────────────────────────┐
│ ___________________________ │
│ ___________________________ │
│ ___________________________ │
├─────────────────────────────┤
│ ___________________________ │
└─────────────────────────────┘
/*

Data Access Corporation 257


Lesson 11 Reporting Discovering Object Oriented DataFlex

Create_Menu Main_Menu Location 1 0 Absolute

Set Action_Bar_Keys_Msg To Main_Menu_Keys

#INCLUDE RECDE_PD.INC

On_Item "View" Begin_Pull_Down View_Pull_Down


On_Item "Ledger Alt+1" Send Activate_Ledger to desktop
On_Item "Journal Alt+2" Send Activate_Journal to desktop
On_Item "Type Codes Alt+3" Send Activate_TypeEnt to desktop
On_Item "Close F3" Send Exit_Function
End_Pull_Down

On_Item "Report" Begin_Pull_Down Report_Pull_Down


On_Item "Chart of Accounts Alt+4" Send Activate_Rep_COA_Report to desktop
On_Item "Balance Sheet Alt+5" Send Activate_Rep_Bal_Report to desktop
On_Item "Income Statement Alt+6" Send Activate_Rep_Inc_Report to desktop
On_Item "Close F3" Send Exit_Function
End_Pull_Down

#INCLUDE TXTW_PD.INC
#INCLUDE NAVI_PD.INC
#INCLUDE HELPA_PD.INC // modified help pulldown. Includes about.

End_Menu

// Hot key support


Procedure Main_Menu_Keys For Desktop Integer Act_Obj
On_Key KEY_ALT+KEY_R Send Activate To (Record_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_V Send Activate To (View_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_T Send Activate To (Text_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_N Send Activate To (Navigate_Pull_Down(Act_Obj)) Private
On_Key KEY_ALT+KEY_H Send Activate To (Help_Pull_Down(Act_Obj)) Private
//
On_Key KEY_ALT+KEY_1 Send Activate_Ledger to Desktop Private
On_Key KEY_ALT+KEY_2 Send Activate_Journal to Desktop Private
On_Key KEY_ALT+KEY_3 Send Activate_TypeEnt to Desktop Private
On_Key KEY_ALT+KEY_1 Send Activate_Rep_COA_Report to Desktop Private
On_Key KEY_ALT+KEY_2 Send Activate_Rep_Bal_Report to Desktop Private
On_Key KEY_ALT+KEY_3 Send Activate_Rep_Inc_Report to Desktop Private
//
End_Procedure

//************************* View Packages/Objects ***************************

Use MyAbout // about - Send about


Use Ledger.VW // View title 1 - Send Activate_Ledger to Desktop
Use Journal.VW // View title 2 - Send Activate_Journal to Desktop
Use TypeEnt.VW // View title 3 - Send Activate_TypeEnt to Desktop
Use Rep_COA.RPT // Report 1
Use Rep_Bal.RPT // Report 2
Use Rep_Inc.RPT // Report 3

Start_Ui (Main_Menu(Current_Object)) // start the program

258 Data Access Corporation


Discovering Object Oriented DataFlex Lesson 11 Reporting

Did you Discover?:


11 - 1. Are there other report classes that DFQuery does not use?

For answers, see “Lesson 11 - Discover Answers” page 284

Data Access Corporation 259


Discovering Object Oriented DataFlex Workshop

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 at least two reports

• Create a Mainprog, that includes all the views & reports.

• 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

Data Access Corporation 261


Discovering Object Oriented DataFlex Appendix A

A p p en d i x A
“Did you Discover
Answers”

Data Access Corporation 263


Appendix A Discovering Object Oriented DataFlex

Lesson 2 - Fill-In Answers

File Relationships

Rule #1 _____Many to N relationship_____

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 #2 ___Parent related field MUST be uniquely indexed__

What happens if we break this rule?


Duplicate parents are allowed and child records will not be linked correctly. E.g., If we have
Customers Jones and Baker, both with customer ID 540, then the child invoice record that is
linking to customer 540 has no way of knowing if the invoice was placed by Jones or Baker.

Rule #3 __Both Parent & Child related fields MUST be the same length and type.__

What happens if we break this rule?


Child records again will not be link correctly. E.g., If a Customer’s number was 123456 and
the related Child field was only 2 digits in length, then when the attach (moving the parent
related field to the child related field) is accomplished during a save, there is no way that the
child related field will be linked correctly. The same corruption occurs if the type is not the
same. DataFlex 3.1 now displays a runtime “Bad relationship” error, whenever a bad
relationship is discovered.

264 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 2 - Discover Answers


2 - 1. What utility(ies) will allow you to create a file? Which ones allows you to
modify a file with active records?

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.

Data Access Corporation 265


Appendix A Discovering Object Oriented DataFlex

Lesson 3 - Fill-In Answers

• Within DFFile, open the Child File, which is __GL_Accts__


• In the Relate to column of child field __GL_Accts.Type_ relate it to parent field _Type.Code_.

266 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 3 - Discover Answers

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.

3. - 2. Which utility will create a new .DEF file?

DFFile or DFMaint

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?

Changing the About.TEM file, you can quickly create a custom About Pop-up that is called from the
Help Pull-Down.

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.

TypeTbl.SRC and TypeTbl.VW are in the Lesson03.ZIP file.

3. - 5. When using the USE command can you leave off the file extension?
Yes, but only if the extension is .PKG (the default).

Data Access Corporation 267


Appendix A Discovering Object Oriented DataFlex

Lesson 4- Fill-In Answers


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

Object GL_ACCTS_DS is a GL_ACCTS_Data_Set


End_Object

Object TRAN_HDR_DS is a TRAN_HDR_Data_Set


End_Object // Tran_Hdr_DS

Object YR_HIST_DS is a YR_HIST_Data_Set ;


Updating (GL_Accts_DS(current_object))
Set Constrain_File to GL_Accts.file_number
// OR
// Begin_Constraints
// Constrain YR_Hist relates to GL_Accts
// End_Constraints
End_Object // Yr_Hist_DS

Object TRAN_DTL_DS is a TRAN_DTL_Data_Set ;


Updating (GL_Accts_DS(current_object)) ;
(Tran_Hdr_ds(current_object))
Set Constrain_File to GL_Accts.file_number
// OR
// Begin_Constraints
// Constrain YR_Hist relates to GL_Accts
// End_Constraints
End_Object // Tran_Dtl_DS

Object GL_Accounts_EF is an Entry_Form ;


Using (GL_Accts_DS(current_object))

Object Memo_EC is an Entry_Client // Nested child DEOs will


// use the DSO of the parent
Object Memo_TW is a Text_Window // if using clause ommited
End_Object // Memo_TW

End_Object // Memo_EC

End_Object // GL_Accounts_EF

Object Yearly_Summary_EF is an Entry_Form ;


Using (YR_Hist(current_object))
End_Object // Yearly_Summary_EF

Object Transaction_TBL is a Table ;


Using (Tran_Dtl(current_object))
End_Object // Transaction_TBL

End_Object // Transactions_View

268 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

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

Object GL_ACCTS_DS is a GL_ACCTS_Data_Set

End_Object

Object TRAN_HDR_DS is a TRAN_HDR_Data_Set

End_Object // Tran_Hdr_DS

Object TRAN_DTL_DS is a TRAN_DTL_Data_Set ;


Updating (GL_Accts_DS(current_object)) ;
(Tran_Hdr_ds(current_object))
Set Constrain_File to Tran_Hdr.file_number
// OR
// Begin_Constraints
// Constrain Tran_Dtl relates to Tran_Hdr
// End_Constraints
End_Object // Tran_Dtl_DS

Object Header_EF is an Entry_Form ;


Using (Tran_Hdr(current_object))

Object Totals_EF is an Entry_Form // Nested child DEOs will


// use the DSO of the parent
End_Object // Totals_EF // if using clause ommited

End_Object // Header_EF

Object Detail_TBL is a Table ;


Using (Tran_Dtl(current_object))

End_Object // Detail_TBL

End_Object // Transactions_View

Data Access Corporation 269


Appendix A Discovering Object Oriented DataFlex

Lesson 4 - Discover Answers

4 - 1 Constraint Blocks can be coded in all objects. True or False?

False. Only Data Set Objects or their subclasses

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.

270 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

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?

Object OrdHead is an Entry_Form OrdHead_Image ; Customer OrdType


Using (_____________(current_object)) File File
Item_List
Entry_Item OrdHead.Order_Number
Entry_Item OrdHead.Date
Entry_Item OrdType.Code
Entry_Item Customer.Customer_Number
Entry_Item Customer.Name OrdHead
End_Item_List File
End_Object

Object OrdDetail_Table is a Table ;


Constrained
Using (OrdDetail_DSO(current_object))
...
End_Object OrdDetail
File

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.

Object Customer_DSO is a Customer_Data_Set


End_Object

Object OrdType_DSO is a OrdType_Data_Set


End_Object

Object OrdHead_DSO is an OrdHead_Data_Set


Updating (Customer(Current_Object)) (OrdType(Current_Object))
End_Object

Object OrdDetail_DSO is an OrdDetail_Data_Set


Updating (OrdHead(Current_Object))
End_Object

Data Access Corporation 271


Appendix A Discovering Object Oriented DataFlex

Lesson 5 - Fill-In Answers

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__

Comparing Access Methods:

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________

Could Empl_Form send the message: Send do_it to (Time_Card_Table(current_object))?

__yes_____________________

Could Time_Card_Table send the message: Send do_it to (Empl_Comment(current_object))?

__no, because of encapsulation, Time_Card_Table should not know about a child of Empl_Form__

• We are (augmenting/overriding/canceling/adding) the Save_Row & Delete_Row messages.

• We are (augmenting/overriding/canceling/adding) the Request_Clear message.

272 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 5 - Discover Answers

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

5 - 2 If within an Entry_Form Object the Request_Clear is canceled, how will this


affect saves?

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)

5 - 4 If the accelerator key Object MyTableis a Table


Kdownarrow is used in object On_Key Kdownarrow Send Print_Label
MyTable will the Print_Label
Procedure Print_Label
procedure shown be executed? ...
Will it be executed if End_Procedure

Kdownarrow is used in MyEdit Object MyEdit is an Edit


...
Object? End_Object // MyEdit

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.

Data Access Corporation 273


Appendix A Discovering Object Oriented DataFlex

Lesson 6 - Fill-In Answers


Function Long_Year Date In_Date Returns _DATE_
If In_Date LT 01/01/100 Begin
// If 2 digit year is > 49 default year to 19xx
// If 2 digit year is <= 49 default year to 20xx
If In_Date GT 12/31/49 Calc (In_date + 01/01/1900) to In_Date
Else Calc (In_Date + 01/01/2000) to In_Date
End
Function_Return __In_Date__
End_Function

Based on constrained Child to Parent DSO Structure:


In a DEO serviced by In a DEO serviced by
Operation Parent File-GL_Accts Child File - Yr_Hist Operation Flows
Saves (F2) Saves only Parent Saves Both Saves Propagate Up
Clears (F5) Clears Both Clears only Child Clears Propagate Down
Deletes (Shift+F2) Deletes Both Deletes only Child Deletes Propagate Down

274 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 6 - Discover Answers

6 - 1 Can Procedures or Functions pass arguments?

Both can

6 - 2 Global Variables can usually be replaced with ___________?

Creating a property

Data Access Corporation 275


Appendix A Discovering Object Oriented DataFlex

Lesson 7 - Fill-In Answers


/Big_Image
================================================
1___ 2____________ 3___ 4______ 5____

6________
7________
8________
9________
10________

11____ 12_______ 13___________


14____ 15_______ 16___________
17____ 18_______ 19___________
20____ 21_______ 22___________

================================================
/*
//**************** fill in the blanks below **************************

//Sub_Page partial_image From Full_image Horizontal Start# # of Windows


Sub_Page Customer_Image from big_image horizontal __1__ __5__

//Sub_Page partial_image From Full_image Vertical Start# # of Windows


Sub_Page Phone_Image from big_image vertical __6__ __5__

//Sub_Page partial_image From Full_image Rectangular Start# Row# Column#


Sub_Page Accounts_Image from big_image rectangular _11_ __4__ __3__

Object My_Client is an Entry_Client __Full_Image__ // full_image here


// add a client and
// move these object properties to the client
Set Object_Color to 112 112
Set location to 5 10 relative

Object Customer is an Entry_Form ___Customer_Image___


Item_List
entry_item customer.number
...
End_Item_List
End_Object

Object Phones is a Picture_Form __Phone_Image_____


...
End_Object

Object Accounts is a Table ___Accounts_Image_____


...
End_Object

End_Object

Procedure Default_Date integer item#


Local Date __today__ // this could be any valid variable name
Get value __item__ __item#__ to __today__
If __today__ EQ "" begin
sysdate __today__
calc (__today__ + 01/01/1900) to __today__
change_value __item__ __item#__ to __today__
end
End_Procedure

276 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 7 - Discover Answers

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

Set Value of (Totals_EF(current_object)) item 3 to MyVar

Data Access Corporation 277


Appendix A Discovering Object Oriented DataFlex

Lesson 8 - Fill-In Answers

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
__________ ________________ ___________________
/*

Object My_Button is a Button Button_Image

On_Key __Key_Alt+Key_P__ send __Print_Label__

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

Selection Lists display data from a __database__.

Pick Lists display ___static___data.

278 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Use Sellist Picklist

/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

Procedure Calc_Diff integer item#


local number bud act
get value item item# to bud
get value item (item# + 1) to act
set changed_value item (item# + 2) to (bud-act)
End_Procedure

Data Access Corporation 279


Appendix A Discovering Object Oriented DataFlex

Lesson 8 - Discover Answers

8 - 1 Create a 5 line program that contains an edit object. The online


Documentation is there to assist you!

Use UI
Object My_Edit is an Edit
Set size to 5 20
End_Object
Start_UI my_edit

8 - 2 Which Class is used as a container object?

Client or Entry_Client

8 - 3 Look up the property Checkbox_Item_State in the Reference Manual and


discover the Defining Class(es).

Check/CheckList/Radio/RadioList/Menu

8 - 4 If I use the Checkbox_Item_State property in an Entry_Form, it would forward


this property to which class to be resolved?

Menu?

280 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 9 - Fill-In Answers

• 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_____

• Creating (new record saves)


_____Assign next Trans number from a system file_______________________________

TRAN_DTL
• Creating (new record saves)
_____Assign next Detail number from Tran_Hdr.next_detail#_______________________

• Update (new & edit saves)


_____Maintain Tran_Hdr’s running totals; adding to total_debits and total_credits______

_____Maintain Yr_Hist’s running totals adding to correct year record and monthly fields_

• Backout (edit saves & deletes)


_____(mirror image of Update procedure subtracting out instead of adding to totals)___

________________________________________________________________________

Data Access Corporation 281


Appendix A Discovering Object Oriented DataFlex

Lesson 9 - Discover Answers

9 - 1 If I wished to automatically assign the next available ID number, which


procedures would I augment?

Creating

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?

Update & Backout (Used for maintaining running totals)

282 Data Access Corporation


Discovering Object Oriented DataFlex Appendix A

Lesson 10 - Discover Answers

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.

Class Entry_Form_ND is an Entry_Form


Procedure Construct_Object integer img#
Forward Send Construct_Object img#
End_Procedure

Procedure Request_Delete
End_Procedure
End_Class

10-2 If Validate_Save returns a Zero, does this mean the save passed or failed?

Passed

Data Access Corporation 283


Appendix A Discovering Object Oriented DataFlex

Lesson 11 - Discover Answers

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.

284 Data Access Corporation


Discovering Object Oriented DataFlex Appendix B

A p p en d i x B
Problems &
Solutions

Data Access Corporation 285


Appendix B Discovering Object Oriented DataFlex

Multiple Selection Processing:

• 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 ║
╠═══════════════════════════╣
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
║ ____________________ ║
╚═══════════════════════════╝
/*

Object Discount_Prompt is a Pick_List Discount_Image Popup

Set Location to 8 14 Relative


Set Scroll_Bar_Visible_State to True
Set Location of (Scroll_Bar(Current_Object)) to 4 17 Relative
Set Select_Mode to Multi_Select
Set Exit_Msg to Process_Selections

integer hold_total

Procedure Add_Discounts integer disc_val


Add disc_val to hold_total
gotoxy 24 0
show “Total selected Discounts = “ hold_total
End_Procedure

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

286 Data Access Corporation


Discovering Object Oriented DataFlex Appendix B

Move_Value_Out Procedure & Display_Buffer_msg Property:

• 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.

Data Access Corporation 287


Appendix B Discovering Object Oriented DataFlex

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

288 Data Access Corporation


Discovering Object Oriented DataFlex Appendix B

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)) }

• Solution: There is many different variations of the auto_prompt, there is even a


Prompt_Entry_Mode property that can be set. See the handbook under Auto_Prompt for all
the options.

Data Access Corporation 289


Appendix B Discovering Object Oriented DataFlex

Pre-compiling

• Problem: Is there a short cut to compiling code?

• 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.

Rules for Pre-compiling


• #HEADER must be the first command line
• #ENDHEADER at a logical break point for the compiler
• Pre-compile the code using the -P compiler option
• #HEADER & #ENDHEADER are compiler directives, therefore must be in Caps
• If changes are made between the #HEADER & #ENDHEADER you must pre-
compile again
• Only one pre-compile package can be used per compiling

290 Data Access Corporation


Discovering Object Oriented DataFlex Appendix B

Code_Selection_List, Code_Pick_List & Code_Radio_Entry_Form

• Problem: I use many Selection Lists my filelist is getting full of small files.

• Solution: Code_Selection_List, Code_Pick_List and Code_Radio_Entry_Form is what you


need. One file stores all your codes and these Code lists will can be used for many lists.

Employee Screen
Male
Name _______________ Female

Sex _ Customer Screen


Marital Status _
Health Insurance _ Married
Name _______________
Dental Insurance _ Single Master
Divorced Visa
Marital Status _
Status _ Widowed American Express
Status _
Active
Inactive Region __ Charge Card _

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

Object Response is a Code_Selection_List


Set Type_Value to Marital // the Database type
Set List_Title to ôMarital Statusö
Set Export_Description_State to False
Set Default_Code to Married
Set Allow_Blank_State to True // blank choices valid
Set Find_Search_State to True
End_Object

Data Access Corporation 291


Appendix B Discovering Object Oriented DataFlex

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

Procedure Append_a_Row // procedure that moves you to end of table


Send End_Of_Data // for creating new records
Send Down
End_Procedure

End_Object

292 Data Access Corporation


Discovering Object Oriented DataFlex Appendix C

A p p en d i x C
Extra Notes:

Data Access Corporation 293


Appendix C Discovering Object Oriented DataFlex

Class Hierarchy Chart


object
array
keyproc_help_edit_name
keyproc_help_name Shadowed Classes are abstract - not to be used for instantiation.
monarray Classes in bold face are predefined - not defined in package files.
set Classes in normal face are defined in supplied package files.
broadcaster
ui_object
edit
code_selection_list
To read Clas Hierarchies is backwards (from
text_window
text_editor right to left). Always start with the end-points
trace classes. Those are the classes you are most
likely to use. The further up the tree you go
menu
action_bar
the more abstract the classes tend to get.
action_bar_menu
entry_action_bar
standard_action_bar
button text_action_bar
checkbox
entry
entry_form
picture_form
prototype_entry
form
list
checklist
entrylist
selection_list
selection_list_row
wide_list
formlist data_list
list_wide table
pick_list
code_pick_list
radio_list directory_list
file_list
pull_down_menu radio_entry_list
radio code_radio_entry_form

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

294 Data Access Corporation


Discovering Object Oriented DataFlex Appendix C

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

* = Defined only in Data Access packages – see package documentation

Data Access Corporation 295


Appendix C Discovering Object Oriented DataFlex

New DataFlex Features

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.

• Auto prompting (ie get_find_req_auto_prompt)


• New Entry Option { Thousands }
• Entry_Name_Item
• New Classes:
• code_pick_list
• code_selection_list
• radio_entry_form
• code_radio_entry_form
• entry_view_client
• selection_list_client

• 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

296 Data Access Corporation


Discovering Object Oriented DataFlex Appendix C

• AutoCreate Utility (DFAuto) & (AutoGen)


These utilities allow the developer to quickly create and edit data-entry “view” prototypes. DFAuto is
also capable of creating new database files. AutoGen generates these views as framework compliant
source code modules.

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.

File Definition Utility (DFFile)


This development utility will allow us to add or change file structures. DFFile allows multiple files to
be opened and upon leaving will reindex or restructure your data as required.

File Administration Utility (DFRun DFAdmin)


This utility is also provide in the runtime version, it provides an interface for creating, editing, and
deleting files.

Query Utility (DFQUERY)


This utility provides the means to extract your data as reports ( to screen / disk / printer) or as text files
(line or comma delimited). Saving the setup as a .QRY file allows the user to rerun the query without
entering the setup. Query is also capable of generating the source code that will allow you to edit,
compile, and run the program as a DataFlex program.

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.

Data Access Corporation 297


Appendix C Discovering Object Oriented DataFlex

Import/Export Utility (DFImport)


This utility provides the means to import ASCII files into a DataFlex database file or export a DataFlex
database file to an ASCII file. The interface is easy to use and there is extensive control of field
selection, placement, and data type.

DFConfig & DFSetup


DFConfig will create a DFConfig.INI file that will hold the setup of a number of DataFlex setups.
Everything from Data format to Default object color and Key mappings are stored here. DFSetup
supports the configuration of hardware and installation of registration code stored within the
Termlist.CFG file.

Menu Utility (DFRun MenuDef)


This utility allows the developer to easily modify the existing DataFlex menu to meet the needs of the
application being created. MenuDef not only allows DataFlex programs to be selected from the menu
but also system commands and RunProgram Wait commands, and prompting users for questions are
also supported. Since the menu selects are stored within a normal DataFlex database, this is a very
quick and easy method of creating a menu for your application.

Help Utilities (DFRUN DFHelp)


Provides your programs with context sensitive help. The utility is great for adding large amounts of
help screens or you can build the screens within a running program by using the HELPEDIT package.

298 Data Access Corporation


Discovering Object Oriented DataFlex Appendix C

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.

• Button images use underscores only (no darts <>)


• “Help” should always be the last item on the action bar
• Right justify accelerator keys in all pull-downs (\aAlt+1)
• Tables have vertical lines between all columns and a horizontal line below column headings
• Selection Lists and Pick Lists only have a horizontal line below column headings
• a Standard method of indicating when a prompt is available.
• Standard placement of images, in an image section or remaining with the Object
• Standard placement of procedures (before or after the Item_List block)
• Register_XXX commands should be together at the top of all each file (view)
• End_Object Commands should include a remark indicate which Object name is ending

Data Access Corporation 299


Appendix C Discovering Object Oriented DataFlex

Events to trigger Messages

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

Standard Item Classes (these classes were designed to trigger/send messages)


• Buttons
• Lists
• Message

300 Data Access Corporation


Discovering Object Oriented DataFlex Appendix C

Student Notes:
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________

Data Access Corporation 301


Glossary Discovering Object Oriented DataFlex

G l o ssar y

302 Data Access Corporation


Discovering Object Oriented DataFlex Glossary

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

Differentiation Deviations of objects from their superclass

.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}

Data Access Corporation 303


Glossary Discovering Object Oriented DataFlex

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 Object The object that currently is capable of user interaction.

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.

UIMS User Interface Management System (UIMS) is a programming environment in


which DataFlex programmers can create and maintain attractive, intuitive, and
powerful user interfaces for applications.

User Interface The method of communication between a computer and its operator.

View A section of code (usually encapsulated in an Entry_View_Client Object and


activated by way of selection from a pulldown). That handles one aspect of a
large application. E.g., The data entry section allowing customer entry. These
independent views are coded and tested stand alone and then combined with
other views to create an application.

304 Data Access Corporation


Discovering Object Oriented DataFlex Glossary

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.

∗ Data Access Database API (Application Program Interface)


For professional programmers and application developers, DataFlex offers a complete application
environment that includes a relational DBMS, object-oriented 4GL, and program generators in a
single, integrated package. There are times, however, when other programs and languages must
access DataFlex files and indexes. For these instances, developers can use products based on the
Data Access Database API which contains the functions needed to read and write DataFlex
database files. Currently, two products are available, a Windows Dynamic Link Library (DLL) and
a C-Library compatible with Borland’s C3.0. These products include all the support files and
documentation needed to create complete applications based on the API.

Data Access Corporation 305


Glossary Discovering Object Oriented DataFlex

∗ NFOflex, Hypertext Documentation for DataFlex


With NFOflex, the complete DataFlex documentation set becomes the industry’s easiest to use. The
NFOflex infobase lets you find the information you need fast, and gives you the flexibility to
categorize the information in a way that makes sense to you.

∗ WinQL (for Windows environments)


WinQL is a powerful yet easy-to-use program for creating reports, lists, and forms using data from your
existing databases. WinQL works by establishing connections with one or more of your databases
and then using these connections as conduits. WinQL draws in the values from database fields you
select and uses them in the report. These can be in their original form or as part of a more
sophisticated formula.

∗ 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.

306 Data Access Corporation


E v al u at i o n
Object Oriented DataFlex

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: ________________________

Would you recommend the class to a friend? ____

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:

Additional Comments: ____________________________________________________


_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

Training Manual errors:


Page Number Discrepancy
___________ _______________________________________________
___________ _______________________________________________
___________ _______________________________________________
___________ _______________________________________________
___________ _______________________________________________
-----------------------------------------------------------------

Data Access Corporation


Training Dept.
14000 S.W. 119 Avenue
Miami, FL USA 33186-6017

-----------------------------------------------------------------

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.

Glossary: A Object Oriented Dictionary

Additional Training and Related Products.

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!

Interaction is what makes a great class, be creative in your presentation!

You might also like