Catalog · How the catalog works
free-pascal-snippets
This repository contains Free Pascal code snippets that I've put together while learning.
- ★ 13 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
Free Pascal Snippets
Free Pascal Snippets
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.
[Explore the docs ??](https://github.com/ikelaiah/free-pascal-snippets)[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

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.
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
- Interest in Object Pascal.
- Install both the Free Pascal Compiler (FPC) and Lazarus IDE. You can use the Lazarus IDE installer or
fpcupdeluxeto 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:
./build-all.ps1 - Clean all build output:
./clean-all.ps1
Linux/macOS (Bash)
- Build all projects:
./build-all.sh - Clean all build output:
./clean-all.sh
The scripts will check if
lazbuildis available and show a clear error message with emojis if not. Cleaning scripts will remove all common build artifacts and thebin/folder.
Usage
Using Lazarus IDE
- Launch your Lazarus IDE.
- Top bar menu, go to
Projects-Open Project .... - Navigate to the snippet folder you'd like to see, and open the
.lpifile.
Using your favourite text editor
- Navigate to an example folder.
- Open the
.lprfile. This is the program source code.
License
Distributed under the MIT License. See LICENSE.md for more information.
Contact
Find me at these places:
- @ikelaiah on GitHub
- the Unofficial Free Pascal & Lazarus discord server.
Project Link: [https://github.com/ikelaiah/free-pascal-snippets](https://github.com/ikelaiah/free-pascal-snippets)
Acknowledgments
- The FPC devs for sharing the joy of Object Pascal.
- The Lazarus IDE devs for making such an amazing IDE.
- The dedicated people behind various units/modules in OPM.
- The kind and helpful individuals on various online platforms such as;


