CPIde - Component Pascal Source Code Examples

CPIde: Component Pascal Development System for Windows
Version 8.1 Copyright © 2006-2022 CFB Software
Email: support@astrobe.com
Website: www.astrobe.com/CPIde

Last Updated 17 Jan 2022

Contents

  1. Introduction
  2. WinForms Examples
  3. Console Output Examples
  4. Library Module Examples
  5. Oberon for FPGA RISC5 Compiler
  6. Licence Agreements

Introduction

When you install CPIde, the source code of these examples is located in your CPIde-v8.1\Examples folders.

When you run the compiled applications in CPIde, the Console Applications display their output in a separate pane in the main CPIde Window where the compilation error messages are also displayed. The WinForms programs are executed as a separate Windows application.

Back to Contents

WinForms Examples

BouncingBall.cp Simple Animated Graphics
A ball bouncing off the borders of a resizable form.
 
BouncingBalls.cp Simple Animated Graphics
Two independent balls bouncing off the walls of a resizable form. It is designed to be easily modified to add extra balls of different size, colour and speed.

Graphics.cp Graphic Shapes, Text and Lines
Draws squares, circles, text with different fonts and lines of different colours on a .NET PictureBox.

ImageFromFile.cp Display an Image
Enter the filename of a jpg or bmp format file when prompted by a standard File Open dialog. The image is displayed on a resizable form.
 
MouseMove.cp Event Handling
Move the mouse over the resizable form. The Mouse Move events are registered and the corresponding mouse co-ordinates are displayed in the Status Bar.
 
MenuStrip.cp MenuStrip
Select a menu item and the menu caption is displayed on the StatusBar. Includes a function to strip non-alphabetic characters from a string using a StringBuilder.

SecondsTimer.cp Seconds Timer
A minutes and seconds timer.  Uses Timer control, Timer.Tick event and DateTime data type.

Countdown.cp Countdown Timer
A minutes and seconds countdown timer.  Uses NumericUpDown and Timer controls, Form.Activated and Timer.Tick events and DateTime data type.

Mailer.cp
 
Send an Email
Functions of the System.Net.Mail assembly are used to create and send emails.  Uses a MenuStrip, a Panel, Labels, TextBoxes and a RichTextBox control. Update the App Config file, Mailer.exe.Config, with your email server authentication details.
 
Birthdays.cp
birthdays.tsv
Birthday Reminder
Read a list of birthdays from a tab-separated (tsv) text file and display it in a DataGridView component. The fields, current age and date of next birthday, are read-only. They are automatically calculated from the date of birth. The display is sorted by 'Next Birthday, Last Name' so that, by default, the next occurring birthday is at the top of the list.

Back to Contents

Console Output Examples

Evens.cp FOR Loop
Display the even numbers from 2 to 10.
 
Out.cp Console Output Functions
Basic output library module used by some of the following programs. Useful if porting simple examples from an Oberon environment.
 
CountChars1.cp WHILE Loop
Count, one by one, the number of characters in a string array.
 
CountChars2.cp ARRAY OF CHAR / Strings
Count the number of characters in a string using the standard Component Pascal LEN function.
 
CountChars3.cp IF THEN ELSE Statement
Count the number of letters and digits in a string using IF THEN ELSE statements.
 
CountChars4.cp IF THEN ELSIF Statement
Count the number of occurrences of different categories of characters in a string using IF THEN ELSIF statements.
 
CountChars5.cp CASE Statement
Count the number of occurrences of different categories of characters in a string using a CASE statement.
 
CountChars6.cp Performance Timing
Count the number of occurrences of different categories of characters in a huge string (1 million characters) using two different techniques. One uses a CASE statement and the other uses IF THEN ELSE statements. To compare the relative efficiencies, the processing time of each technique is measured using .NET timing procedures which have microsecond resolution.
 
FileCountChars.cp Text File Input
Count the number of occurrences of different categories of characters in a text file using a StreamReader, Command-line arguments and a CASE statement.
 
CopyText.cp Text File IO
When you run the program it creates a duplicate (called Copy of CopyText.cp) of its source.  Uses StreamReader and StreamWriter functions to copy an entire text file to / from a string.
 
