Buttons

CPIde


Features
Download
 

CP Examples
CP Resources

 

 

 

Component Pascal Examples
v2.1.1 - Updated 9 Jul 2008

The examples are presented here as text files to be viewed in your browser. If you want to compile and run the examples download the file CPExamples.2.1.1.zip (34Kb)

Console Output Examples
 
Evens.txt FOR Loop
Display the even numbers from 2 to 10.
 
Out.txt Console Output Functions
Basic output library module used by some of the following programs. Useful if porting simple examples from an Oberon environment.
 
CountChars1.txt WHILE Loop
Count, one by one, the number of characters in a string array.
 
CountChars2.txt ARRAY OF CHAR / Strings
Count the number of characters in a string using the standard Component Pascal LEN function.
 
CountChars3.txt IF THEN ELSE Statement
Count the number of letters and digits in a string using IF THEN ELSE statements.
 
CountChars4.txt IF THEN ELSIF Statement
Count the number of occurrences of different categories of characters in a string using IF THEN ELSIF statements.
 
CountChars5.txt CASE Statement
Count the number of occurrences of different categories of characters in a string using a CASE statement.
 
CountChars6.txt 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.txt 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.txt 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.txt
 
Text File IO
Uses StreamReader and StreamWriter functions to read the contents of the text file SplitLines.txt line by line, creating a set of subfiles SplitLines.001, SplitLines.002 etc. each with a maximum of 100 lines.
 
MergeText.txt 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.txt Environment Variables
Display the contents of the system's PATH and CPSYM environment variables.
 
Registry.txt Windows Registry
Display the current values of the CPIde options' registry keys read from the Windows Registry.
 
Directory.txt 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.
 


WinForms Examples
 
BouncingBall.txt Simple Animated Graphics
A ball bouncing off the borders of a resizable form.
 
BouncingBalls.txt 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.txt Graphic Shapes, Text and Lines
Draws squares, circles, text with different fonts and lines of different colours on a .NET PictureBox.
 
ImageFromFile.txt 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.txt 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.txt 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.txt Seconds Timer
A minutes and seconds timer.  Uses Timer control, Timer.Tick event and DateTime data type.
 
Countdown.txt Countdown Timer
A minutes and seconds countdown timer.  Uses NumericUpDown and Timer controls, Form.Activated and Timer.Tick events and DateTime data type.
 
Mailer.txt
 
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.
 
Birthdays.txt Birthday Reminder
Read a list of birthdays from a tab-separated text file Birthdays.tsv 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.
 


Library Module Examples
 
NetLibs.txt Interface Definitions for Commonly Used .NET Modules
Open this file in the Component Pascal IDE (CPIde version 2.0 or later) 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.txt
TestMaths.txt
 
Additional Maths Functions
Sum, Mean, Variance, Standard Deviation and Random functions are implemented.
 
Find.txt
TestFind.txt
 
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.
 

 

Copyright
Copyright © 2008 CFB Software All rights reserved. Privacy Policy
ABN 20 939 391 060