APL+Win Training Pack 7

Object Oriented Programming (continued) & Accessing ODBC Databases

Download APL+Win Training Pack 7 (793 K)

This APL+Win Training Pack explains how to start building your own class hierarchy of objects.

It contains:

  • a new version of the Qwi utility with a few enhancements
  • a template QwiNewClass function for creating new objects
  • a template QwiInherit function for creating new objects which inherit from an existing class

The Qwi utility has been improved so that all user defined class ultimately derive from a common Object class.

A first new class called Form is created: this class inherits from the standard APL+Win Form class to which it adds a number of new properties and methods.

Then a new FOne class is created: an FOne object is a form which contains a Formula One OCX object which knows how to resize itself when the form is resized and understands a number of general basic methods, needed with any from with a grid. The FOne object inherits from our Form class and therefore can use all of the Form class properties and methods.

In the second part of this APL+Win Training Pack, a new FOneODBC class of objects is developed. This class inherits from the FOne class and therefore from our Form class as well. An FOneODBC object is a form object which contains a Formula One OCX object and knows how to connect itself to any ODBC database, retrieve data from the database tables into the grid, show the database tables and columns structure, retrieve data to APL, update records in database tables, insert new records in the database tables, etc...

In this process of starting to build a class hierarchy, we are facing the challenges of Object Oriented Design. This APL+Win Training Pack includes detailed explanations about Object Oriented Analysis and Design.

A few dummy objects are added to our class hierarchy so that it looks like the following:

A few utilities are provided to complement the ODBC workspace:

  • the Tree function is a recursive utility which allows to draw a tree in APL
  • the ClassTree function analyzes a workspace and draws its class hierarchy tree

All subsrcibers to the APL+Win Training will be able to greatly benefit from the new Form and FOne classes. Yhey will be able to create their own child classes starting from Form and FOne.

But the major part of this APL+Win Training Pack is the FOneODBC object.

With this new object, you will be able to access ODBC databases from APL+Win and update them. This object in itself offers similar functionnalities as commercial products which cost as much as this whole APL+Win Training Program.

Let's quickly show how you can use this object:

      Qwi 'New' 'FOneODBC' 'DemoShow'
      ds←Qwi 'Connect' 'c:\windows\odbc\data sources\biblio97.dsn'
      rc←Qwi 'Query' 'select * from authors'

The first instruction creates an instance of the FOneODBC object and shows it topmost in the upper right corner of the screen.

The second instruction connects it to the BIBLIO.MDB Access database.

The third instruction retrieves all records from the authors table into the FOneODBC grid.

The result is the following:

If you start changing cells by typing new data into them, the records are automatically and immediately updated in the BIBLIO.MDB Access database.

If you type in new records, all you need to do to insert them into the database table, is to invoke the FOneODBC Insert method:


You can even use the FOneODBC object as a background engine to retrieve ODBC data directory to APL with the GetQuery and GetQueryVars methods:

      Qwi 'GetQuery' 'select * from authors where au_id < 10'
1 Adams, Pat
2 Adrian, Merv
3 Ageloff, Roy         1943
4 Andersen, Virginia
5 Antonovich Michael P.
6 Arnott, Steven E.
7 Arntson, L. Joyce
8 Ault, Michael R
9 Avison, D. E.

      Qwi 'GetQueryVars' 'select * from authors where au_id < 10'

1 2 3 4 5 6 7 8 9

Adams, Pat
Adrian, Merv
Ageloff, Roy
Andersen, Virginia
Antonovich Michael P.
Arnott, Steven E.
Arntson, L. Joyce
Ault, Michael R
Avison, D. E.

Of course, at any time you can query the database tables and columns structure using the Tables and Columns methods:

C:\APLBOOK\disk7\biblio  MSysACEs          SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysColumns       SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysIMEXColumns   SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysIMEXSpecs     SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysIndexes       SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysMacros        SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysModules       SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysModules2      SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysObjects       SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysQueries       SYSTEM TABLE
C:\APLBOOK\disk7\biblio  MSysRelationships SYSTEM TABLE
C:\APLBOOK\disk7\biblio  Authors           TABLE
C:\APLBOOK\disk7\biblio  Publishers        TABLE
C:\APLBOOK\disk7\biblio  Title Author      TABLE
C:\APLBOOK\disk7\biblio  Titles            TABLE
C:\APLBOOK\disk7\biblio  All Titles        VIEW

      Qwi'Columns' 'authors'
C:\APLBOOK\disk7\biblio authors Au_ID      4 COUNTER  10   4  0  10 1 1
C:\APLBOOK\disk7\biblio authors Author    12 TEXT    255 255  0   0 1 2
C:\APLBOOK\disk7\biblio authors Year Born  5 SHORT     5   2  0  10 1 3

The FOneODBC object includes other methods and properties.

Pack 7 Content

File Description
DISK7.DOC A 76 pages Winword document containing Chapters 15 and 16 of the APL+Win Training.
ODBC.W3 A workspace allowing you to explore accessing ODBC databases in an Object Oriented fashion as well as utilities to explore a class hierarchy and several objects built in a small class hierarchy.
ODBCMIN.W3 The minimum set of functions required for the FOneODBC object to run.