Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

free-pascal-snippets

This repository contains Free Pascal code snippets that I've put together while learning.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Free Pascal Snippets

Logo

Free Pascal Snippets

pascal
A collection of Free Pascal snippets that I put together while learning Object Pascal.

This repo is part of my study note — Free Pascal Cookbook.

pascal
[Explore the docs ??](https://github.com/ikelaiah/free-pascal-snippets)
pascal
[Explore Contents](#contents)
??
 [Read Free Pascal Cookbook](https://ikelaiah.github.io/free-pascal-cookbook)
??
[View Cookbook repo](https://github.com/ikelaiah/free-pascal-cookbook)

About The Project

Demo Screen 1

This repository contains a collection of Free Pascal code snippets (work in progress) that I put togehter while studying Object Pascal with the Lazarus IDE and the Free Pascal Compiler (FPC).

It is a part of the Free Pascal and Lazarus Cookbook project.

(back to top)

Contents

The source code is organized into the following categories and example subfolders:

Basic Concepts

  • HelloWorld/
    • HelloWorldAlt/
    • HelloWorldPause/
    • HelloWorldSimple/
  • Variables/
    • BasicVariableTypes/
    • VariableAssignment/
  • Numbers/
    • BasicMathOperations/
    • FormatCurrency/
    • FormatNumberCommas/
    • NDecimalRoundingBanker/
    • NDecimalsRoundingExamples/
    • RandomNumberBetween/
    • RandomNumberSimple/
    • RandomRealNumberBetween/
    • RandomRealNumberList/
    • RandomRealNumberListv2/
    • RoundingExamples/
  • Strings/
    • StringOperationsExample/
    • TrailingCommas/
  • Arrays/
    • DynArrayConcat/
    • DynArrayDemo01/
    • DynArrayDemo02/
    • StaticArrayDemo/
    • StaticArrayDemo02/
  • Lists/
    • AppendFGLList/
    • DynamicArray/
    • FGLIntegerList/
    • LGIntegerList/
    • LGIntegerListSort/
    • SimpleIntegerList/
    • StaticArray/
    • StringList/
    • TListCustomComparison/
  • Loops/
    • ForInLoop/
    • Loops/
  • FuncProc/
    • ExampleFunctionWithoutParams/
    • ExampleFunctionWithParams/
    • ExampleFunctionWithVarSection/
    • ExampleProcedureWithoutParams/
    • ExampleProcedureWithParams/
    • ExampleProcedureWithVarSection/
    • ParamModifierConst/
    • ParamModifierVar/

Intermediate Features

  • Class/
    • ClassExample/
  • Records/
    • AdvancedRecordExample/
  • Interfaces/
    • COMInterfaceExample/
  • Generics/
    • GenericClassExample/
    • GenericFunctionExample/
    • GenericRecordExample/
  • AnonymousFunctions/ (⚠️requires FPC trunk)
    • AnonymousFuncGradeCalculator/
    • AnonymousFuncSimple/
    • StudentDataProcessor/
  • FunctionReferences/
    • CalculatorExample/
    • FuncRefDigitalCircuitSimulator/
    • FuncRefSimple/
  • Threading
    • AssignStudentIDs/
    • CreateThreads/
    • CreateThreadsCriticalSection/
    • CriticalSectionIncrementCounter/
    • EX1SingleThread/
    • EX2MultiThread/
    • EX3MultiThread/
    • ezthreadsDependency/
    • ezthreadsPool/
    • ezthreadsSimple/
    • LargeTextFileParser/
  • Immutability
    • Immutability/
  • Subrange
    • SubrangeDaysofWeek/

File & I/O Operations

  • ConsoleInputOutput/
    • ConsoleIO/
    • ReadExample/
    • WriteExample/
  • CommandLineArguments/
    • CLSimple/
    • GetOptSimple/
  • DirsPathsFiles/
    • CheckDirExists/
    • CollectFilePaths/
    • FindFirstSearch/
    • FindFirstSearchRecursive/
    • FindFirstSearchRegex/
    • FindFirstSearchRegexStoreInArray/
    • FindFirstSearchStoreInArray/
    • GetHomeDir/
    • ListAllFiles/
  • FileHandling/
    • BasicReadTextFileClassic/
    • BasicWriteTextFile/
    • ClassicAppendTextFile/
    • ClassicCountLine/
    • ClassicCreateBlankTextFile/
    • ClassicNewTextFile/
    • ClassicNewTextFileOrganised/
    • ClassicReadTextFile/
    • SimpleReadTextFile/
    • SimpleWriteText/
    • TBufferedFIleStreamCount/
    • TBufferedFileStreamReadFile/
    • TFileStreamAppendTextFile/
    • TFileStreamCreateBlankTextFile/
    • TFileStreamNewTextFile/
    • TFileStreamNewTextFileOrganised/
    • TFileStreamSplitFile/
    • TStreadReaderReadFileTidy/
    • TStreamReaderCount/
    • TStreamReaderReadFile/
    • TStringListAppend/
    • TStringListBlankFile/
    • TStringListNewTextFile/
    • TStringListReadTextFile/
  • FileHandling_II/
    • TCSVDatasetGetSpecificCols/
    • TCSVDocumentGetSpecificCols/

Advanced Topics

  • DateTime/
    • DateTimeBenchmark/
    • DateTimeBetween/
    • DateTimeComparison/
    • DateTimeCurrent/
    • DateTimeUnix/
    • ParseDate/
  • Debugging/
    • HeapMemoryLeaks/
  • Regex/
    • MatchingFilename/
    • MatchingFilenameAlt/
    • RegexExample/
    • ReplaceDateSeparators/
  • Networking/
    • GetRequest/
    • ParseJSON/
    • SimpleApiWebserver/
  • CodeStructure/
    • ProgramStructure/
    • SimpleProgram/
    • SimpleProgramWithUnit/
    • UnitStructure/
  • ZipUnzip/
    • UnzipEx01/
    • UnzipFile/
    • ZipEx01/
    • ZipEx02/
    • ZipEx03/
    • ZipFiles/

Libraries & Frameworks

  • LGenerics/
    • GHashmapLP/
  • Mormot2/
    • Collections/
    • CollectionsV2/
    • MormotKeyValueDemo/
  • NumLib/
    • eig_general_matrix/
    • eig_symband_matrix/
    • eig_symtridiag_matrix/
    • InnerProductVectors/
    • integrate/
    • inverse_matrix/
    • matrix_example/
    • omvinp_demo/
    • omvmmv_demo/
    • omvtrm_demo/
    • omv_norm_demo/
    • polynomial_fit/
    • solve_band/
    • solve_leastsquares/
    • solve_linear_eq/
    • solve_ode/
    • solve_ode_sys/
    • solve_root_binomial/
    • solve_root_bisection/
    • solve_root_nonlinear/
    • solve_root_polynomials/
    • solve_root_quadratic/
    • solve_spd/
    • solve_tridiag_matrix/
    • spline_interpolation/
  • Lazarus/
    • HelloWorld/

Compilation Output

When you compile any project, the executable output will be placed in the top-level bin/ folder of the repository.

Why? This keeps the compiled binaries separate from the source code and makes it easier for me to manage multiple examples.

Getting Started

Prerequisites

  1. Interest in Object Pascal.
  2. Install both the Free Pascal Compiler (FPC) and Lazarus IDE. You can use the Lazarus IDE installer or fpcupdeluxe to install both.

Installation

None. Just download or git clone the repo to your local drive.

Build and Clean All Projects

To build or clean all Lazarus projects in this repository, use the provided scripts from the repo root:

Windows (PowerShell)

  • Build all projects:
    powershell
    ./build-all.ps1
  • Clean all build output:
    powershell
    ./clean-all.ps1

Linux/macOS (Bash)

  • Build all projects:
    bash
    ./build-all.sh
  • Clean all build output:
    bash
    ./clean-all.sh

The scripts will check if lazbuild is available and show a clear error message with emojis if not. Cleaning scripts will remove all common build artifacts and the bin/ folder.

(back to top)

Usage

Using Lazarus IDE

  1. Launch your Lazarus IDE.
  2. Top bar menu, go to Projects - Open Project ....
  3. Navigate to the snippet folder you'd like to see, and open the .lpi file.

Using your favourite text editor

  1. Navigate to an example folder.
  2. Open the .lpr file. This is the program source code.

License

Distributed under the MIT License. See LICENSE.md for more information.

(back to top)

Contact

Find me at these places:

Project Link: [https://github.com/ikelaiah/free-pascal-snippets](https://github.com/ikelaiah/free-pascal-snippets)

(back to top)

Acknowledgments

(back to top)