Virtual Pascal for OS/2 v1.10 Evaluation Licence - Examples (C) 1996 fPrint UK Ltd A number of examples demonstrating various aspects of OS/2 programming with Virtual Pascal can be found in the EXAMPLES subdirectory of the VP/2 installation. Many more examples are included in the full version of VP/2. Compiling the examples ~~~~~~~~~~~~~~~~~~~~~~ All of the examples are compiled with dynamic linking, using the VP11DEMO.DLL library for all system functions. The full version of VP/2 includes statically linked versions of the examples that do not require the DLL in order to run. The CLOCK example ~~~~~~~~~~~~~~~~~ The Clock example is an example of an OS/2 Presentation Manager program. It implements a very simple analog clock, which when minimized continues to update its minimized icon. The SYSDEMO example ~~~~~~~~~~~~~~~~~~~ This example (which can be compiled using Borland Delphi v2) demonstrates the use of many different functions defined in the SysUtils unit. SysUtils is a natural extension of the System unit, and contains a long list of formatting, conversion, I/O and error handling routines. The CLSDEMO example ~~~~~~~~~~~~~~~~~~~ This example (which can be compiled using Borland Delphi v2) demonstrates the use of many different functions defined in the Classes unit and also serves as an example of the "new" Delphi class model. Classes implements a large number of very sophisticated classes, and the CLSDEMO example can be used to get across the initial hurdle of programming using the Delphi class model. The final part of the example is interesting, because it shows that VP/2 is compatible with Delphi .DFM files (Where the layout of Forms and other graphical stuff is stored). These files can be read, modified and rewritten from VP/2 programs. The TLSDEMO example ~~~~~~~~~~~~~~~~~~~ This example demonstrates the power of Thread Local Storage, TLS. A number of system variables (declared as globals in Borland Pascal) have been declared in Thread Local Storage using the Threadvar reserved word instead of Var in the VP/2 implementation. These include InOutRes, DosError, FileMode, ExecResult, etc. Declaring them as TLS means, that each thread in the program gets its own instance of the variable and does not corrupt the storage used by other threads - something that could cause a corruption or misbehaviour of the program. This example runs three threads, each doing a FindFirst/FindNext sequence. If TLS had not been implemented the program would not work, since DosError would be shared among the threads. The DLL examples ~~~~~~~~~~~~~~~~ These two examples use a common Dynamic Link Library, TSTVPDLL.DLL. This DLL exports just one function using the method normally used in Borland Pascal (as opposed to the by-unit method introduced in Virtual Pascal using the {$Exports} directive). The first example TESTDLL1 calls the function normally, with DLL loading, initialisation and termination handled by VP/2. The second example TESTDLL2 dynamically loads the DLL, finds the entry point of the routine, calls it, and disposes of the DLL. The FLAME example ~~~~~~~~~~~~~~~~~ Demonstrates how to do full-screen graphics in OS/2 using Virtual Pascal. The program runs in full screen mode only. Note, that it may appear as if OS/2 has hung while FLAME is running. What really happens is, that OS/2 delays task switching commands for 30 seconds while full screen graphics are running. The LISTEA example ~~~~~~~~~~~~~~~~~~ Demonstrates how to get access to Extended Attributes via a normal FindFirst - FindNext sequence. Run LISTEA from the command line, specifying a wildcard, and it will show a list of all files and directories that have EA's associated with them. The LISTCLS example ~~~~~~~~~~~~~~~~~~~ In this example, VP/2 interfaces with the OS/2 workplace shell, and displays a list of all object classes registered with the WPS. The OS2LOW example ~~~~~~~~~~~~~~~~~~ Is designed to help you converting your low level DOS code to OS/2, by demonstrating the use of some of the low level calls available through the Os2Base and VPUtils unit. When run, it displays various information that would require BIOS calls or other illegal low-level activity if it were to run under DOS. The RATRACE example ~~~~~~~~~~~~~~~~~~~ Demonstrates how to program a multithreading application in Virtual Pascal. The multithreaded application controls access to critical routines by using a MuTex semaphore. The program initialises 8 rats in different colours that are assigned a thread each and every time a thread becomes active, the rat moves forward one character. The final positions of the rats are then noted at the bottom of the screen. The REXXEXT example ~~~~~~~~~~~~~~~~~~~~ Shows, how new REXX functions can be implemented in Virtual Pascal. The DLL implements a Touch function similar to the one of the Touch example, and calls this function from a REXX script. The TESTCRT example ~~~~~~~~~~~~~~~~~~~ Demonstrates Virtual Pascal's compatibility with the Crt unit of Borland Pascal. When executed, the program plays a little tune, while filling a text window with a string of various colours. When you press a key, it manipulates the content of the window. The second part displays a "star sky", with blinking stars. The TRIPLEX example ~~~~~~~~~~~~~~~~~~~ Is an OS/2 Presentation Manager game, somewhat similar to the popular TETRIS game. Demonstrating the methodology required to implement PM programs using Virtual Pascal, this example is going to be much used. The BREAKOUT example ~~~~~~~~~~~~~~~~~~~~ Is a text mode version of the BreakOut game and is part of Borland Pascal v7. Hit the boxes with the ball, and make sure the ball does not slip past you. The TVDEMO example ~~~~~~~~~~~~~~~~~~ Demonstrates Virtual Pascal's astounding compatibility with Turbo Vision. The program demonstrates many of Turbo Vision's features by implementing a desktop with calculator, help, puzzle, editor, ascii table etc. The TVFM example ~~~~~~~~~~~~~~~~ This program implements a multiple-window drag/drop text-mode File Manager using Borland's Turbo Vision. The MathPak 87 examples ~~~~~~~~~~~~~~~~~~~~~~~ VP/2 includes a subset of the advanced MATHPAK87 library, featuring a large number of mathemathical routines optimised for speed and size. For detailed information about the library, please refer to the MathPak online documentation. The DEMO example ~~~~~~~~~~~~~~~~ This example fills an array with numbers ranging from 1 to 2000, and calculates the sum, mean and standard deviation of the numbers. The LEASTSQ example ~~~~~~~~~~~~~~~~~~~ This is an example program to show how MATHPAK 87 procedures can be used to program a polynomial least-squares data fitting program. See the Appendix of the online manual for a description of the program. The "The Art Of OS/2 Programming" examples ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All examples included with this book have been converted from C to Virtual Pascal, and are included in the full version. In this evaluation version, only a few of the examples are included. Terminal program ~~~~~~~~~~~~~~~~ This is a very simple example of communication with the serial port through DosDevIOCtl calls. The example communicates with COM1 by echoing keyboard input to the port, and displaying output from the port on the screen. The WinSave example ~~~~~~~~~~~~~~~~~~~ This is an examples of how to create a PM Window that saves its size so it is restored to the same size and position when it is next opened. The WinSize example ~~~~~~~~~~~~~~~~~~~ This example creates a PM window, and maintains a minimum size restriction for the window. The MLE3 example ~~~~~~~~~~~~~~~~ Is a demonstration of the Multi-Line Edit control. The example implements a simple editor window, which supports load/save from a file and cut/paste from the clipboard. The Contain4 example ~~~~~~~~~~~~~~~~~~~~ Demonstrates the use of the OS/2 Container class. Features a pop-up menu where a number of different view, filter and sort settings can be defined for the container. The FileDlg example ~~~~~~~~~~~~~~~~~~~ Shows how to use a simple OS/2 File-Open dialog. The Print example ~~~~~~~~~~~~~~~~~ Displays a list of all printers installed, and allows a small test print to be sent to one of your choice. Also demonstrates how to invoke the Printer Setup panel, etc.