Jeff Duntemann's Contrapositive Diary Rotating Header Image

FreePascal (And Lazarus) From Square One

About two years ago I started piecing together a book on FreePascal based on my 1992 Bantam book, Borland Pascal 7 From Square One. I set the project aside in part because I needed to get my assembly book updated and back into print–something that took most of a year and all of the personal energy I could summon. But there was another problem: The text-mode IDE included with FreePascal is erratic in the extreme, and crashed constantly on me, especially under Windows. I had hoped that there was an easy fix, but apparently not. I installed the new 2.4.0 release of FreePascal yesterday, and the IDE hasn’t changed a bit. Try to set the text display resolution to anything at all (25 X 80, 43 X 80, whatever) and it crashes. One wonders why the damned thing is still there.

I’ve been following the Lazarus project since it had been the Megido project, back in 1998. The idea was to create an open-source alternative to Delphi, by writing a GUI front end for FreePascal. It’s possible to create ordinary console apps in FreePascal using Lazarus as the IDE, but I hesitated to use Lazarus as the example IDE in the book because it’s only available for Windows, Linux, and FreeBSD. (There’s a Mac port, but I’ve heard it’s less complete and much less robust than the others.)

Pascal and VDM readers, feel the irony: Jeff Duntemann hanging back from a RAD environment because he’d hoped to have a more broadbly applicable (read here: portable) book. Wow.

Heh. I changed my mind. I’ll have to go back to the beginning and pull out all the references and screenshots involving the text-mode IDE, but Lazarus is a much better IDE, even if you’re not actually doing any RAD work….yet.

“Yet” is key. If this first book works out, I hope to adapt some of my material from The Delphi 2 Programming Explorer into an intro book for Lazarus as a RAD tool. So getting readers familiar with the editing and project management machinery built into Lazarus is a good thing, even if the bulk of the app goes to waste while people learn the fundamentals of Pascal.

I’m going to try something new with this book. I’m going to pull a Cory Doctorow and give away the complete PDF version for free, and sell the printed version on Lulu. The book will be yet another descendant of Complete Turbo Pascal (in fact, it will in essence be the 25th Anniversary Edition!) and I’ve been paid for the work many times over. So I won’t be losing much by giving it away, and I’m very curious to see how many paid print sales I’ll make based on a free ebook.

Most of the work lies in the early chapters, where I introduce people to the Lazarus RAD environment. After that, well, it’s all basic Pascal, and while Delphi has extended Pascal fantastically in the last fifteen years, CASE statements are still CASE statements.

Unlike my earlier books, I intend to post regular PDFs of the work in progress, so you can follow the project as it happens. (There’s a 2008-era PDF out there now, and you can get it from my FTP area using HTTP.) I’ll post an updated PDF as soon as I untangle all the existing references to the text-mode IDE. Watch this space for more details.

