Mastering. Pascal and Delphi Programming

Similar documents
0 Mastering Microsoft Office

MACMILAN MASTER SBUEI

Mastering. Spreadsheets Q

Mastering. C Programming 0

MASTERING COBOL PROGRAMMING

Program and Electronic Projects for the SSC, Electron and Spectrum Computers

In Business Now Series Graphs and Charts Renee Huggett Markets Renee Huggett

Fundamentals of Operating Systems. Fifth Edition

.,JID Macmillan Modern Office f..dst'pj lnto . 4 D I. :.sp.. w ay :e ~l. ..II Joanna Gosling l... l. MACMILLAN

GCSE & GCE Summer 2018 Exam Timetable

Macmillan Computer Science Series

Changes to assessment in Higher courses from session onwards

Contents 8086 Processor 8086/8088 Instructions 80386/80486 Pentium/Pentium Pro 8086 Interfacing and Timing

Pearson New International Edition. The 8051 Microcontroller and Embedded Systems Mazidi Mazidi McKinlay Second Edition

Interfacing with C++

Computer Literacy - A Beginners' Guide

Graphics Programming in c++

Word Processing with Amstrad

Digital Electronics A Practical Approach with VHDL William Kleitz Ninth Edition

C for Electronic Engineering

COURSE NUMBER TITLE F14 S15 F15 S16 F16 S17 F17 S18 ACCT 100 ACCOUNTING LAB X X X X X X X X ACCT 101 PRINCIPLES of ACCOUNTING I X X X X X X X X ACCT

New Syllabus Mathematics for 0-Level 1

Research on Industrial Security Theory

Using the Template to Format the Thesis/Dissertation

Advanced Graphics with the Commodore 128

Assembly Language Assembled for the Sinclair ZX81

A Structured Programming Approach to Data

Essential Series. Springer-Verlag London Ltd.

C Programming for Electronic Engineers

Only the original curriculum in Danish language has legal validity in matters of discrepancy

Fundamentals of Operating Systems

x 1) send an to stating the material you would like to obtain

16/03/2018 Pearson GCE 9DR0 Drama & Theatre Externally Set Assignment day all day

General Qualifications 2017/2018

FUZZY LOGIC WITH ENGINEERING APPLICATIONS

Please note: Only the original curriculum in Danish language has legal validity in matters of discrepancy. CURRICULUM

Stock Message Boards

An Introduction to Programming with IDL

Lexical Priming in Spoken English Usage

Measuring the effectiveness of your ISMS implementations based on ISO/IEC 27001

FUNDAMENTALS OF COMPUTER PROGRAMMING AND IT

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

C PROGRAMMING THE C PROGRAMMING THE PDF C PROGRAMMING TUTORIAL IN PDF - CURRENT AFFAIRS 2018 C (PROGRAMMING LANGUAGE) - WIKIPEDIA

General Qualifications

FINAL GCE/GCSE/BTEC EXAM TIMETABLE SUMMER 2018

Network Performance Analysis

Numerical Analysis Timothy Sauer Second Edition

Summer Exam Timetable 2018

EXAMINATIONS TIMETABLE SUMMER 2015 DATE START LENGTH BOARD COMP.CODE COMP.TITLE LEVEL VENUE NO.CAND

Software Development & Education Center C Programming

Unit level raw mark and UMS grade boundaries January 2011 series. AS GCE / Advanced GCE / AS GCE Double Award / Advanced GCE Double Award

Grade Boundaries. Edexcel International AS/A Level. June 2018

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Elementary Number Theory. Kenneth H. Rosen Sixth Edition

INFORMATION SECURITY FOR MANAGERS

Grade Boundaries. Edexcel International AS/A Level. January 2018

Foundations of 3D Graphics Programming

August 2011 Graduating Class Employment Data Last Updated on

C++ Programming for Programmers

COMPUTER SCIENCE, BACHELOR OF SCIENCE (B.S.)

International Political Economy

Provisional Summer Exam Timetable 2018

TortoiseSVN 1.7. Beginner's Guide. Perform version control in the easiest way with the best SVN client TortoiseSVN.

