Free Pascal and Lazarus Programming Textbook

Total Page:16

File Type:pdf, Size:1020Kb

Free Pascal and Lazarus Programming Textbook This page deliberately left blank. In the series: ALT Linux library Free Pascal and Lazarus Programming Textbook E. R. Alekseev O. V. Chesnokova T. V. Kucher Moscow ALT Linux; DMK-Press Publishers 2010 i UDC 004.432 BBK 22.1 A47 Alekseev E.R., Chesnokova O.V., Kucher T.V. A47 Free Pascal and Lazarus: A Programming Textbook / E. R. Alekseev, O. V. Chesnokova, T. V. Kucher M.: ALTLinux; Publishing house DMK-Press, 2010. 440 p.: illustrated.(ALT Linux library). ISBN 978-5-94074-611-9 Free Pascal is a free implementation of the Pascal programming language that is compatible with Borland Pascal and Object Pascal / Delphi, but with additional features. The Free Pascal compiler is a free cross-platform product implemented on Linux and Windows, and other operating systems. This book is a textbook on algorithms and programming, using Free Pascal. The reader will also be introduced to the principles of creating graphical user interface applications with Lazarus. Each topic is accompanied by 25 exercise problems, which will make this textbook useful not only for those studying programming independently, but also for teachers in the education system. The book’s website is: http://books.altlinux.ru/freepascal/ This textbook is intended for teachers and students of junior colleges and universities, and the wider audience of readers who may be interested in programming. UDC 004.432 BBK 22.1 This book is available from: The <<Alt Linux>> company: (495) 662-3883. E-mail: [email protected] Internet store: http://shop.altlinux.ru From the publishers <<Alians-kniga>>: Wholesale purchases: (495) 258-91-94, 258-91-95. E-mail: [email protected] Internet store: http://www.alians-kniga.ru/ The material in this book is distributed under the GNU FDL License. The book contains the following text on the first page after the cover: <<In the series: ALT Linux Library>>. The title is: <<Free Pascal and Lazarus: A Textbook on Programming>>. The book does not contain invariant sections. The authors of the sections are shown in the titles of the respective sections. ALT Linux is a trademark of ALT Linux. Linux is a trademark of Linus Torvalds. Other names in this textbook may be trademarks of their respective owners. ISBN 978-5-94074-611-9 © Alekseev E.R., Chesnokova O.V., Kucher T.V., 2010 © ALT Linux, 2010 ii Table of Contents From the Editors.....................................................................................................................1 About free software for education.................................................................................1 The “ALT Linux Library” Series.........................................................................................2 Introduction............................................................................................................................3 Chapter 1. Development Tools............................................................................................5 1.1 The Program Development Process........................................................................5 1.2 The Free Pascal Programming Environment..........................................................6 1.2.1 The Free Pascal Text Editor.....................................................................................9 1.2.2 Running a Program and Viewing Results...........................................................11 1.3 The Geany Development Environment.................................................................11 1.4 The Lazarus RAD Environment...............................................................................14 1.4.1 Installing Lazarus on Linux...................................................................................14 1.4.2 Installing Lazarus on Windows............................................................................15 1.4.3 The Lazarus Environment.....................................................................................17 1.4.4 The Lazarus Main Menu........................................................................................18 1.4.5 The Application Form............................................................................................22 1.4.6 The Lazarus Source Editor....................................................................................22 1.4.7 The Component Palette........................................................................................28 1.4.8 The Object Inspector.............................................................................................29 1.4.9 Your First Lazarus Program..................................................................................30 1.4.10 A Useful Program.................................................................................................38 1.4.11 A Lazarus IDE Console Application....................................................................43 1.4.12 Data Input / Output Statements........................................................................46 Chapter 2. Introduction to Free Pascal.............................................................................49 2.1 Lazarus Project Structure........................................................................................49 2.2 The Console Application Structure........................................................................50 2.3 Language Elements..................................................................................................52 2.4 Free Pascal Data Types............................................................................................52 2.4.1 The Character Type................................................................................................53 2.4.2 The Integer Types..................................................................................................53 2.4.3 The Real Type..........................................................................................................54 iii 2.4.4 The DateTime Type................................................................................................55 2.4.5 The Boolean Type...................................................................................................55 2.4.6 Creating New Types...............................................................................................55 2.4.7 The Enumeration Type..........................................................................................56 2.4.8 The Subrange Type................................................................................................56 2.4.9 Structured Types....................................................................................................57 2.4.10 Pointers.................................................................................................................59 2.5 Operators and Expressions.....................................................................................60 2.5.1 Arithmetic Operators.............................................................................................62 2.5.2 Relational Operators..............................................................................................64 2.5.3 Boolean Operators.................................................................................................64 2.5.4 Pointer Operators..................................................................................................64 2.6 Standard Mathematical Functions.........................................................................65 2.7 Exercises.....................................................................................................................75 Chapter 3. Flow Control......................................................................................................79 3.1 Principal Algorithm Constructs...............................................................................79 3.2 The Assignment Statement.....................................................................................81 3.3 The Compound Statement......................................................................................81 3.4 Selection Structures.................................................................................................81 3.4.1 The If..Then..Else Selection Structure..................................................................81 3.4.2 The Case Selection Structure................................................................................98 3.4.3 Error Handling and Displaying Messages........................................................101 3.5 Repetition Statements...........................................................................................105 3.5.1 The while..do Statement.....................................................................................105 3.5.2 The repeat..until Statement................................................................................107 3.5.3 The for..do Statement.........................................................................................108 3.5.4 Control Transfer Statements..............................................................................110 3.5.5 Solving Problems Using Loops...........................................................................111 3.5.6 Entering Data Using an InputBox......................................................................126 3.6 Exercises..................................................................................................................135
Recommended publications
  • KDE 2.0 Development, Which Is Directly Supported
    23 8911 CH18 10/16/00 1:44 PM Page 401 The KDevelop IDE: The CHAPTER Integrated Development Environment for KDE by Ralf Nolden 18 IN THIS CHAPTER • General Issues 402 • Creating KDE 2.0 Applications 409 • Getting Started with the KDE 2.0 API 413 • The Classbrowser and Your Project 416 • The File Viewers—The Windows to Your Project Files 419 • The KDevelop Debugger 421 • KDevelop 2.0—A Preview 425 23 8911 CH18 10/16/00 1:44 PM Page 402 Developer Tools and Support 402 PART IV Although developing applications under UNIX systems can be a lot of fun, until now the pro- grammer was lacking a comfortable environment that takes away the usual standard activities that have to be done over and over in the process of programming. The KDevelop IDE closes this gap and makes it a joy to work within a complete, integrated development environment, combining the use of the GNU standard development tools such as the g++ compiler and the gdb debugger with the advantages of a GUI-based environment that automates all standard actions and allows the developer to concentrate on the work of writing software instead of managing command-line tools. It also offers direct and quick access to source files and docu- mentation. KDevelop primarily aims to provide the best means to rapidly set up and write KDE software; it also supports extended features such as GUI designing and translation in con- junction with other tools available especially for KDE development. The KDevelop IDE itself is published under the GNU Public License (GPL), like KDE, and is therefore publicly avail- able at no cost—including its source code—and it may be used both for free and for commer- cial development.
    [Show full text]
  • The Linux Kernel Module Programming Guide
    The Linux Kernel Module Programming Guide Peter Jay Salzman Michael Burian Ori Pomerantz Copyright © 2001 Peter Jay Salzman 2007−05−18 ver 2.6.4 The Linux Kernel Module Programming Guide is a free book; you may reproduce and/or modify it under the terms of the Open Software License, version 1.1. You can obtain a copy of this license at http://opensource.org/licenses/osl.php. This book is distributed in the hope it will be useful, but without any warranty, without even the implied warranty of merchantability or fitness for a particular purpose. The author encourages wide distribution of this book for personal or commercial use, provided the above copyright notice remains intact and the method adheres to the provisions of the Open Software License. In summary, you may copy and distribute this book free of charge or for a profit. No explicit permission is required from the author for reproduction of this book in any medium, physical or electronic. Derivative works and translations of this document must be placed under the Open Software License, and the original copyright notice must remain intact. If you have contributed new material to this book, you must make the material and source code available for your revisions. Please make revisions and updates available directly to the document maintainer, Peter Jay Salzman <[email protected]>. This will allow for the merging of updates and provide consistent revisions to the Linux community. If you publish or distribute this book commercially, donations, royalties, and/or printed copies are greatly appreciated by the author and the Linux Documentation Project (LDP).
    [Show full text]
  • Bag-Of-Features Image Indexing and Classification in Microsoft SQL Server Relational Database
    Bag-of-Features Image Indexing and Classification in Microsoft SQL Server Relational Database Marcin Korytkowski, Rafał Scherer, Paweł Staszewski, Piotr Woldan Institute of Computational Intelligence Cze¸stochowa University of Technology al. Armii Krajowej 36, 42-200 Cze¸stochowa, Poland Email: [email protected], [email protected] Abstract—This paper presents a novel relational database ar- data directly in the database files. The example of such an chitecture aimed to visual objects classification and retrieval. The approach can be Microsoft SQL Server where binary data is framework is based on the bag-of-features image representation stored outside the RDBMS and only the information about model combined with the Support Vector Machine classification the data location is stored in the database tables. MS SQL and is integrated in a Microsoft SQL Server database. Server utilizes a special field type called FileStream which Keywords—content-based image processing, relational integrates SQL Server database engine with NTFS file system databases, image classification by storing binary large object (BLOB) data as files in the file system. Microsoft SQL dialect (Transact-SQL) statements I. INTRODUCTION can insert, update, query, search, and back up FileStream data. Application Programming Interface provides streaming Thanks to content-based image retrieval (CBIR) access to the data. FileStream uses operating system cache for [1][2][3][4][5][6][7][8] we are able to search for similar caching file data. This helps to reduce any negative effects images and classify them [9][10][11][12][13]. Images can be that FileStream data might have on the RDBMS performance.
    [Show full text]
  • Note on Using the CS+ Integrated Development Environment
    Tool News RENESAS TOOL NEWS on April 16, 2015: 150416/tn2 Note on Using the CS+ Integrated Development Environment When using the CS+ IDE, take note of the problem described in this note regarding the following point. Statements in source code which form a deeply-nested block 1. Products Concerned Products from the following list for which the version number of the CS+ common program is 3.00.00 to 3.01.00. - RX Family C/C++ Compiler Package (with IDE) - RL78 Family C Compiler Package (with IDE) - RH850 Family C Compiler Package (with IDE) - CS+ evaluation edition To check the version number of the product you have, refer to the following URL. https://www.renesas.com/cubesuite+_ver 2. Description CS+ might be terminated forcibly when a program is downloaded to a debugging tool or when an editor panel is opened after downloading a program. 3. Conditions Forced termination may occur when the source code for a project includes code that meets any of the following conditions. (a) { } blocks nested to a depth of 128 or more within a function. (b) 64 or more consecutive "else if" conditions are in sequence. (c) The total of double the number of consecutive "else if" conditions and the depth of the nesting of {} blocks at some point in the sequence of consecutive "else if" conditions is 128 or more. With conditions (b) and (c) above, the problem only arises when the C99 option is designated and the product is the RX family C/C++ compiler package (with IDE). 4. Workaround To avoid this problem, do any of the following.
    [Show full text]
  • Writing Your First Linux Kernel Module
    Writing your first Linux kernel module Praktikum Kernel Programming University of Hamburg Scientific Computing Winter semester 2014/2015 Outline ● Before you start ● Hello world module ● Compile, load and unload ● User space VS. kernel space programing ● Summary Before you start ● Define your module’s goal ● Define your module behaviour ● Know your hardware specifications ○ If you are building a device driver you should have the manual ● Documentation ○ /usr/src/linux/Documentation ○ make { htmldocs | psdocs | pdfdocks | rtfdocks } ○ /usr/src/linux/Documentation/DocBook Role of the device driver ● Software layer between application and device “black boxes” ○ Offer abstraction ■ Make hardware available to users ○ Hide complexity ■ User does not need to know their implementation ● Provide mechanism not policy ○ Mechanism ■ Providing the flexibility and the ability the device supports ○ Policy ■ Controlling how these capabilities are being used Role of the device driver ● Policy-free characteristics ○ Synchronous and asynchronous operations ○ Exploit the full capabilities of the hardware ○ Often a client library is provided as well ■ Provides capabilities that do not need to be implemented inside the module Outline ● Before you start ● Hello world module ● Compile, load and unload ● User space VS. kernel space programing ● Summary Hello world module /* header files */ #include <linux/module.h> #include <linux/init.h> /* the initialization function */ /* the shutdown function */ static int __init hello_init(void) { static void __exit hello_exit(void)
    [Show full text]
  • Rapid Application Development Software | Codegear RAD Studio
    RAD Studio 2010 Product Review Guide August 2009 Corporate Headquarters EMEA Headquarters Asia-Pacific Headquarters 100 California Street, 12th Floor York House L7. 313 La Trobe Street San Francisco, California 94111 18 York Road Melbourne VIC 3000 Maidenhead, Berkshire Australia SL6 1SF, United Kingdom RAD Studio 2010 Reviewer Guide TABLE OF CONTENTS Table of Contents ............................................................................................................................ - 1 - Introduction ...................................................................................................................................... - 3 - General Overview of RAD Studio 2010 ...................................................................................... - 3 - What is New in RAD Studio 2010 ............................................................................................... - 3 - A Word on Delphi Prism ............................................................................................................. - 6 - Prerequisites ................................................................................................................................ - 7 - Minimum System Requirements ................................................................................................. - 7 - Internationalizations .................................................................................................................... - 7 - Editions ........................................................................................................................................
    [Show full text]
  • RPC Broker 1.1 Deployment, Installation, Back-Out, and Rollback Ii May 2020 (DIBR) Guide
    RPC Broker 1.1 Deployment, Installation, Back-Out, and Rollback (DIBR) Guide May 2020 Department of Veterans Affairs (VA) Office of Information and Technology (OIT) Enterprise Program Management Office (EPMO) Revision History Documentation Revisions Date Revision Description Authors 05/05/2020 8.0 Tech Edits based on the Broker REDACTED Development Kit (BDK) release with RPC Broker Patch XWB*1.1*71: • Changed all references throughout to “Patch XWB*1.1*71” as the latest BDK release. • Updated the release date in Section 3. • Updated all project dates in Table 4. • Added a “Skip This Step” note in Section 4.3.2. • Updated “Disclaimer” note in Section 4.8. • Added “Skip Step ” disclaimer to Section 4.8.1. • Deleted Sections 4.8.1.3, 4.8.1.3.1, and 4.8.1.3.2, since there are no VistA M Server routines installed with RPC Broker Patch XWB*1.1*71. • Updated Section 4.8.2.1.4; deleted Figure 3, “Sample Patch XWB*1.1*71 Installation Dialogue (Test System),” since there are no VistA M Server routines installed with RPC Broker Patch XWB*1.1*71. • Updated Section 5.2; Added content indicating install is only on Programmer-Only workstations. • Updated Section 5.6.1; added a “Skip Step” disclaimer and deleted Figure 9, “Restoring VistA M Server Files from a Backup Message,” since there are no VistA M Server routines RPC Broker 1.1 Deployment, Installation, Back-Out, and Rollback ii May 2020 (DIBR) Guide Date Revision Description Authors installed with RPC Broker Patch XWB*1.1*71.
    [Show full text]
  • The Design of a Pascal Compiler Mohamed Sharaf, Devaun Mcfarland, Aspen Olmsted Part I
    The Design of A Pascal Compiler Mohamed Sharaf, Devaun McFarland, Aspen Olmsted Part I Mohamed Sharaf Introduction The Compiler is for the programming language PASCAL. The design decisions Concern the layout of program and data, syntax analyzer. The compiler is written in its own language. The compiler is intended for the CDC 6000 computer family. CDC 6000 is a family of mainframe computer manufactured by Control Data Corporation in the 1960s. It consisted of CDC 6400, CDC 6500, CDC 6600 and CDC 6700 computers, which all were extremely rapid and efficient for their time. It had a distributed architecture and was a reduced instruction set (RISC) machine many years before such a term was invented. Pascal Language Imperative Computer Programming Language, developed in 1971 by Niklaus Wirth. The primary unit in Pascal is the procedure. Each procedure is represented by a data segment and the program/code segment. The two segments are disjoint. Compiling Programs: Basic View Machine Pascal languag program Pascal e compile program filename . inpu r gp output a.out p t c Representation of Data Compute all the addresses at compile time to optimize certain index calculation. Entire variables always are assigned at least one full PSU “Physical Storage Unit” i.e CDC6000 has ‘wordlength’ of 60 bits. Scalar types Array types the first term is computed by the compiler w=a+(i-l)*s Record types: reside only within one PSU if it is represented as packed. If it is not packed its size will be the size of the largest possible variant. Data types … Powerset types The set operations of PASCAL are realized by the conventional bit-parallel logical instructions ‘and ‘ for intersection, ‘or’ for union File types The data transfer between the main store buffer and the secondary store is performed by a Peripheral Processor (PP).
    [Show full text]
  • Read and Write Images from a Database Using SQL Server
    HOWTO: Read and write images from a database using SQL Server Atalasoft is an imaging SDK and we do not directly have any dependencies on, or specific functionality for Database access (with the single exception of our DbImageSource class). However, since the typical means of image storage in a database is a BLOB (Binary Long Object), developers can take advantage of the AtalaImage.ToByteArray and AtalaImage.FromByteArray methods to use in their own code to store and retrieve image data to and from databases respectively. Atalasoft dotImage has streaming capabilities that can be used jointly with ADO.NET to read and write images directly to a database without saving to a temporary file. The following code snippets demonstrates this in C# and VB.NET. Please note that the code examples below are provided as a courtesy/convenience only and are not meant to be production code or represent the only way to access a database. The code is provided as is as but an example of how to get the needed data in a byte array suitable for use in storing to a database and how to take binary data containing an image back into an AtalaImage to use in our SDK. Write to a Database C# rivate void SaveToSqlDatabase(AtalaImage image) { SqlConnection myConnection = null; try { // Save image to byte array. // we will be storing this image as a Jpeg using our JpegEncoder with 75 quality // you could use any of our ImageEncoder classes to store as the respective image types byte[] imagedata = image.ToByteArray(new Atalasoft.Imaging.Codec.JpegEncoder(75)); // Create the SQL statement to add the image data.
    [Show full text]
  • LAZARUS UNDER the HOOD Executive Summary
    LAZARUS UNDER THE HOOD Executive Summary The Lazarus Group’s activity spans multiple years, going back as far as 2009. Its malware has been found in many serious cyberattacks, such as the massive data leak and file wiper attack on Sony Pictures Entertainment in 2014; the cyberespionage campaign in South Korea, dubbed Operation Troy, in 2013; and Operation DarkSeoul, which attacked South Korean media and financial companies in 2013. There have been several attempts to attribute one of the biggest cyberheists, in Bangladesh in 2016, to Lazarus Group. Researchers discovered a similarity between the backdoor used in Bangladesh and code in one of the Lazarus wiper tools. This was the first attempt to link the attack back to Lazarus. However, as new facts emerged in the media, claiming that there were at least three independent attackers in Bangladesh, any certainty about who exactly attacked the banks systems, and was behind one of the biggest ever bank heists in history, vanished. The only thing that was certain was that Lazarus malware was used in Bangladesh. However, considering that we had previously found Lazarus in dozens of different countries, including multiple infections in Bangladesh, this was not very convincing evidence and many security researchers expressed skepticism abound this attribution link. This paper is the result of forensic investigations by Kaspersky Lab at banks in two countries far apart. It reveals new modules used by Lazarus group and strongly links the tools used to attack systems supporting SWIFT to the Lazarus Group’s arsenal of lateral movement tools. Considering that Lazarus Group is still active in various cyberespionage and cybersabotage activities, we have segregated its subdivision focusing on attacks on banks and financial manipulations into a separate group which we call Bluenoroff (after one of the tools they used).
    [Show full text]
  • Delphi 8 for .NET HOE WERKT DELPHI 8 for .NET EN WAT ZIJN DE VERSCHILLEN MET VISUAL STUDIO.NET?
    Bob Swart is auteur, trainer en consultant bij Bob Swart Training & Consultancy. Delphi 8 for .NET HOE WERKT DELPHI 8 FOR .NET EN WAT ZIJN DE VERSCHILLEN MET VISUAL STUDIO.NET? Dit artikel introduceert Delphi 8 for .NET, en laat zien hoe we .NET-toepassingen kunnen ontwikkelen met de nieuwste IDE voor het .NET Framework. Omdat de meeste lezers op de hoogte zullen zijn van de mogelijkheden van Visual Studio.NET, gaat dit artikel met name in op de verschillen, zowel in positieve als wat minder positieve zin. elphi 8 for the Microsoft .NET Framework is de officiële niet alleen als twee druppels water op die van Visual Studio, maar naam, maar de meeste ontwikkelaars noemen het gewoon is daadwerkelijk de designer van Microsoft. Dat heeft als voordeel DDelphi 8 of Delphi 8 for .NET (alleen Delphi for .NET is dat gebruikers van Visual Studio zonder al teveel problemen de niet volledig, want bij Delphi 7 zat eind 2002 al een Delphi for .NET proefversie van Delphi 8 for .NET kunnen gebruiken om eens te preview command-line compiler, die echter niet te vergelijken is met proeven hoe het werkt.1 wat nu als Delphi 8 for .NET beschikbaar is). Alhoewel Delphi 8 for .NET een relatieve nieuwkomer is op het .NET Framework, geldt dat In afbeelding 1 zien we de Object Inspector, WinForms Designer, niet voor de taal Delphi zelf. Delphi 1.0 wordt op Valentijns dag in een Tool Palette met componenten en rechtsboven een venstertje 1995 gelanceerd, en was in feite de 8ste generatie van Turbo Pascal waarin je met de Project Manager, Model View (daarover later) of compiler, die het eerste daglicht ziet in het begin van de 80-er jaren.
    [Show full text]
  • LAZARUS FREE PASCAL Développement Rapide
    LAZARUS FREE PASCAL Développement rapide Matthieu GIROUX Programmation Livre de coaching créatif par les solutions ISBN 9791092732214 et 9782953125177 Éditions LIBERLOG Éditeur n° 978-2-9531251 Droits d'auteur RENNES 2009 Dépôt Légal RENNES 2010 Sommaire A) À lire................................................................................................................5 B) LAZARUS FREE PASCAL.............................................................................9 C) Programmer facilement..................................................................................25 D) Le langage PASCAL......................................................................................44 E) Calculs et types complexes.............................................................................60 F) Les boucles.....................................................................................................74 G) Créer ses propres types..................................................................................81 H) Programmation procédurale avancée.............................................................95 I) Gérer les erreurs............................................................................................105 J) Ma première application................................................................................115 K) Bien développer...........................................................................................123 L) L'Objet..........................................................................................................129
    [Show full text]