typestar

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.

Start this tour

Programs & variables

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

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 Integer that is sized, filled, and then grown.
  • RecordsA TShelter record pairs a name with a bed count and travels whole into a function.

Enums & sets

  • Enumerated typesTPhase names the four moon phases, and a case picks the line to print.
  • SetsA bike repair kit held as a set of TTool, edited and then questioned with in.
  • Subranges and OrdA TLane = 1..4 subrange indexes an array of lap times, and Ord round-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 finally block.

Exceptions

  • try-finallyA TStringList created before the try and freed in the finally, 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.

The other Delphi tours