Theme:
v
APL+Win Training Pack 6

Resizing Forms & Dialog Boxes & Object Oriented Programming & Intoduction to OCX: an OCXPrinter Object

Download APL+Win Training Pack 6 (2387 K)

Object Oriented Programming with APL+Win

It is possible to do real Object Oriented Programming with APL+Win!

And believe it or not, this can be extremely simple and clear. So simple that, if you learn it and taste it there is a high chance you'll become addicted!

This 115 pages lesson teaches all the basic concepts of Object Oriented Programming, shows you how to implement them in APL+Win through numerous very simple examples, and gives you the one self-contained Qwi utility which allows you to use pure OOP in APL+Win.

You will be learning:

  • what objects are
  • how to create your own new classes of objects
  • how to build a hierarchy of classes
  • how to fully use inheritance
  • how to overload methods and properties
  • what is a superclass
  • how to override methods and properties by calling superclass methods and properties
  • what polymorphism is and how to use it
  • how to use encapsulation

Not only developing your own new classes of objects is very simple once you have read this lesson, but you then use them with the Qwi utility which shares the same syntax as the APL+Win ŒWI user interface system function. See an example below.

With this lesson, you will immediately be able to start defining your own new classes of objects and benefit from the many advantages of real Object Oriented Programming in APL+Win:

  • write truly reusable code
  • avoid code duplication and rewrites with inheritance
  • simplify programming with polymorphism
  • greatly increase code sharing with other developers
  • improve the consistency of your interface
  • increase your software reliability
  • increase your productivity

In this APL+Win Training we will be developing a good number of new very porwerful new classes of objects for APL+Win, starting with the first of them called: OCXPrinter


A new object for APL+Win: OCXPrinter

The first part of this Chapter describes how to use the brand new APL+Win OCX interface, using the Formula One OCX v4.1.5 spreadsheet. After reading these few pages you should be able to use any new OCX with APL+Win.

Then, in order to put the new Object Oriented technlogy into action, we build together a new class of object called OCXPrinter.

OCXPrinter is a rewrite of the GuiPrint utility presented in Chapter 11 (see Pack 3) this time implemented as an object and as a stand-alone APL function.

This object not only allows you to create and print almost any report you can imagine from APL+Win, with Excel quality, but also encapsulates new methods for directly importing and exporting data between APL and Excel 5/95, for example automatically installing planes of a 3-dim APL nested array in successive sheets of the Excel workbook.

OCXPrinter comes with 2 properties (ontop and visible) and more than 60 built-in methods (Add AddAcross AddColPageBreak AddPageBreak AddRowPageBreak Align Auto AutoAll BackColor BlankZeroes Bold Border BottomMargin Clear ClearAll Close ColWidth Copy DefaultFont Export FitToPage Font FontColor FontName FontSize Footer FooterFont FooterMargin Format Get GetSelRef GridHeadings GridLines HCenter HLine Header HeaderFont HeaderMargin Import Italic LeftMargin Margins Move New NextRowPageBreak Open Orient Preview Print PrintArea PrintGridLines PrintHCenter PrintScale PrintTitles PrintVCenter RemoveColPageBreak RemovePageBreak RemoveRowPageBreak Resize RightMargin Scale Sel SelAll SelRef TopMargin Underline VCenter VLine).

Here is an example using the OCXPrinter object. To print the following report:

You need to write the following straight forward APL function:

Note that you must have the APL2000.TTF file installed on your computer to see APL characters in the function listing below. You can download the APL2000.TTF True Type file now if you need to.
    ∇ OCXPrinterTest;L;S;data;pos;⎕wself
[1]   ⍝∇ OCXPrinterTest -- Sample report using the OCXPrinter object
[2]
[3]   L←ListSeparator   ⍝ retrieve Windows Intl list separator setting
[4]
[5]   data←((⊂''),months,¨' '),(days,¨⊂'  ')⍪¯2000+?12 7⍴10000
[6]
[7]   ⍝ Create instance of OCXPrinter object
[8]   ⎕wself←'ff' Qwi 'New' 'OCXPrinter'('ontop' 1)('where' 2 10 31 107)
[9]
[10]  ⍝ Fill the grid with data
[11]  pos← Qwi 'Add' (4 1) data
[12]
[13]  ⍝ Apply formating and add column headers
[14]       Qwi'Format' '[>0] [BLACK] # ###.00 ;[<0] [RED] (# ###.00);'
[15]       Qwi'Font' 'Impact' 14
[16]  pos← Qwi'AddAcross' 3 (2 4) 'First 3 days'
[17]  pos← Qwi'AddAcross' 3 (5 6) 'Last 2 days'
[18]  pos← Qwi'AddAcross' 3 (7 8) 'Weekend'
[19]       Qwi('Sel' 'B3:H3')('BackColor' 192 192 192)('Font' 'Impact' 18)
[20]       Qwi('Sel'('B4:H4',L,'A3:A16'))('BackColor' 192 192 192)
[21]       Qwi('Align' 'right' 'center')'AutoAll'
[22]       Qwi('ColWidth'(⍳9)(9⍴3800))('Sel' 1 1 1 1)
[23]
[24]  ⍝ Printer settings
[25]       Qwi('TopMargin' 1.6)('BottomMargin' 2) ⍝1.4
[26]       Qwi('HeaderMargin' .5)('FooterMargin' .5)
[27]       Qwi'HeaderFont' 'Arial' 12 'Arial Bold' 24 'Arial' 12
[28]       Qwi'FooterFont' 'Arial' 12 'Arial' 12 'Arial' 12
[29]           S←⊂'Uniware' 'APL Department' 'Year Report'
[30]           S←S,⊂'' 'APL Sales' '(1996)'
[31]           S←S,⊂'&D' '&T'
[32]       Qwi'Header' S
[33]           S←⊂'Copyright ⍝ 1997 Eric Lescasse'
[34]           S←S,⊂''
[35]           S←S,⊂'Page &P/&N'
[36]       Qwi'Footer' S
[37]       Qwi'Orient' 'landscape'
[38]       Qwi'PrintHCenter' 1
[39]
[40]  ⍝ Finish
[41]       Qwi'Preview'            ⍝ print preview
[42]  ⍝or: Qwi'visible' 1          ⍝ display Formula One form
[43]  ⍝or: Qwi'Print' 0            ⍝ print immediately (with no interface)
[44]  ⍝or: Qwi'Print' 1            ⍝ print dialog box
    ∇