MacmUI8D Computer Science Series Consulting Editor: Professor F.H. Sumner, University of Manchester

Pre-Matriculation Test Credits for

SDH/SONET Explained in Functional Models

Macmillan Computer Science Series Consulting Editor: Professor F.H. Sumner, University of Manchester

COMPUTER SCIENCE, BACHELOR OF SCIENCE (B.S.) WITH A CONCENTRATION IN CYBERSECURITY

DOI: / Scandinavian Object Shift and Optimality Theory

Curriculum Information St Paul s Catholic College September 2017

Guide to the implementation and auditing of ISMS controls based on ISO/IEC 27001

THE ARCHITECTURE OF COMPUTER HARDWARE, SYSTEM SOFTWARE, AND NETWORKING

Cheadle Hulme Sixth Form Application Form: 2019 Entry

SymbolicC++: An Introduction to Computer Algebra using Object-Oriented Programming

Engineering with Excel. Ronald W. Larsen Fourth Edition

B.Sc II Year Computer Science (Optional)

C++ Programming for Programmers using Microsoft Visual C Professional

This content has been downloaded from IOPscience. Please scroll down to see the full text.

GO! with Microsoft Access 2010 Introductory Gaskin Mclellan Graviett First Edition

Summer 2018 Provisional External Timetable

Microprocessor Theory

GLOBAL EDITION. Assembly Language. for x86 Processors SEVENTH EDITION. Kip R. Irvine

Programmable Logic Controllers. Second Edition

Next Generation Networks Perspectives and Potentials. Dr Jingming Li Salina LiSalina Consulting, Switzerland Pascal Salina Swisscom SA, Switzerland

Understanding and Writing Compilers

Inside Relational Databases with Examples in Access

Gcse Religious Studies Unit 11 Paper

MICROPROCESSOR Architecture, Programming and Interfacing SUNIL MATHUR. Assistant Professor Maharaja Agrasen Institute of Technology Delhi

Logic Programming with Prolog

UCF Academic Program Review Seven-Year Cycle

CYBERCRIME AS A NEW FORM OF CONTEMPORARY CRIME

A Structured Programming Approach to Data

Workplace Communications The Basics George J. Searles Fifth Edition

Summer Examinations 2018

JUNE 2016 WEEK 1. Time Code Title Loc. Dur. Ent Date Time Code Title Loc. Dur. Ent. Mon 16 May. Tue 17 May. Thu 19 May. Fri 20 May

The Commodore 64 in Action

B.TECH(COMPUTER) Will be equipped with sound knowledge of mathematics, science and technology useful to build complex computer engineering solutions.

SUMMER 2011 EXAMINATION TIMETABLE

Intexta Web Services Privacy Statement

Unit level raw mark and UMS grade boundaries January 2012 series. AS GCE / Advanced GCE / AS GCE Double Award / Advanced GCE Double Award

Transcription:

Mastering Pascal and Delphi Programming

MACMILLAN MASTER SERIES Accounting Advanced English Language Advanced Pure Mathematics Arabic Banking Basic Management Biology British Politics Business Administration Business Communication Business Law C Programming C++ Programming Catering Theory Chemistry COBOL Programming Communication Databases Economic and Social History Economics Electrical Engineering Electronic and Electrical Calculations Electronics English as a Foreign Language English Grammar English Language English Literature French French 2 German German 2 Global Information Systems Human Biology Internet Italian Italian 2 Java Manufacturing Marketing Mathematics Mathematics for Electrical and Electronic Engineering Microsoft Office Modern British History Modern European History Modern World History Pascal and Delphi Programming Philosophy Photography Physics Psychology Science Shakespeare Social Welfare Sociology Spanish Spanish 2 Statistics Study Skills Visual Basic World Religions Macmillan Master Series Series Standing Order ISBN 978-0-333-69343-8 (outside North America only) You can receive future titles in this series as they are published by placing a standing order. Please contact your bookseller or, in case of difficulty, write to us at the address below with your name and address, the title of the series and the ISBN quoted above. Customer Services Department, Macmillan Distribution Ltd Houndmills, Basingstoke, Hampshire RG21 6XS, England

