Master Cross-Platform Development: A Deep Dive into Delphi FMX Samples
If you are transitioning from VCL to FireMonkey (FMX) or looking to sharpen your cross-platform skills, the best way to learn is through hands-on exploration. FireMonkey is more than just a library; it’s a powerful framework that allows you to write one codebase for Windows, macOS, iOS, Android, and Linux.
The following guide explores the most essential Delphi FMX samples that every developer should master to build modern, high-performance applications. 1. The Power of Styles: The "CustomListBox" Sample
Unlike VCL, which relies on the operating system to draw controls, FMX uses a GPU-accelerated drawing engine. This means everything is a "primitive" that can be styled.
Why it matters: In FMX, a ListBox isn’t just for text. You can embed images, switches, buttons, and custom shapes into every item.
Key takeaway: Study the CustomListBox sample to understand the Styles Designer. Learning how to manipulate the StyleLookup property is the secret to making an Android app look native while maintaining a unique brand identity.
2. Layouts and Responsiveness: "FlowLayout" and "GridPanelLayout"
One of the biggest hurdles in cross-platform design is screen size variance. An app that looks great on a desktop monitor can break on a 6-inch phone screen. The Sample: Look for the Layouts demo project.
What to learn: Focus on TFlowLayout. It acts like HTML/CSS wrapping, where controls automatically shift to the next "line" when the container shrinks. Mastering TScaledLayout is also vital for apps that need to maintain exact proportions regardless of resolution. delphi fmx samples
3. Low-Level Graphics: "FireMonkey Mirror" and "Shader" Demos
Because FireMonkey uses DirectX (Windows) and OpenGL/Metal (macOS/Mobile), you have direct access to the GPU. The Sample: The ControlRollup or Shader demos.
Practical Use: These samples show you how to apply visual effects—like blurs, shadows, and reflections—without hitting the CPU. If you want to build a high-end UI with smooth animations, these samples demonstrate how to use TEffect and TAnimation components effectively.
4. Interacting with Hardware: "Location" and "Camera" Samples
Mobile development is nothing without hardware integration. Delphi provides wrapper components that make "coding to the metal" surprisingly simple. The Samples: LocationDemo and CameraComponent.
The Lesson: These samples teach you how to handle Permissions. Since Android 6.0 and iOS 10, requesting permissions at runtime is mandatory. These demos show the standard pattern for checking if a user has granted access to the GPS or camera before the app attempts to use them. 5. Data Binding: "LiveBindings" Samples
Gone are the days of manually coding Label1.Text := Table1Field1.AsString. FireMonkey relies heavily on LiveBindings. The Sample: LiveBindingsVisual demo.
Why it’s essential: LiveBindings allows you to visually connect data sources to UI elements. It’s powerful but has a learning curve. Studying the samples helps you understand how to use the LiveBindings Designer to create complex data links without writing a single line of boilerplate code. Where to Find These Samples? Master Cross-Platform Development: A Deep Dive into Delphi
You don't need to scour the web to find these. Embarcadero includes them directly in your installation:
Path: C:\Users\Public\Documents\Embarcadero\Studio\XX.0\Samples\Object Pascal\Multi-Device Samples
Additionally, the GitHub repository for Embarcadero is frequently updated with community-driven samples that cover modern features like App Tethering and JSON REST integration. Conclusion
Delphi FMX is a massive framework, but you don't have to learn it all at once. By deconstructing these samples, you move from "standard" UI development into the world of high-performance, GPU-powered, multi-device applications.
Delphi's FireMonkey (FMX) framework offers a robust library of samples designed to demonstrate cross-platform capabilities across Windows, macOS, iOS, Android, and Linux. These samples range from basic UI controls to advanced hardware integration. Core FMX Sample Categories
Samples are typically categorized by their functional focus to help developers navigate specific cross-platform challenges: FMX.CopyPaste Sample - RAD Studio Code Examples
How to Use the Sample * Navigate to one of the locations given above and open: Delphi: CopyPaste. dproj. C++: CopyPaste. cbproj. * Embarcadero DocWiki Category:FMX - RAD Studio Code Examples
TAnimator and TAnimation classes to move, fade, rotate controls.TSVGIconImage or TImageViewer.A sample demonstrating the use of the TCamera component to access the device's camera. AnimatedShapes – Uses TAnimator and TAnimation classes to
program CameraSample;
uses
System.StartUpCopy,
FMX.Forms,
FMX.Controls,
FMX.Types,
FMX.Camera;
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Form1.Camera1.Active := True;
Application.Run;
end.
// Touch-based audio mixer with real-time effects
TTouchMixer = class
procedure OnTouch(Point: TPoint; TouchID: Integer);
procedure ApplyEffect(EffectType: TAudioEffect; Value: Single);
end;
Let's walk through a real scenario: building a "Field Service Report" app for iOS and Android, starting from an FMX sample.
Step 1 – Starting Point: Download the official CameraDemo sample. It captures a photo and saves it to disk.
Step 2 – Add Signature Capture: Find a community sample for TPaintBox with OnMouseMove events. Merge that into a new form.
Step 3 – Add a Database: Use the FireDAC_SQLite_Sample to create a local table: CREATE TABLE Reports (ID INTEGER PRIMARY KEY, PhotoPath TEXT, SignaturePath TEXT, Notes TEXT).
Step 4 – Add Cloud Sync: Study the FMX.REST.Client sample (part of RESTRequest4Delphi, a community library). It shows how to upload images to an S3 bucket via HTTP multipart form data.
Step 5 – Polish UI: Apply a StyleBook from the FMX.Bootstrap.Styles sample (available on GitHub). This gives your app a modern, flat iOS/Android look in minutes.
Result: By assembling five different Delphi FMX samples, you create a production-ready cross-platform app in less than 1000 lines of Pascal code.
3D samples use a right-handed coordinate system with Z forward. Converting a 2D drag-and-drop sample to 3D requires recalculating using TControl3D.ScreenToLocal.