Language basics
27 steps in 9 sets of Delphi.
Delphi is Object Pascal grown up: the language of Turbo Pascal with classes, properties, and a component model bolted on so cleanly that it carried the 1990s RAD revolution and still ships point-of-sale systems, lab instruments, and Windows line-of-business software today. It is verbose where C is terse — begin and end, := for assignment, semicolons as separators — and famously readable a decade later because of it.
This tour covers the language core as Free Pascal compiles it in Delphi mode: program shape and variables, the string toolkit, the four loop forms, procedures versus functions with const and var parameters, arrays and records, the enum-and-set machinery Pascal does better than anyone, classes with constructors and try-finally lifetime discipline, and exceptions. The encore ships complete programs. Every seed compiles warning-free and runs.
Programs & variables
- The program shapeA lighthouse log greeting built from the smallest set of parts a Delphi program needs.
- Variables and constantsA bakery till works out a morning's takings from a fixed loaf price.
- Assignment and arithmeticA bus conductor tracks riders boarding and splits a fare into dollars and cents.
Types & strings
- Numeric typesAn observatory counts frames, sums bytes and measures an exposure in seconds.
- Format and field widthsA ferry timetable printed as a three-column table whose numbers line up.
- String helpersA seed-library label gets trimmed, recased, searched and rewritten.
Control flow
- if and caseA fog signal chooses its pattern from visibility, then a month picks the watch.
- for loopsOrchard crates are counted upward, listed back downward, then walked without an index.
- while and repeatOne three-minute kiln countdown written twice, once in each loop form.
Procedures & functions
- ProceduresA
procedurereports one hive inspection, and the main block only calls it. - Functions and ResultTwo functions that answer with a value by assigning to
Result. - const and var parameters
Tunereads aconststation name and writes back through avarparameter.
Arrays & records
- Static arraysFive rainfall figures in an
array[0..4] of Integer, walked once for a total and a peak. - Dynamic arraysTrack lengths in an
array of Integerthat is sized, filled, and then grown. - RecordsA
TShelterrecord pairs a name with a bed count and travels whole into a function.
Enums & sets
- Enumerated types
TPhasenames the four moon phases, and acasepicks the line to print. - SetsA bike repair kit held as a
set of TTool, edited and then questioned within. - Subranges and OrdA
TLane = 1..4subrange indexes an array of lap times, andOrdround-trips a letter.
Classes
- ClassesA step counter class: one field, one method, and an instance you create and free.
- Properties and gettersA circle whose area is a property backed by a getter instead of stored data.
- Constructors and FreeA booking built by a constructor that takes arguments, then freed in a
finallyblock.
Exceptions
- try-finallyA
TStringListcreated before thetryand freed in thefinally, whichever way the function leaves. - try-exceptThree strings through
StrToInt, one of them not a number, handled instead of crashing. - Raising your own exceptionAn overdraft rule that raises its own exception class, caught where the withdrawals happen.
Encore
- word_freq.pasCounts words in an inline passage and prints the five most common with bars.
- grade_report.pasQuiz scores for five students, averaged into letter grades with a class summary underneath.
- temp_stats.pasA week of daily highs reduced to coolest, warmest and mean, with a bar chart per day.