Mastering Pascal and Delphi Programming William Buchanan, BSc, CEng, PhD Senior Lecturer Department of Electrical and Electronic Engineering Napier University Edinburgh Series Editor William Buchanan ~ MACMILLAN

William Buchanan 1998 All rights reserved. No reproduction, copy or transmission of this publication may be made without written permission. No paragraph of this publication may be reproduced, copied or transmitted save with written permission or in accordance with the provision of the Copyright, Designs and Patents Act 1988, or under the terms of any licence permitting limited copying issued by the Copyright Licensing Agency, 90 Tottenham Court Road, London W1P 9HE. Any person who does any unauthorised act in relation to this publication may be liable to criminal prosecution and civil claims for damages. The author has asserted his right to be identified as the author of this work in accordance with the Copyright, Designs and Patents Act 1988. Published 1998 by MACMILLAN PRESS LTD Houndmills, Basingstoke, Hampshire RG21 6XS and London Companies and representatives throughout the world ISBN 978-0-333-73007-2 DOI 10.1007/978-1-349-14770-0 A catalogue record for this book is available from the British Library. ISBN 978-1-349-14770-0 (ebook) This book is printed on paper suitable for recycling and made from fully managed and sustained forest sources. 10 9 8 7 6 5 4 3 2 1 07 06 05 04 03 02 01 00 99 98

0 Contents Preface X 1 Introduction 1 1.1 Introduction 1 1.2 Hardware, software and firmware 1 1.3 Basic computer architecture 2 1.4 Compiling, linking and producing an executable program 3 1.5 Compilation 4 1.6 Introduction to Pascal 4 1. 7 Exercises 8 2 Input/Output 10 2.1 Introduction 10 2.2 Pascal input/output 10 2.3 Examples 12 2.4 Exercises 18 3 If Statement 20 3.1 if... else statements 20 3.2 Examples 21 3.3 Exercises 26 4 Case Statement 29 4.1 case statement 29 4.2 Examples 29 4.3 Exercises 33 5 For Loop 36 5.1 Introduction 36 5.2 for 36 5.3 Examples 37 5.4 Exercises 39 6 While/Repeat Loops 42 6.1 while 42 6.2 Repeat... until 42 6.3 Examples 43 6.4 Exercises 46

7 Functions 50 7.1 Introduction 50 7.2 Arguments and parameters 50 7.3 Pascal functions 51 7.4 Local variables 54 7.5 Examples 55 7.6 Exercises 62 8 Procedures 65 8.1 Introduction 65 8.2 Pascal parameter passing 65 8.3 Examples 67 8.4 Exercises 71 9 Arrays 76 9.1 Introduction 76 9.2 Pascal arrays 76 9.3 Examples 79 9.4 Multidimensional arrays 85 9.5 Exercises 87 10 Strings 92 10.1 Introduction 92 10.2 Pascal strings 92 10.3 Examples 95 10.4 Exercises 100 11 File 110 103 11.1 Introduction 103 11.2 Pascal file I/0 105 11.3 Examples 106 11.4 Exercises 110 12 Records 113 12.1 Introduction 113 12.2 Records in Pascal 113 12.3 Array of structures 116 12.4 Exercises 119 13 Graphics 123 13.1 Introduction 123 13.2 Basic graphics routines 128 13.3 Exercises 138 V1 Mastering Pascal

14 Software Interrupts 140 14.1 Introduction 140 14.2 BIOS and the operating system 140 14.3 Interrupt vectors 141 14.4 Processor interrupts 142 14.5 Generating software interrupts 142 14.6 Exercises 155 15 Interfacing 158 15.1 Introduction 158 15.2 Interfacing with memory 159 15.3 Memory mapped 110 159 15.4 Isolated 110 160 16 RS-232 165 16.1 Introduction 165 16.2 Electrical characteristics 165 16.3 Frame format 168 16.4 Communications between two nodes 169 16.5 Programming RS-232 173 16.6 RS-232 programs 178 16.7 Exercises 181 17 Parallel Port 184 17.1 Introduction 184 17.2 PC connections 185 17.3 Data handshaking 185 17.4 110 addressing 188 17.5 Exercises 193 18 Hardware Interrupts 197 18.1 Introduction 197 18.2 Hardware interrupts 198 18.3 Interrupt vectors 199 18.4 Programmable interrupt controller (PIC) 202 18.5 Interrupt-driven RS-232 204 18.6 Exercices 211 19 Date and Time 213 19.1 Introduction 213 19.2 Time 214 19.3 Date 214 19.4 DateTime record 215 Contents vii

