# free-pascal-snippets
**Repository Path**: sikale/free-pascal-snippets
## Basic Information
- **Project Name**: free-pascal-snippets
- **Description**: No description available
- **Primary Language**: Pascal
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-01-13
- **Last Updated**: 2025-12-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Free Pascal Snippets
## 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](https://ikelaiah.github.io/free-pascal-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)](https://www.freepascal.org) and [Lazarus IDE](https://www.lazarus-ide.org). You can use the [Lazarus IDE installer](https://www.lazarus-ide.org/index.php?page=downloads) or [`fpcupdeluxe`](https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases) 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:
- [@ikelaiah](https://github.com/ikelaiah) on GitHub
- the [Unofficial Free Pascal & Lazarus discord server](https://discord.com/channels/570025060312547359/570091337173696513).
Project Link: [https://github.com/ikelaiah/free-pascal-snippets](https://github.com/ikelaiah/free-pascal-snippets)
(back to top)
## 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;
- [Unofficial Free Pascal discord server](https://discord.com/channels/570025060312547359/570091337173696513).
- [Free Pascal & Lazarus forum](https://forum.lazarus.freepascal.org/index.php).
- [Tweaking4All Delphi, Lazarus, Free Pascal forum](https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/).
- [Laz Planet - Blogspot](https://lazplanet.blogspot.com) / [Laz Planet - GitLab](https://lazplanet.gitlab.io).
- [Delphi Basics](https://www.delphibasics.co.uk/index.html).
(back to top)