40 Comments

  1. Chris says:

    I remember using Turbo Pascal quite extensively about 20 years ago, and I used Delphi quite extensively for about a year about 8 years ago. I hate to say it but if Pascal ever had a window of opportunity I think its past. BTW do they still make Delphi? I heard there was a free version from Inprise some years ago. Also has anyone gotten Free Pascal integrated with Eclipse?

    They were both pretty decent products, but the world has moved on. These days all of the desktop development jobs are in C#/.NET and J2EE pretty much taking whats left. Frankly if you want to do Windows development VS 2008 is very hard to beat.

    Anyway, like your diary, I remember regularly purchasing PC Techniques back in the day and always enjoyed your editorials and book reviews. It was a great magazine.

    Take care.

  2. Darrin Chandler says:

    Chris,

    “These days all of the desktop development jobs are in C#/.NET and J2EE pretty much taking whats left.”

    That mindset is one of the things that will make such a book even more valuable. Believe it or not there are still Pascal projects out there. A couple of years ago I was talking to a company about helping them with their flagship project written in Delphi. And for people without an existing code investment this may help to break some developers out of the popularity feedback loop.

    “Frankly if you want to do Windows development VS 2008 is very hard to beat.”

    Windows development isn’t what it used to be. It’s still very important, of course. But applications living on the internet have given many people an expectation of being able to run software on their OS of choice, and I expect that trend to continue. Cross platform is now both more important and easier than ever before.

    FYI, when people fly in for a meeting where I work there are a lot of Macs. And many (most?) of the people are also familiar with using Linux as well.

    1. Chris says:

      Okay I’ll bite.

      “That mindset is one of the things that will make such a book even more valuable.”

      Well its the markets mindset. Why is the market wrong?

      “Believe it or not there are still Pascal projects out there. ”

      I’m sure there are lots of Delphi apps out there. I’m sure there are even Turbo pascal apps out there.

      But let me put this to you:

      Can you name 5 features in Pascal that are not already in C# or Java? How about 3? Things significant enough that someone actually decide to forgo the popular choices and chance a million+ bucks (a trivial amount of money in development, much less marketing) on Pascal instead of the popular safe choices which have thousands of developers ready and willing to go.

      Talk to me as a businessman, why is it worth taking the risk. Where are the dollars to be saved?

      “Windows development isn’t what it used to be.”

      As a desktop software developer 89% of your potential customers are Windows users.

      “But applications living on the internet have given many people an expectation of being able to run software on their OS of choice, and I expect that trend to continue”

      I disagree, how many business are asking employees to use Google office to do their corporate spreadsheets? Second you say many, but you provide no links to studies on this. I know the companies who see more $ in cloud computing are pushing this idea, but who else is? Its the solution to the problem nobody seems to have.

      But back on point why is Pascal better than Java in this regard? In cloud computing you can implement the server side in anything you want, typically C++ for speed. On the client side its expected the thin client will run in a browser, thus your choices are a Java applet or ug, ASP .NET.

      So far as I can tell Free pascal seems to be a cross compiler (like GNU C) not have its own RTE like Java. So how is it an advantage in cloud computing?

      “FYI, when people fly in for a meeting where I work there are a lot of Macs. And many (most?) of the people are also familiar with using Linux as well.”

      First I like Linux just fine I spent 4 years doing embedded Linux work.

      Second the numbers don’t back you up. See the link below. Looks like 11 percent combined.

      http://www.w3schools.com/browsers/browsers_os.asp

      To be fair, I’m sure there are a fair number of iPhone users, who are not included in the above survey. But for reasons below, this does not support your argument any better.

      Third why wouldn’t cross platform developers just do the development in Java or C++/GTK? Apple developers on both the iPhone and Mac use Objective C (and Java) pretty much 100%. And Linux uses Eclipse/GnuC/C++ and GTK+ (and again Java) close to 100%.

      Also GNU C/C++/GTK can be cross compiled to run on all three platforms(Linux, OS X and Windows) already and has been proven many many times. And Java will run on all three without even needing to be compiled.

      So back to the original point why is the market wrong? Where does Pascal find its angle?

      1. Darrin Chandler says:

        “…its the markets mindset. Why is the market wrong?”

        I think we have a different ideas of what the market comprises. You keep mentioning desktop development as if it’s pretty much the whole development world. For the last decade desktop development has been the minority of what I’ve been doing, and I have to stress I have not been working for dot coms. And the desktop work I have done has largely been talking to servers. I’m not alone here: this is a shift in the market.

        “Can you name 5 features in Pascal that are not already in C# or Java? How about 3? … But back on point why is Pascal better than Java in this regard?”

        Maybe, but I’d sure have to dig, and even so it would be something esoteric. I do really miss object properties when I use C++, but such things really aren’t relevant in this context. I think there’s a market for such a book, and that having said book would be a good thing.

        This reminds me of a mailing list thread about which source control software to use. It began with a simple question asking about the profusion of choices. Various people, including me, chimed in with pros and cons of software they’d used. It was all very informative and interesting. But one person took it on himself to then *defend* his software of choice against all comers, matching features, market/mind share, size of community, et al. He wanted his choice to *win*! That wasn’t appropriate.

        The value I see in Jeff’s proposed book is not that it should convert the market to using Free Pascal. It’s not about scoring a *win* for Free Pascal. It’s about providing a nice, informative book for people who liked Borland’s Pascal products and/or have existing code.

        “First I like Linux just fine I spent 4 years doing embedded Linux work. … Second the numbers don’t back you up. See the link below. Looks like 11 percent combined.”

        Why would I look there when I can glance in the meeting room and see all the glowing apples on the laptop lids? How would it go over if I told them we’re only supporting Windows because that’s what the market decided?

        The truth is that “the market” is really multiple overlapping markets. Tech pundits are telling me that the phone IS the computer now, and that’s just absurd for many market segments. Once you have the mindset of “THE market” only the majority counts. That viewpoint works well enough for a lot of people, but it’s not the total picture for computing or software development.

        I really don’t want this to be a contentious discussion, Chris. You make some very valid points, and I think I do also. For many of these points we can both be right sometimes, in some market segments.

        1. Darrin’s right here: Pascal (irrespective of implementation) will never “win.” On the other hand, it’s not dead by any means, and the market (however we want to define “market”) is more than big enough to include Pascal, as well as all the other new languages (which to me seem indistinguishable from C, or maybe Java or Python) that I read about every other week on Slashdot. Having a good intro book on a language is essential, and I just happened to have a Pascal intro book lying around doing nothing since 1995 or so. My goal is to give people who are interested in Pascal a “front door” to the skills they’ll need to program in it. I recognize that it won’t be a huge crowd, but I made my money on that book long ago, and giving it to people who might be interested seemed like the right thing to do. If it helps Pascal survive, then I’m happy.

  3. Alan Earnshaw says:

    Jeff,

    “After that, well, it’s all basic Pascal…”

    Well, which is it? Basic or Pascal? 😉

  4. Bill Melvin says:

    I look forward to seeing how this progresses. I recently “ported” a Delphi app to Lazarus on Ubuntu to try it out. The app is a simple, single form, file copy utility so it wasn’t much of a test for Lazarus (no database stuff in there). I was surprised I only had to change three lines of code to make it compile in Lazarus. Too many other irons in the fire to explore Lazarus further right now but I’ll definitely follow your work on the book.

    1. One of the big problems porting anything from Delphi is that most of the libraries aren’t available for Lazarus, whether originally from Borland/Embarcadero or third parties. I own a small fortune in Delphi libraries, none of which will install in Lazarus. I’ve seen what you’ve seen pretty much: Small, simple apps will port without a lot of trauma. Anything that makes any significant use of third-party libraries is either hosed or requires duplication of those libraries, which in most cases just won’t happen. So as similar as the two products are conceptually, I don’t foresee a huge amount of code moving from one to the other.

      Stay tuned. The PDF version of the book will be free, and I’ll release regular updates as I work on it.

  5. […] described my FreePascal from Square One book project in detail a couple of weeks ago, and I work on it as time allows. There have been some hangups; in […]

  6. Tom Unger says:

    Jeff, I am delighted to learn that you are preparing a book on Lazarus/FreePascal.

    I was searching to see if such a book exists and stumbled onto your site. You have wriiten some great books in the past, so it’s great that you are the one writting a book on Lazarus/FreePascal.

    I use Delphi at work (plus Oracle PL/sql). But am just a Lazarus dabbler. If you need a beta-reader, I’ll work for free.

    Any idea when the book will be out?

    Thanks.,
    Tom

  7. Andrew says:

    There is still a market for Object Pascal, i work for a company that uses Delphi for most of our apps (even some web ones), we make software for well known Fast Food companies mostly in France but also in other countries especially in EU.
    The main advantage of Delphi is power comparable to C/C++ in a clean strong-typed language that prevents you from shooting yourself in the foot, yes you still have pointers if you need them but their use is much safer than in C, the language, compiler, IDE all encourage you to write clean, readable maintainable code, there aren’t many traps when developing with Delphi, the only thing one might want from Delphi is probably a Garbage Collector but you can use interfaces and components if you are careless or simply lazy, there are also tools like AQTime and MadExcept or EurekaLog that help you detect any possible memory leaks or problems.
    Our company has a new project which might be done at least partly with Lazarus/FreePascal because it’s the best Delphi alternative and also CrossPlatform and we need to work with small embeded systems running Linux (Ubuntu in our case).
    I am aware that in the US Delphi is not used so much anymore but C# and Java walk around like huge mammoths and dinosaurs but the world is not US alone, there is still a market for Delphi in Brazil, Russia, Netherlands, Germany and other EU countries, also if i understand correctly there is a growing market for Delphi in China and other asian countries.
    Lazarus has a chance that Delphi never had, to make Object Pascal known and respected in the Unix world which from a commercial point of view might not seem much but you must remember that both Pascal and Unix/Linux started in the academic world but were later used as commercial tools and once again ObjectPascal might be used to build powerful applications bringing safety and discipline where C/C++ lack and speed where Java does not shine also it may fulfill the C# promise of being the true CrossPlatform Java successor everyone has been waiting.
    FreePascal is a powerful compiler with many dialects and extensions and it’s Open so everybody can extend and customize it to their needs you will see that it might even have a larger set of libraries than Java or C# just because of it’s ability to easily import and use C libraries with native performance, no interpretors, no Virtual Machines no lazy JIT’ers and memory hungry applications.
    Honestly i’ve only seen two Java Desktop Applications SmartSvn and another one but if you analyze them, you’ll see much more Delphi applications on windows like Skype, TUGZip, Total Commander and many more, PeaZip was built with Lazarus and also Morfik the powerful web IDE/Framework is build with Delphi and uses FreePascal as it’s compiler for impressive results supporting ObjectPascal, C# and VB syntax with no requirement for deep understanding of client side scripting and CrossBrowser incompatibilities.
    Lazarus and FreePascal might seem weak but they are not powered by some large foundation with millions of dollars like Mozilla or Novell/Mono so there is no advertising except for announcements and articles/comments on various blogs or forums.
    I believe that Lazarus and FreePascal follow the same path Linux did and hopefully will enjoy at least the same level of success which is probably more than Delphi ever had.

  8. eric dexter says:

    bloodshed seems to work well as an ide..

  9. Abdul Karim Jaber says:

    Hay , I am looking for a book in LaZaRus in Graphics , to draw and
    show a File.BMP . Thank you A. Jaber

  10. Mark says:

    Heya Jeff,

    I know this is an old post but thought I’d chime in as well.

    I built some pretty low level stuff with PASCAL in the past and reversed engineered DOS and Netware internals with it (See the INT List, A. Schuman/Kyle) . I began using FreePascal and Lazarus a few years ago and love it. lol. On Gentoo the text IDE works great! Built a complex and stable Astronomical/logic Web site back end that is readable and works… (using the Text IDE…grin, after experimenting on WIN using Lazarus)

    The cons (hopefully improved upon in the future) are it could be faster at runtime (TP 3.0 was FAST). Though for slow points embedding ASM works just fine. Pros, it’s memory management and foot print (RAM and disk) are second to none.

    Keep up the good work and take care.

  11. Waqqas says:

    Andrew, I really liked that post!
    FreePascal and Pascal itself is the MOST underestimated programming languages! If any big company promoted it (like if Apple suddenly made developer write apps in Pascal), and people started using it – they’d realize what they’ve been missing.

    C++ is Murder! It really is and even the basic of apps manage to have memory leaks. Pascal is amazingly intuitive. it really deserves a higher place in this world.

    1. Lars says:

      Waqqas, old mactinosh computers used to be written in Pascal and then they changed to Objective C later. C++ programs have memory leaks, and so do freepascal/delphi ones. Delphi and free pascal is not a safe language that is garbage collected like Oberon. i don’t see why you are thinking freepascal will solve your memory leaks problems.. it won’t. Using tools to ensure your application doesn’t have memory leaks is good, but I don’t think that is unique to pascal. It is equally possible in C++ to check for leaks with special tools I would think.

  12. Vicente García says:

    Hello :

    I´m very interested in “FreePascal (And Lazarus) From Square One”. Is it available for download?.

    Thanks a lot.

    1. Yes. The link below will bring it right down:

      http://www.copperwood.com/pub/FreePascalSquareOneVol1.pdf

      Note well: The book is not finished, and not even close to being finished. There are blank pages and space-holders and typos and things I will fix as time allows. What’s up there is now a year old, and there are newer versions of both FreePascal and Lazarus than the ones I cite. As I work on the book, I upload newer PDFs to that location, so if you check back you may get a bigger and better file.

      I don’t know when it will be done, but you’re certainly welcome to what I have so far.

  13. Scott says:

    Hi Jeff,

    Any additional info on where you are with this and when you expect to finish? There is interest out there Lazarus and Free Pascal. Lazarus is now in 1.0 RC territory.

    Thanks

    Scott

    1. I set the project aside to let the products mature a little. One thing I would very much like to see in Lazarus (and no one there seems interested in adding it) is a dirt-simple template for absolutely minimal Pascal programs of the “Hello, World!” species. What I want is an additional item in the File|New… dialog, under the Project heading. When selected, the following program should be created:

      program SimpleTest1;

      begin
      end.

      I don’t want to boggle brand new users with the (unnecessary) folderol that comes in with the Program selection:

      program Project1;

      {$mode objfpc}{$H+}

      uses
      {$IFDEF UNIX}{$IFDEF UseCThreads}
      cthreads,
      {$ENDIF}{$ENDIF}
      Classes
      { you can add units after this };

      {$R *.res}

      begin
      end.

      I’ve done classic “Hello, World!” four-liners in Lazarus and it works just fine. I don’t know where in the product the templates are stored, or I’d create one myself. If you know how, please take a few minutes and do it. That would help me a lot.

      Thanks!

      1. snorkel says:

        Submit a feature request on the Lazarus bug tracking system.
        Probably wouldn’t be to hard to add it to the source and even submit a patch.

  14. Scott says:

    Hi Jeff,

    I believe you could simply use New Project From File… under the project menu.

    Then select the file you create using the 4 lines you’ve done above. You would have to create that file first, and so would your readers. But it can be done.

    Hopefully that helps,

    Scott

    1. Well, that’s the fallback, obviously. I can always create the file and bundle it (along with other code listings) with the book file itself. But I also think that a fundamental 4-line Pascal template would be useful for square-one tutorial use, and I can’t imagine that it would be difficult to build into the IDE. If you know those guys on the Lazarus team at all well (I don’t, though they know my name) bug them about it.

      I think that when the Lazarus 1.0 version is released, I’ll go back and update the book accordingly, and seriously add some material to it. I’m working on an SF novel right now, but I’m almost done. It would be good to get back to some Pascal work for a bit.

  15. Leonardo says:

    I’m very sure Object Pascal (and its flavors) is powerful, reliable and productive. I develop complex Computer Graphics libraries from scratch using Free Pascal + Lazarus. You can see, for example, something about my vector-based drawing library here (everything made from scratch):
    http://www.picturetopeople.org/dev/maccala_features.html

    I migrated from C++ years ago because I have the same low level power (like pointers) with Free Pascal and other things C++ doesn’t have. Object Pascal gives me a more strongly typed language and I can make a more effective RAD programming.

    Why is a strongly typed language so important? Because when you deal daily with very complex algorithms you must have a compiler that is your friend. A loosely typed language has a compiler that lets you make a lot of bad code (and you make it, mainly after a whole night dealing with Math without resting).

    Object Pascal also offers me an easily syntax when making object oriented programming, usually without loosing quality. C++ is too verbose for most situations. Usually it’s really boring to need to code “copy constructor”, for example, for most of my classes.

    Furthermore, when I made my tests evaluating if it would be good change my code to Free Pascal, my libraries have run just kind of 10% slower than when coded in C++.

    For me (I develop complex low level software) a language like Java is just a toy language.

    Java is slow and has a ridiculous syntax for an interpreted language (its “case” clauses can have just one value – it makes sense for C++ where each clause will map directly to a machine jump, but doesn’t make sense for a interpreted language). If you can pay the price of being slow, at least get a very nice syntactic sugar to save your fingers.

    Java has no pointers, they say. But, if you use it, soon you see the more famous exception the language has is called (typed) NullPointerException. Is that a joke? Are they making fun with me ???

    Java also has other terrible issues that make it poor for serious programming like, for example:
    – its streams usually don’t have random access and, even worse, can just be read forward;
    – all its integer types are signed (when you need to deal with bit level operations, this limitation can be really bad);
    – you can’t copy data structure contents (memory blocks) if they don’t have the same type – say goodbye to performance forever. It’s really wrong to make it automatically and silently, but it would have some way to make it on purpose (like a kind of pointer casting).

    All languages are good for a niche or kind of work, and all of them have pros and cons. Anyway, I have no doubt Object Pascal has the best cost/benefit if you need to produce fast, serious and complex software.

  16. ipkwena says:

    I still have the original CD copies of Delphi1/2/3/4 stowed away somewhere in the house. I learned about FreePascal when I needed to continue programming in my favourite language for the Linux environment without having to learn C++ and Java. Well, the rest is history.

    Now I develop virtually all projects in Lazarus-FreePascal and that includes integration with networking protocols and databases systems. Developing a front-end application that interactively communicates with an Asterisk PBX system has given me the most satisfaction to date.

    The Lazarus IDE version 1.0 is such a pleasure to work with considering that it is a free product. Last week I installed Monodevelop to explore the C# language and I cannot help feeling the similarity C# has with the Delphi/FreePascal paradigm.

    I book on any programming language can only be a positive contribution to anyone who has an interest to read programming literature. You have my vote on the book.

  17. Tito says:

    Jeff,

    it’s good for me to know that you are still writing about Pascal. I learned programming, reading one of your books (translated) and I must say that it was the best programming book I had ever read.
    Go ahead and continue delighting us with your particular style of writing. I’m waiting for you finish this book.
    PD: Sorry for my English. I’m not native speaker.

    Thanks.

  18. snorkel says:

    Jeff,
    Are you still working on the Free Pascal Book? You should let people know about it on the Lazarus forms.

    1. Yes; see my reply to Cavan below. There’s a new file with a new name and a fair bit of new material. I had to set it aside while I finished a textbook project, but it’s underway again as of mid-May 2014.

  19. Cavan says:

    Hi Jeff,

    Just tried the link you posted above (http://www.copperwood.com/pub/FreePascalSquareOneVol1.pdf) and there is nothing there. Have you abandoned this project?

    Pity if it is so.

    1. Sorry. I renamed the file to reflect the release date. It’s here:

      http://www.copperwood.com/pub/FreePascalSquareOne–25-05-2014.pdf

      Much new in the file, but keep in mind that it’s not complete and it’s still full of formatting bugs etc. I’m currently taking a pass through it to make it reflect Lazarus 1.2.2, and some of the screenshots still need to be replaced. After that, I’ll go back to adding new chapters on Pascal fundamentals. The project is very much alive!

  20. Eduardo says:

    Just tried the link above (http://www.copperwood.com/pub/FreePascalSquareOne–25-05-2014.pdf) and all i can get is a 404 error hope you can point me to the book.

    Thanks in advance.

    1. Hang on for a bit–just got back from three weeks away. This is a known problem and I’ll fix it today.

      1. Eduardo says:

        Thank you so much!

        1. Try this:
          http://www.copperwood.com/pub/FreePascalSquareOne–08-06-2014.pdf

          If you have trouble, give me a yell. It’s the latest version of the file.

  21. Travis Ayres says:

    I am SUPER excited to have you writing about FreePascal and Lazarus, and I can’t wait to buy your books! Let me know if you need a guinea pig to have try code!

    1. Many thanks for the vote of confidence. I’m going to need some time, and the clock won’t even be ticking until Carol and I complete our move to Phoenix. I really want to do more writing in both fiction and nonfiction, though the computer book I’m wrapping up now for a large publisher was a horrible logistical mess. I may need to take a break from computer books for a year or so. But stay tuned, and again, thanks!

  22. Rick Widmer says:

    I just tried downloading from http://www.copperwood.com/pub/FreePascalSquareOne–08-06-2014.pdf and got a 404 error. Is there a new URL I can try?

    Thanks, Rick Widmer — a long time fan

  23. Rick Widmer says:

    Sorry. I found it here: webapps.me.uk/download.php?f=FreePascalSquareOneVol1.pdf

  24. Darian Miller says:

    Minor note: Page 62, “there’s a science to semicolon placement, which I’ll take up in detail later on in Section X.X.”

    1. I haven’t straightened out all the section references, so things like “see Section X.X” are common in the current state of the book. I’m adapting a lot of material from a very large book (900 pp) that was mostly focused on DOS, so the chapter numbering is not the same. I did some work on the book this afternoon, and I’ll upload a new PDF in the next couple of days.

Leave a Reply

Your email address will not be published. Required fields are marked *