Free Pascal from Square
Total Page:16
File Type:pdf, Size:1020Kb
FreePascal From Square One Volume 1: The Fundamental Ideas of Programming Installing and Configuring FreePascal and Lazarus The Core of the Pascal Language by Jeff Duntemann Revision of 11/04/2020 Repeat... Until... Copperwood Press ● Scottsdale, Arizona FreePascal from Square One By Jeff Duntemann This work is licensed under the Creative Commons Attribution-Share alike 3.0 United States License. To view a copy of this license, visit this Web link: http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to: Creative Commons 171 Second Street, Suite 300 San Francisco CA 94105 USA So that no one misunderstands the above: This is a free ebook. And I really mean that. Like FreePascal itself, you are free to give it to your friends, post it on your Web or FTP site or Usenet, include it on CDs or DVDs with your software or your own books, and just get it out there to anybody who needs or wants it. You are free to print it out at home to punch and put in a binder, or have a print-on-demand site create a book out of it for you. I would like to reserve rights to “publisher-style” printed editions sold at retail. If you’re a publisher and wish to create and sell such an edition, contact me. I post updated and corrected editions periodically. If you spot errors or see something that could be improved somehow, please send me an email so that I can fold those changes into the master copy. Use “jeff” “at” “duntemann” “dot” “com” and it’ll reach me. Please also note that as of the revision date on the main title page, This book is not yet finished. I work on it as time allows, and upload revisions as they happen. Copperwood Media, LLC Scottsdale, Arizona Table of Contents Introduction: How This Book Came About . 5 Part 1: The Fundamental Ideas of Programming . 9 Part 2: Installing and Using FreePascal. 83 Part 3: The Core of the Pascal Language . xx FreePascal from Square One, Volume 1 Introduction: How This Book Came to Be, and What I’m Trying to Do essir, the book you’re reading has been around the block a few times since I Ybegan writing it in November of 1983—which I boggle to think was thirty- five years ago. It’s been through four print editions and on paper sold over 125,000 copies. It’s been translated into five languages. Now it’s time set it free. Pascal was not my first programming language. That honor belongs to FORTH, though I don’t admit it very often. FORTH struck a spark in my imagination, but it burned like a pile of shredded rubber tires, leaving a stink and a greasy residue behind that I’m still trying to get rid of. BASIC came next, and burned like dry pine; with fury and small explosions of insight, but there was more light than heat, and it burned out quickly. BASIC taught me a lot, but it didn’t take me far enough, and left me cold halfway into the night. Pascal, when I found it, caught and burned like well-seasoned ash: Slow, deep, hot; I learned it with a measured cadence by which one fact built on all those before it. 1981 is a long time gone, and the fire’s still burning. I’ve learned a lot of other languages in the meantime, including C, which burns like sticks of dynamite: It either digs your ditch or blows you to Kingdom Come. Or both. But when something needs doing, I always come back to Pascal. When I began writing Pascal From Square One in the fall of 1983, I had no particular compiler in mind. There were several, and they were all (by today’s standards) agonizingly bad. The best of the bunch was the long-extinct Pascal/MT+, and I used that as the host compiler for all of my example code. The book, however, was about Pascal the language: How to get started using it; how to think in Pascal; how to see the language from a height and then learn its component parts one by one. When I turned the book in at the end of summer 1984, my editor at Scott, Foresman had a radical suggestion: Rewrite the book to focus not on Pascal the language but on Turbo Pascal the product. The maverick compiler from Scotts Valley was rapidly plowing all the other Pascals into the soil, and he smelled a new and ravenous audience. I took the manuscript back, and by January of 1985 I had 7 8 FreePascal from Square One, Volume 1 rewritten it heavily to take into account the numerous extensions and peccadilloes of Borland’s Turbo Pascal compiler, version 2.0. The book was delayed getting into print for several months, and as it happened, Complete Turbo Pascal was not quite the first book on the shelves focusing on Turbo Pascal. It was certainly the second, however, and it sold over 125,000 copies in the four print editions that were published between 1985 and 1993. The Second Edition of Complete Turbo Pascal (“2E”, as we publishing insiders called it) came out in 198, and addressed Turbo Pascal V3.0. By March 1987 I had moved to Scotts Valley, California and was working for Borland itself, creating a programmer’s magazine that eventually appeared in the fall of 1987 as Turbo Technix. Doing the magazine was a handful, and I gladly let others write the books for Turbo Pascal 4.0. I had the insider’s knowledge that V5.0 would come soon enough, and change plenty, so I worked a little bit ahead, and Complete Turbo Pascal, Third Edition was published in early 1989. It’s tough to stay ahead in this business. Turbo Pascal 5.5 appeared in May of 1989, largely as a response to Microsoft’s totally unexpected (but now long-forgotten) QuickPascal. V5.5 brought with it the new dazzle of object-oriented programming, and while I did write the V5.5 OOP Guide manual that Borland published with the V5.5 product I chose to pass on updating Complete Turbo Pascal for either V5.5 or V.0. The magazine Turbo Technix folded after only a year, and I left Borland at the end of 1988, wrote documentation for them until the end of 1989, and moved to Arizona in February of 1990 to start my own publishing company. This included my own programmers’ magazine, PC Techniques, which became Visual Developer in 199 and ran until early 2000. The early 1990s saw some turbulence in the Pascal business. Borland retired the “Turbo Pascal” brand and renamed their flagship product Borland Pascal. The computer books division of my publisher, Scott Foresman, was engulfed and devoured by some other publisher. Complete Turbo Pascal was put out of print, and I got the rights back. An inquiry from Bantam Books in 1992 led to my expanding Complete Turbo Pascal into a new book focused on Borland Pascal 7. I was able to re- title the book Borland Pascal 7 From Square One (the title Complete Turbo Pascal had been imposed by Scott, Foresman) and bring it up to date. That edition didn’t sell well because by 1994, Borland had created Delphi, and most of us considered the DOS era closed. I began writing books about Delphi and never looked back. And so it was for almost 15 years. I considered just posting the word-processor files fromBorland Pascal from Square One a few years ago, but figured that no one was using Pascal all by itself anymore. Not so. I first saw FreePascal in 1998 and tried it from time to time, but it wasn’t until January 2008 that Anthony Henry emailed me How This Book Came to Be 9 to suggest that FreePascal could use a good tutorial, and it shouldn’t be too hard to update Borland Pascal 7 from Square One to that role. He was right—and the project has been a lot of fun. I mention all this history because I want people to understand where FreePascal from Square One came from, emphasizing that it’s been a work in progress for thirty-five years. Why stop now? I don’t have to cater to publishers, paper costs, print runs, or release schedules anymore. The book can evolve with the compiler, and every so often you can download the latest update. My publishing company Copperwood Press (will soon) offer a print-on-demand paper edition if you’d like one, but you can print it yourself if you prefer. That’s how technical publishing ought to be, and someday will be. What I’m Trying to Do Here I wrote this book for ordinary people who had the itch to try programming, and with some dedication get good at it over time. You don’t have to know anything at all about Pascal, or programming generally, to read it. Anyone who lives a tolerably comfortable life in this frenetic twenty-first century can program. Most of us (as I’ll show a little later) engage the skills of programming to organize our daily lives. If you want to program, you can. It’s that simple. And this book begins at what I call Square One: The absolute beginning. I will explain the concepts behind programming, how to install FreePascal and the Lazarus IDE, and how to craft simple text-based programs in the Pascal language.