Sign in Join

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

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

delphi-multi-threaded-sort-algorithms

Multi-threaded Sort Algorithms in Delphi

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Delphi Multi-threaded Sorting Algorithms Visualizer

Overview

This is a VCL-based desktop application written in Delphi that demonstrates parallel execution, thread-safe UI interactions, and custom canvas drawing. The application visually demonstrates 9 different sorting algorithms running concurrently in real-time on a randomized dataset.

This project serves as an excellent demonstration of concurrent programming, algorithm implementation, and custom UI rendering in Delphi.

Features & Architecture Showcased

  • Symmetric Concurrency: Nine independent TThread subclasses execute symmetrically and concurrently, each implementing a distinct sorting algorithm:
    1. Selection Sort
    2. Shell Sort
    3. Insertion Sort
    4. Merge Sort
    5. Quick Sort
    6. Heap Sort
    7. Bubble Sort
    8. Comb Sort
    9. Cocktail Shaker Sort
  • Decoupled Rendering Engine: Custom plotting using TPaintBox and OnPaint events.
    • Worker threads (TSorterThread) focus purely on algorithmic logic and safely update shared state records via pointers.
    • A detached TTimer master loop safely ticks at ~33 FPS to independently query thread states and redraw the visual grids without blocking the UI thread.
  • Double Buffering: Implemented DoubleBuffered := True natively on controls to completely eliminate visual tearing and flickering during high frame-rate canvas repaints.
  • Real-time Color Cues:
    • White/Grey: Unsorted elements.
    • Red/Blue: Active elements currently being compared or swapped by an algorithm inside the worker thread.
    • Green: Segments of data that are verified as sorted or have completed their algorithmic passes.
  • Modern Delphi Constructs:
    • Built-in memory leak detection (ReportMemoryLeaksOnShutdown := True;) demonstrating an awareness of robust memory management.
    • Usage of Generics (TArray<Integer>) rather than static or legacy types.
    • Responsive, dynamically scaling UI grid (OnResize) adjusting all 9 paint boxes seamlessly.

How to use

  1. Open the MultiSearchDemo.dpr project file in Embarcadero RAD Studio / Delphi.
  2. Press F9 or hit Run.
  3. Maximize the window if desired, then click the Start Algorithms Visualization button.
  4. Watch a randomly shuffled array visually sort itself across all 9 algorithms simultaneously! "# delphi-multi-threaded-sort-algorithms"