![Logo](https://github.com/ikelaiah/free-pascal-snippets/raw/main/Images/logo.png)
A collection of Free Pascal snippets that I put together while learning Object Pascal.
This repo is part of my study note — Free Pascal and Lazarus Cookbook.
Explore the docs »
Explore Contents
·
Read Free Pascal and Lazarus Cookbook
·
View Cookbook repo
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.
All about structuring Pascal source files.
- ProgramStructure. Structure of a Pascal program.
- SimpleProgram. An example of a Pascal program.
- UnitStructure. Structure of a Unit file.
- SimpleProgramWithUnit. An example of creating and using a unit file.
The starting point for everyone.
- HelloWorldSimple. An example of a Hello World program.
- HelloWorldPause. An example of a Hello World program and pause console at the end.
- HelloWorldAlt. An example of a Hello World program with more readable directives.
All about parsing command line arguments and options.
- CLSimple. Parsing arguments using
ParamStr
andParamCount
. - GetOptSimple. An example of using
GetOpt
to parse command line flags.
- DateTimeBenchmark. A simple way to profile your program.
- DateTimeBetween. Finding time difference between two timestamps.
- DateTimeComparison. Comparing date times.
- DateTimeCurrent. Getting the current date time.
- DateTimeUnix. Getting date time in unix notation.
- ParseDate. A simple example of parsing a string into a
TDateTime
object usingScanDateTime
.
All about file handling; reading and writing.
- ClassicNewTextFile. Create a new text file the classical way.
- ClassicNewTextFileOrganised. Create a new text file the classical way but more organised.
- TFileStreamNewTextFile. Create a text file the object way.
- TFileStreamNewTextFileOrganised. Create a text file the object way but more organised.
- ClassicCreateBlankTextFile. The classical way of creating a blank file.
- TFileStreamCreateBlankTextFile. The object way of creating a blank file.
- TStreamReaderReadFile. Read a text file using
TStreamReader
. - TStreadReaderReadFileTidy. Read a text file using
TStreamReader
but more tidy.
- ParamModifierConst. Ensuring function arguments won't be changed in a function or procedure.
- ParamModifierVar. Moifying named parameters from a function or procedure.
Ensuring const
behaving like const
in other programing languages.
- Loops - Examples of loops in Free Pascal.
All about building lists in Free Pascal.
- StaticArray. Building and processing static arrays.
- DynamicArray. Building and processing dynamic arrays.
- StringList. Create a list of string.
- SimpleIntegerList. Create a list of integer using
Generics.Collections
unit and sort it. - TListCustomComparison. Crete a custom comparer for a
TList<T>
list. - FGLIntegerList. Create a list of integer using
fgl
unit and sort it. - AppendFPGList. Append two
TFPGList<integer>
lists. - LGIntegerList. Create a list of integer using
TGVector<T>
fromLGenerics
unit. - LGIntegerListSort. Sort a
TGVector<integer>
list.
All things about numbers.
- RandomNumberSimple. Generate a random number, simplest way.
- RandomNumberBetween. Generate a random integer number between two numbers.
- RandomRealNumberBetween. Generate a random real number between two numbers.
- RandomRealNumberList. Create a list of random number using LGenerics.
- RandomRealNumberListv2. Create a list of random number using a dynamic array.
Snippets relating to Folders, Paths and Filesnames.
- CheckDirExists - Check if a folder exists.
- GetHomeDir - Get user home dir in Free Pascal.
- ListAllFiles - List files recursively using wildcards.
Examples on using regex expressions.
- RegexSimpleExample. A simple pattern matching using regex.
- ReplaceDateSeparators. An example of replacing date separators using regex.
Using threads in Free Pascal.
- CreateThreads. A simple example of creating threads using
TThread
.
- GetRequest. A simple Get request demo. Based on FreePascal and JSON by Marcus Fernström.
- ParseJSON. A snippet to show how to parse JSON data. Based on FreePascal and JSON by Marcus Fernström.
- SimpleApiWebserver. An example ocreating a simple API webserver. Based on Create REST API’s with FreePascal by Marcus Fernström.
Install both the Free Pascal Compiler (FPC) and Lazarus IDE. Use fpcupdeluxe
.
You can find the latest installer here; https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases.
None. Just download or git clone
the repo to your local drive.
- 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
.lpi
file.
- Navigate to an example folder.
- Open the
.lpr
file. This is the program source code.
Distributed under the MIT License. See LICENSE.md
for more information.
Iwan Kelaiah - [email protected]
Project Link: https://github.com/ikelaiah/free-pascal-snippets
-
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;