SplitText.cp
SplitLines.txt
Text File IO
Uses StreamReader and StreamWriter functions to read the contents of the text file SplitText.txt line by line, creating a set of subfiles SplitLines.001, SplitLines.002 etc. each with a maximum of 100 lines.
 
MergeText.cp Text File IO
Uses StreamReader and StreamWriter text file IO functions to join the set of files SplitLines.001, SplitLines.002 etc. into a single file MergeLines.txt
 
EnvironmentVars.cp Environment Variables
Display the contents of the system's PATH and CPSYM environment variables.
 
Registry.cp Windows Registry
Display the current values of some of the CPIde registry keys read from the Windows Registry.
 
Directory.cp Directory Listing
Display the list of files and their attributes in the current directory. Uses the SET data type to conveniently process System.IO.AttributeFlags.
 

Back to Contents

Library Module Examples

NetLibs.cp Interface Definitions for Commonly Used .NET Modules
Open this file in the Component Pascal IDE then double-click on the name of one of the listed imported modules in the CPI Imports Window to view the definition of the module's interface.
 
Maths.cp
TestMaths.cp
 
Additional Maths Functions
Sum, Mean, Variance, Standard Deviation and Random functions are implemented.
 
Find.cp
TestFind.cp
 
A Non-modal FindText dialog
Uses the following Windows Forms controls: CheckBoxes, Buttons, a Label, and a ComboBox. A multi-line TextBox is used to log any user actions.

Back to Contents

Oberon for FPGA RISC5 Compiler

This Oberon for FPGA RISC5 command-line compiler, AstrobeCompile, is built from the same source code modules used for the Oberon compiler in Astrobe for FPGA RISC5. Consequently, the source code, symbol files and code files it uses and generates are 100% compatible with those used by the Astrobe IDE compiler. The only differences are:

When AstrobeCompile and all of its dependent modules have been compiled, the source code of the included example Oberon library module Random.Mod can be compiled using the command:

AstrobeCompile.exe <foldername>Random.Mod

<foldername> can be omitted if the source code file is in the same folder as AstobeCompile.exe

AstrobeCompile.cp Main Program
Processes the command line argument, initialises the modules and starts the compilation.
ORB.cp Symbol File Handler
Creates symbol files (*.smb) for exported items and reads the related symbol file when a module is imported.
ORE.cp Globals
Common declarations used by more than one module.
ORG.cp Code Generator
Generates the RISC instructions and module linking information and saves them in a code file (*.rsc)
ORP.cp Parser
Checks data types for compatibility, allocates memory for variables, identifies Oberon language statements and expressions using the syntax rules and calls the appropriate Code Generator functions.
ORS.cp Scanner
Reads the source text file of the Oberon module and converts it into a tokenised form so that it can be efficiently processed by the Parser.
Files.cp Binary File Input / Output
Handles all of the file access and reading / writing operations used by the Symbol File Handler and Code Generator.
Texts.cp Text Input / Output
Reads Oberon source code text files and writes error and status messages to the console.
Random.Mod Random Number Generator
An example Oberon library module that can be compiled by the command-line compiler.

Back to Contents

Licence Agreements

CPIde Examples Source Code

Copyright (c) 2006-2022 CFB Software.
https://www.astrobe.com/CPIde

Permission to use, copy, modify, and/or distribute these examples in source code form (the "Software") for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 

DISCLAIMER

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THE SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES OR LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DEALINGS IN OR USE OR PERFORMANCE OF THE SOFTWARE.


The RISC5 Oberon compiler example is subject to the following licence agreement:

Project Oberon, Revised Edition 2013

Book copyright 2013 Niklaus Wirth and Juerg Gutknecht;
software copyright 2013 Niklaus Wirth (NW), Juerg Gutknecht (JG), Paul Reed (PR/PDR).

Permission to use, copy, modify, and/or distribute this software and its accompanying documentation (the "Software") for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THE SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES OR LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DEALINGS IN OR USE OR PERFORMANCE OF THE SOFTWARE.

Back to Contents