Sign in Join

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

Catalog · How the catalog works

Random project

Delphi_MVC

Samples of Delphi App with MVC Pattern

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

Delphi MVC

Samples of Delphi App with MVC Pattern, used for educational purposes.

Please note: The examples are simplified and not complete.

./banner-carlo-mvc

Examples:

Calculator

1. Calculator_VCL_Flat (no MVC)

A simple calculator without MVC pattern implementation.

2. Calculator_MVC (Enhanced - VCL & FMX)

A full-featured calculator application implementing the MVC pattern with both VCL and FireMonkey (FMX) support, demonstrating true cross-platform architecture.

Features:

  • Standard Calculator: Basic arithmetic operations with a clean, modern interface
  • Scientific Calculator: Extended with 6 scientific operations:
    • |x| - Absolute value
    • x³ - Cube
    • exp - Exponential (e^x)
    • x^y - Power (binary operation)
    • 10^x - Power of 10
    • log - Base-10 logarithm
  • Theme Selector (VCL only): Runtime enumeration and selection of VCL styles
  • Font Selector (VCL only): System font selection with live preview
  • Navigation Menu:
    • VCL: TSplitView with TCategoryButtons for easy navigation
    • FMX: TMultiView (Drawer mode) with TListBox for mobile-friendly navigation
  • Settings Persistence: Theme and window position saved to .ini file

Architecture:

  • Model-View-Controller Pattern: Clean separation of concerns
    • Model: Pure business logic and mathematical operations (shared between VCL and FMX)
    • View: Reusable frames implementing ICalculatorView interface
    • Controller: Mediates between Model and View (shared between VCL and FMX)
  • Frame-Based UI: Modular, reusable components for both VCL and FMX
  • Shared Business Logic: Model and Controller units work with both UI frameworks
  • Platform-Specific Views: Separate frame implementations for VCL and FMX
  • Full Keyboard Support: Complete keyboard input for both calculators (VCL)
  • Error Handling: Robust validation (division by zero, invalid logarithms, etc.)
  • Unicode Symbols: Mathematical symbols for better visualization

Technical Highlights:

Common (VCL & FMX):

  • Frame switching with dynamic Controller management
  • Separate Controllers for Standard and Scientific calculators
  • GridPanel/GridLayout for responsive button grids
  • Comprehensive XML documentation for educational purposes

VCL-Specific:

  • TSplitView with overlay mode for slide-in menu
  • TCategoryButtons with two categories (Calculator, Settings)
  • VCL Actions for operation handling
  • Intelligent keyboard input forwarding to active frame

FMX-Specific:

  • TMultiView in Drawer mode for mobile-friendly navigation
  • TListBox with custom styled items for menu
  • Cross-platform compatibility (Windows, macOS, iOS, Android)
  • Touch-friendly interface with larger buttons
  • Responsive layouts using TGridLayout

Project Structure:

pascal
Calculator_MVC/
????????? Sources/
???   ????????? Calculator.Types.pas          (Shared - VCL & FMX)
???   ????????? Calculator.Model.pas          (Shared - VCL & FMX)
???   ????????? Calculator.Controller.pas     (Shared - VCL & FMX)
???   ????????? Calculator.Resources.pas/dfm  (Shared - VCL & FMX)
???   ???
???   ????????? Calculator.MainForm.pas/dfm            (VCL Main Form)
???   ????????? Calculator.CalculatorFrame.pas/dfm     (VCL Standard Frame)
???   ????????? Calculator.ScientificFrame.pas/dfm     (VCL Scientific Frame)
???   ????????? Calculator.ThemeFrame.pas/dfm          (VCL Theme Selector)
???   ????????? Calculator.FontFrame.pas/dfm           (VCL Font Selector)
???   ???
???   ????????? Calculator.MainForm.FMX.pas/fmx        (FMX Main Form)
???   ????????? Calculator.CalculatorFrame.FMX.pas/fmx (FMX Standard Frame)
???   ????????? Calculator.ScientificFrame.FMX.pas/fmx (FMX Scientific Frame)
???
????????? Projects/
    ????????? Calculator.VCL.MVC.Project.dpr  (VCL Windows Application)
    ????????? Calculator.FMX.MVC.Project.dpr  (FMX Cross-Platform Application)

Code Reusability:

  • ~60% shared code: Model, Controller, and Types units work identically in both frameworks
  • ~40% platform-specific: UI frames and main forms adapted for VCL/FMX
  • Demonstrates best practices for maximizing code reuse in multi-platform Delphi applications

Orders/Customers

  1. MVC_Simple_Orders
  2. MVC_Orders_Customers
  3. MVC_Orders_Customers_IO

Delphi Day 2025

Demos and exercises for Delphi Day Seminar - Piacenza 16 June 2025

Licensing

Copyright (c) 2025 (Ethea S.r.l.)

Author: Carlo Barazzetta

Contributors: Claude Code

Licensed under the Apache License, Version 2.0 (the "License");