DMarlon Studio

Pascal course

Clear and strict, ideal for learning: Free Pascal and Lazarus build native apps for Windows, macOS and Linux.

In DMarlon Studio, Pascal powers desktop apps with Lazarus (like the offline Odoo demo) and the console.

From scratch: everything you need to write your first programs.

  1. 1Hello, worldYour first Pascal program: WriteLn prints text and results to the console. Compile it with Free Pascal or run it with F9 in DMarlon Studio.Lesson 1
  2. 2Variables and basic typesDeclare variables in Pascal's var block with the basic types (Integer, Double, Char, Boolean and String) and give them values with :=.Lesson 2
  3. 3Arithmetic: div, mod and /Do maths in Pascal: div for whole-number division, mod for the remainder, / for decimal division, and Trunc and Round to get back to integers.Lesson 3
  4. 4Formatting outputShape numbers in Pascal: WriteLn with :width:decimals and the Format function from SysUtils to line up the columns of a café receipt.Lesson 4
  5. 5Reading from the keyboardAsk the user for data with ReadLn in Pascal: text and numbers, one per line or several on the same line, to work out the price of cinema tickets.Lesson 5
  6. 6if, then and elseMake decisions in Pascal with if, then and else: weather warnings and exam grades, with begin…end blocks and else if chains.Lesson 6
  7. 7The case statementChoose between many values with case in Pascal: days of the week, grade ranges and the menu of a vending machine.Lesson 7
  8. 8Booleans and comparisonsCompare values in Pascal with =, <>, < and >, and combine conditions with and, or, not and xor to decide who rides the roller coaster.Lesson 8
  9. 9while and repeat…untilRepeat code in Pascal while a condition holds: while checks it before each pass and repeat…until checks it at the end.Lesson 9
  10. 10for loops with to and downtoCount with for in Pascal: to counts up, downto counts down, plus running totals, Char counters and nested loops for cinema seats.Lesson 10
  11. 11Static arraysStore several values of the same type in a Pascal array: a week of temperatures, with the average and the hottest day.Lesson 11
  12. 12Working with stringsWork with text in Pascal: join with +, then Length, Copy, Pos, UpperCase and LowerCase to split an email address into user and domain.Lesson 12
  13. 13ProceduresGroup named blocks of code into Pascal procedures, with parameters and local variables, to print a bakery receipt.Lesson 13
  14. 14Functions and ResultWrite Pascal functions that return a value through Result: Celsius to Fahrenheit, prices with VAT and whether a year is a leap year.Lesson 14
  15. 15var and const parametersPass Pascal parameters by value, by reference with var, and read-only with const, and return several results from one procedure.Lesson 15
  16. 16RecordsGroup related data in a Pascal record: a stationery shop's products with name, price and stock, plus functions that use them.Lesson 16
  17. 17Enumerated types and setsDefine enumerated types and sets in Pascal: a shop's opening days with in, Include, Exclude, Ord, Succ and set intersection.Lesson 17
  18. 18Dynamic arraysUse Pascal dynamic arrays that grow and shrink with SetLength: a shopping cart with routines to add items and total them up.Lesson 18
  19. 19Text filesWrite and read text files in Pascal with AssignFile, Rewrite, Append, Reset, ReadLn and CloseFile: a shopping list saved to disk.Lesson 19
  20. 20Project: a shop invoiceA small Pascal project that brings together records, arrays, loops, procedures and Format to print the invoice of a computer shop.Lesson 20

For those who know the basics: the techniques used in real projects.

  1. 1Classes and objectsDeclare Object Pascal classes with fields, methods, a constructor and a destructor, and learn to release objects with Free in Free Pascal.Lesson 1
  2. 2Visibility and propertiesProtect your class data with private and public, and expose it through properties that validate on write and compute on read in Object Pascal.Lesson 2
  3. 3Inheritance and inheritedBuild child classes in Object Pascal that inherit fields and methods, and call the parent constructor with inherited in Free Pascal.Lesson 3
  4. 4Virtual methods and polymorphismUse virtual and override in Object Pascal so each class answers the same call in its own way: polymorphism with shipping rates.Lesson 4
  5. 5Abstract classesDeclare abstract methods in Object Pascal to define a common outline that each child class fills in, with payment methods and their fees.Lesson 5
  6. 6InterfacesDefine Object Pascal interfaces, implement them in unrelated classes and let reference counting free the objects for you.Lesson 6
  7. 7ExceptionsRaise and catch exceptions in Object Pascal with raise and try/except, and create your own exception classes for your application's errors.Lesson 7
  8. 8Try/finally and cleanupMake sure your objects are released even when errors happen with try/finally in Object Pascal, the pattern that prevents memory leaks.Lesson 8
  9. 9Pointers, New and DisposeWork with pointers in Pascal: addresses with @, access with ^, and dynamic memory allocated with New and released with Dispose.Lesson 9
  10. 10A linked listBuild a linked list in Pascal with records and pointers: create nodes, insert in the middle without moving anything and free all the memory.Lesson 10
  11. 11Generics with fglUse the generic lists and maps from Free Pascal's fgl unit, TFPGList and TFPGMap, to store orders and stock with their exact types.Lesson 11
  12. 12Generics.CollectionsCount sales per city with TDictionary and sort the result with TList, the generic collections in Free Pascal's Generics.Collections unit.Lesson 12
  13. 13TStringList in depthSort, search and store name=value pairs with TStringList, the string list from the Classes unit that every Free Pascal and Lazarus program uses.Lesson 13
  14. 14Procedural types and callbacksPass functions and methods as parameters in Object Pascal with procedural types and of object, the mechanism behind Lazarus events.Lesson 14
  15. 15Operator overloadingDefine +, * and conversions for your own types with advanced records in Free Pascal: a money type in cents that adds up like a number.Lesson 15
  16. 16Recursion and backtrackingSolve search problems with recursion and backtracking in Pascal: which pending invoices add up exactly to the amount of a payment.Lesson 16
  17. 17Quicksort and binary searchWrite quicksort and binary search in Pascal with open arrays and recursion, and see why searching a sorted list is so fast.Lesson 17
  18. 18Strings with StrUtils and FormatSplit, align, transform and mask text with the StrUtils functions and Format patterns in Free Pascal, working on a line from a CSV file.Lesson 18
  19. 19JSON with fpjsonRead and build JSON in Free Pascal with fpjson and jsonparser: walk an order, add up its lines and reply with a brand new JSON object.Lesson 19
  20. 20Project: a small bankBring classes, inheritance, generics and exceptions together in a small Object Pascal bank that refuses impossible withdrawals and frees all its memory.Lesson 20