If we had commented line 41 and decommented line 42 in the above function, here is the window which would have popped up:

allowing you to further edit data in the grid, before printing and change many printing parameters through various print dialog boxes.

To see how easy it is to use the OCXPrinter object to exchange data between APL+Win and Excel 5, Excel 7 or Excel 95, here is a sample APL session:

      apl3d←'This' 'is' 'a' '3D' 'nested' 'APL' 'array'
      apl3d←apl3d,'containing' 'numbers' 'and' 'text',⍳10
      apl3d←4 6 7⍴apl3d
      'ff' Qwi 'New' 'OCXPrinter' ('Export' 'c:\temp\temp.xls' apl3d)

Each plane of the 3-dimensional APL array automatically goes into a different workbook sheet in Excel; numeric APL data become numerci cells under Excel.

Now to reimport the data to APL again:

      imported←'ff' Qwi 'Import' 'c:\temp\temp.xls'
⍴imported
4
	
      1⊃imported
       This      is   a   3D nested APL array
containing numbers and text      1   2     3
		4       5   6    7      8   9    10
 This      is   a   3D nested APL array
containing numbers and text      1   2     3
		4       5   6    7      8   9    10

      ⍴¨imported
6 7  6 7  6 7  6 7

      ⍴⊃imported
4 6 7

Note that you must close the Excel workbook before you can import it. Note also that the result of the Import method is alsways a nested vector where each element is a different sheet of the imported Excel workbook. This allows to import ANY Excel spreadsheet within APL in seconds, since Excel workbook sheets may have different number of lines and columns.

From the above Import/Export example which demonstrates invoking methods of a new class of APL+Win objects (OCXPrinter) you can see how easy it is to use an object. And the good news are that, with this lesson, you will learn how to easily customize an object like OCXPrinter by adding your own methods and properties. You will also be able to create child classes of the OCXPrinter class and fully use inheritance and polymorphism to you greatest benefit.


Resize handlers

This Pack WinWord document also talks about Resize handlers and how to automatically resize all children of a form when the form is resized.

2 utilities are provided: ResizeHandler and ResizeFontHandler which resizes all the fonts used in the form accordingly to the nesw form size.

Learn the techniques involved and reuse these 2 utilities as wished.

Here is an example:

The following APL+Win form:

gets automatically resized by ResizeFontHandler to the following form:

or to the following form:


The Tip of the Month

The tip of the month is a new session tool with a shortcut key allowing you to pack APL+Win workspaces squeezing as many bytes out of them as possible before saving them to disk.


Pack 6 Content

disk6.doc A 115 pages Winword document containing Chapters 12, 13 and 14 of the APL+Win Training.
resize.w3 Resize handlers (ResizeHandler and ResizeFontHandler) as well as functions to test them.
qwi.w3 The Qwi utility and a dozen of new APL+Win classes to explore OOP programming with APL+Win (inheritance, polymorphism, etc.). Requires APL+Win 1.9.14+.
qwimin.w3 The Qwi and HANDLERFOR utilities: the minimal set of utilities to copy into your workspace to use OOP and new classes of objects. Requires APL+Win 1.9.14+.
ocx.w3 A few functions to explore using OCXs from APL+Win. Requires APL+Win 1.9.14+.
qwiprint.w3 The OCXPrinter object and several additional utilities:
DecimalSeparator and ListSeparator read the Control Panel Intl settings
ImportXls and ExportXls use the OCXPrinter object to import/export to Excel 5,7,95.
Requires APL+Win 1.9.14+.
vcf132.ocx
mfcans32.dll
msvcrt20.dll
oc30.dll
odbc32.dll
Formula One OCX v4.1.5 (the redistributable files).