19.5 Packing Time 215 19.6 File Time 215 19.7 Examples 216 19.8 Counting timer ticks 218 19.9 Exercises 219 20 System Commands 220 20.1 Introduction 220 20.2 System calls 220 20.3 Passing arguments 226 20.4 Exercises 228 21 Introduction to Delphi 230 21.1 Introduction 230 21.2 Event-driven programming 230 21.3 Delphi files 231 21.4 Other terms 232 21.5 Main screen 233 21.6 Object Inspector 236 21.7 Exercises 240 22 Delphi Input/Output 243 22.1 Introduction 243 22.2 Running Pascal programs 244 22.3 Message and dialog boxes 246 22.4 Input dialog 254 22.5 Exercises 256 23 Delphi Forms 258 23.1 Introduction 258 23.2 Setting properties 258 23.3 Forms and code 259 23.4 Temperature conversion program 266 23.5 Quadratic roots program 270 23.6 Resistance calculation with slider controls program 272 23.7 Exercises 279 24 Delphi Menus and Dialogs 281 24.1 Introduction 281 24.2 Menu editor 281 24.3 Open and close dialog boxes 286 24.4 Running an application program 289 24.5 Exercises 290 Vlll Mastering Pascal

25 Delphi Events 292 25.1 Introduction 292 25.2 Program events 292 25.3 Exercises 301 26 Delphi Graphics 303 26.1 Introduction 303 26.2 Loading graphics files 303 26.3 Colours 305 26.4 Drawing 306 26.5 Exercises 312 A Turbo Pascal Reference 314 B ASCII 325 c Bits, Bytes and Operators 329 C.l Bits and bytes 329 C.2 Binary arithmetic 330 C.3 Numbers and representations 331 C.4 Pascal operators 333 D Dephi Reference 338 D.1 Standard units 338 D.2 Forms unit 339 D.3 WinProcs unit 340 D.4 System unit 354 0.5 Dialogs unit 356 E Miscellaneous 358 E.l Structure charts 358 E.2 Programs with errors 359 Index 366 Contents ix

0 Preface Pascal is one of the most widely used PC-based programming languages. It is also one of the best programming languages to teach good software development techniques. This book provides an introduction to programming with Pascal and extends this to show how Borland Delphi, which uses Pascal, is used to develop Microsoft Windows programs. After many years of teaching software development to undergraduates I have found that C and C++ suffer from several pitfalls, especially in parameter passing, pointers and the lack of strong data type checking. These areas may provide flexibility for experienced programmers, but for novices they add to the complexity of the program. I have also been involved with extensive consultancy work and book writing over the years and I have used C, C++ (Borland C++ and Visual C++), HTML/JavaScript, Java, Visual Basic, Turbo Pascal and Borland Delphi. From this, I can say, without doubt, that Delphi is the easiest and most powerful development system I have found. It provides a great deal of flexibility in that it doesn't try to write all the code for the programmer, and basically it provides a framework for the user to add code to. The best way to learn a programming language is to write real applications. For this reason the book includes many real-life applications. Chapters 13 to 20 cover some practical applications, such as: software interrupts, hardware interrupts, graphics, date and time, system commands, RS-232 and parallel ports. The book thus covers three main areas: Pascal programming (Chapters 1 to 12). Pascal applications (Chapters 13 to 20). Delphi programming (Chapters 21 to 26). Further information and source code can be found on the WWW page: http://www.eece.napier.ac.uk/-bill_b/pascal.html Help from myself can be sought using the email address: w.buchanan@napier.ac.uk Dr. William Buchanan. X