Launch your Pascal. With FPC Pascal, you get an MS-DOS command prompt window "promptly" (heh! heh! (Sorry)), and it then looks as if something's wrong, or as if the computer is waiting for you to enter some command. Be patient! After what will seem an age until you are used to it, "stuff" will appear in the window, not least a menu bar and an edit window. Don't worry... once "awake" it runs as fast as it should. (On my reasonably fast (for it's vintage) Win98 machine, it just took 40 seconds.)
Once your Pascal is running, and you are in the edit window, enter the following:
program first; uses crt; begin ClrScr; writeln('Hi'); end.
Some of the text that you've typed in will appear in different colors. More on that later; more on what's going on later, but for now: Let's make something happen! But before we do, let's save your typing.
Click File|Save. This will actually bring up the "Save As" dialog box, because this is the first time you are saving the program you've just typed in. You could just enter "My Program" in the file name box and click "ok", but I'm going to suggest a slight improvement.
You may be in the folder (directory) into which you installed FPC. Or someplace else... FPC seems to save where you were from invocation to invocation. I would suggest making a folder for the files you create. This isn't as easy in FPC as one would hope... but it is do-able, if a little strange to Windows-spoilt users. Use your tool of choice- I like Windows Explorer- to create, outside of FPC, any folders you want to use.
Once the folder is created, to move into that folder. Navigating the tree of folders is a little strange at first, but you can do it! Big help: The "file" called "..\" is a link to the parent folder of whatever folder you are in. Assign a name for the file, I'd suggest "First", or "PLT1aff". (PascaL Tutorial 1aff, which is the name of the web page you are reading.) Click "Save".
Do, by the way, remember to drag the lower right hand corner of the FPC box outwards. You can't resize the window quite as freely as you could most other Windows windows, but you can at least give yourself a larger font.
(A little aside for people very new to Windows. The following is true not only for FPC, but for most Windows applications. If you've started something from scratch, i.e. by using File|New, then the first time you save it, you get the "Save As" dialog, as I've already said. From that point on, if you use File|Save, your work is simply saved where ever, and under whatever name you specified during the first save. The previous version of your work is over-written. Also, when you load something pre-existing, then doing File|Save will again simply replace the previous version. If you have been working on something, and you don't want to destroy the previous version, then use File|Save As, and change the name used for saving what you have.)
Keyboard shortcuts, like F2 for save, are always nice. Try to start using a few; the practice may grow on you. Ctrl-F9 to compile and run your code, and F6 to switch between windows are particularly useful.
Several common Windows keyboard shortcuts, notably ctrl-C / ctrl-X and ctrl-V don't do the same thing in FPC as they do in Windows. In FPC you use ctrl-insert, shift-delete and shift-insert to accomplish copy/ cut/ paste. (By the way: I once had a weird disruption of copy/ paste in my Windows application while FPC was open in another window. I only had to close and restart FPC to resolve the problem.)
Selecting text works a little differently in FPC than in Windows, and selected text is not automatically deleted if you go to type something on top of it. If you get some selection that you want to get rid of, just do shift-UpArrow followed by shift-DownArrow.
So... you've typed in the little program I gave you. You've saved your typing.
Now click "Run" on the menu, and "Run" again from the sub-menu (or just press ctrl-F9, the equivalent... as you can see from the right-hand column of the sub-menu.) You may well get an error message, in which case you'll get messages, and, probably the words "Compile Failed". Your Pascal will even tell you where it got confused... but that isn't always where the problem lies. If you can't see a fault where your Pascal says to look, check preceding lines. One favorite trick of new Pascal programmers: Leaving out a semicolon. (Although, in rare cases (which you'll learn to be aware of), a superfluous semicolon may be the problem!) The error message even tells you which line of your program holds the place Pascal got confused.
When there's a message on the screen, you tell it "Okay, got that, now go away" by clicking on the little square in the upper left of the message's box, or pressing by escape or enter.
The interface used with FPC is from the days before Windows. (Yes, there was such a time... When I was a boy... (Don't let me get started!!))
FPC does work in a "windowed" environment, but you could be forgiven for not liking it. However the concepts of maximized and "restored" windows are present. (I'm not sure how to mimic a minimize.) You can... really... even re-size the windows. It's just all less intuitive than modern Windows.
If you had an error, find it, maybe re-save, and try to run the program again.
Don't be alarmed if it seems that nothing has happened.
When you finally (or if you are a careful copier, the first time you...) ran the program and got no "complaints", you may have noticed the screen flash, and you might even have seen the "Hi" you've accomplished. But it didn't stay. Your sourcecode ("program first; begin...") came back. FPC: Press Alt-F5. TP: Use the menus: Alt-R (To get the "Run" menu, then U for "user screen". That SHOULD bring you to a screen with "Hi" on it... someplace. There may be other "stuff" there, too. I must confess that I had a little trouble with this, so just keep at it... you'll get that User Screen thing eventually! It's been a while since I used TP, and I am a very new user of FPC. I have every confidence that both are usable... it just takes a little struggling to get fluent. I hope these pages are, at least, saving you some of the struggle? With FPC, Alt-F5 seemed to work well for switching back and forth between the sourcecode, in the editor, and the "user screen". As I said, with TP, use the menu to access the User Screen (the menu SAYS the key combination "Alt-F" should do it... but it wouldn't for me, on my XP machine.) And use the escape key to go back to the sourcecode.
Whew! It gets easier. I promise.
Just one last little flourish to finish off this first tutorial. You won't finish a real program in one go. Part of learning to program is learning to build something up by degrees. Add a second writeln line, specifically writeln('Bye'); Compile and run the program again; see your new masterpiece in action (or fix the typos!) and cheer... you're a programmer!
Oh yes... I said I'd take you through the program....
Every Pascal program begins with the word "program". After that, you supply a name; I chose "First" in this case. (PLT1a would have been better, but might have confused you at that stage.) And then the line is finished with a semicolon. You get a lot of semicolons in Pascal. More on them another time.
Next in our simple first program came the word "begin". For every "begin" there is an "end". You can have many begin/ end blocks, and they always nest. Leaving out the rest, a complex program might look like.....
begin begin begin end; end; begin begin begin end; begin end; end; end; end.
Did I scare you? I hope not... I wanted you to look forward to the excitement of a really sophisticated project! Anyway. Begins are always paired with ends, as I said. You do NOT put a semicolon after the begin (unusual), but you do put one after the end... usually. (I'll discuss the exceptions another time.) After the final end in a program, you put a period (full stop) instead of the semi-colon.
"Clrscr" cleared the screen.write and writeln are words built into all the Pascals we've been discussing. (A rough equivalent for Delphi, by the way, is "showmessage", e.g. showmessage('Hi');).
Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.
....... P a g e . . . E n d s .....