Getting Started with Embarcadero C++Builder XE8: A Beginner’s Guide

Building Cross-Platform Apps with Embarcadero C++Builder XE8

Embarcadero C++Builder XE8 remains a capable IDE for building native cross-platform applications from a single C++ codebase. This guide shows a practical workflow to create, adapt, and deploy apps for Windows, macOS (via FireMonkey mobile/macOS support at the time), iOS, and Android using XE8’s FireMonkey framework, plus tips to maximize portability and performance.

1. Why choose C++Builder XE8 for cross-platform development

  • Single codebase: FireMonkey (FMX) lets you write UI and business logic once and target multiple platforms.
  • Native performance: Compiles to native binaries for each platform, avoiding heavy runtime overhead.
  • RAD productivity: Visual designers, live bindings, and component libraries accelerate development.
  • Platform access: Platform services and conditional compilation let you use OS-specific APIs where needed.

2. Project setup and target platforms

  1. Create a new Multi-Device Application in XE8 and choose a FireMonkey template (Blank or Master-Detail).
  2. In Project Manager, add targets you intend to support: Windows ⁄64, iOS (device/simulator), Android. (macOS support depends on XE8 tooling and platform SDKs.)
  3. Configure SDKs: Install and link required SDKs—Android SDK/NDK and Java JDK for Android; Xcode and iOS SDK for iOS deployment. Ensure correct SDK paths in Tools > Options > SDK Manager.
  4. Set conditional defines per platform if you plan platform-specific compilation (e.g., MSWINDOWS, ANDROID, IOS).

3. UI design with FireMonkey

  • Use FMX visual components (TForm, TButton, TListView, TImage) which render natively on each platform.
  • Prefer layouts (TLayout, TGridPanelLayout, TFlowLayout) over absolute positioning for responsive UIs.
  • Use Anchors and Align properties to adapt to varying screen sizes and orientations.
  • Styles: Create platform-specific styles only when necessary; otherwise rely on FireMonkey’s style mechanism for consistent look-and-feel. Use StyledSettings to keep native font/colors where desired.

4. Shared code patterns

  • Separate UI and business logic: Put platform-agnostic logic in separate units or static libraries that compile for all targets.
  • Abstract platform services behind interfaces. Implement platform-specific functionality (notifications, camera, file access) using IFMXPlatformService or custom interface wrappers with conditional compilation.
  • Use LiveBindings to connect UI and data models with less boilerplate.

5. Handling platform-specific features

  • Conditional compilation example:

    cpp

    #if defined(_WIN32) // Windows-specific code #elif defined(ANDROID) // Android-specific code #elif defined(APPLE) // iOS/macOS-specific code #endif
  • Use JNI (Android) or Objective-C bridges (iOS) for low-level native APIs. XE8 provides helper units (Androidapi.and iOSapi.*) for bridging.
  • Packaging and entitlements: Set Android manifest tweaks and iOS provisioning profiles/capabilities in Project Options before deployment.

6. Data storage and networking

  • Use FireDAC for database access — it supports local SQLite and many server databases. Configure paths so local DB files are stored in the platform-appropriate app data folder.
  • For REST and HTTP, use TNetHTTPClient / TRESTClient and JSON libraries included in XE8. Handle network availability gracefully and perform long-running requests on background threads or using async patterns.

7. Threading and concurrency

  • Use TTask and System::Threading for concurrent work; marshal UI updates to the main thread via TThread::Queue or TThread::Synchronize.
  • Avoid heavy UI work on the main thread to keep interfaces responsive on mobile devices.

8. Testing and debugging

  • Test early on actual devices—emulators/simulators can differ in performance and behavior.
  • Use platform-specific debugging targets in the IDE. For Android, enable USB debugging and use logcat; for iOS, use Xcode device logs.
  • Profile performance hotspots and optimize rendering (reduce overdraw, use cached bitmaps where appropriate).

9. Packaging and deployment

  • Android: Configure manifest permissions, icon resources, and sign the APK using keystore settings in Project Options. Use Gradle tools if integrating newer build flows.
  • iOS: Ensure correct provisioning profiles and code signing. Build for device or archive for TestFlight/App Store distribution.
  • Windows: Produce ⁄64-bit installers or distribute portable executables; include required runtime files if using third-party libraries.

10. Performance and size optimizations

  • Strip unused units and enable compiler optimizations in Project Options.
  • Reduce resource sizes: compress images, use vector assets where appropriate, and minimize embedded resources.
  • For mobile, prefer scalable UI and efficient repaint strategies to limit battery and CPU usage.

11. Common pitfalls and fixes

  • SDK mismatch: Keep Android SDK/NDK and Java versions compatible with XE8 requirements.
  • Case-sensitive file issues: macOS/iOS builds can fail if unit filenames differ only by case—use consistent naming.
  • Third-party libraries: Verify availability of libraries for each target or compile separate binaries for each platform.

12. Example project structure

  • MyApp/
    • Source/
      • MainForm.cpp/h (FMX UI)
      • AppLogic.cpp/h (shared logic)
      • PlatformServices.cpp/h (conditional platform implementations)
    • Resources/
    • Assets/
    • ProjectGroup.groupproj
    • MyApp.cbproj

13. Quick checklist before release

  • Test on minimum supported OS versions.
  • Verify app permissions and privacy strings (iOS).
  • Sign and notarize if required by platform.
  • Run final performance and memory checks.

Conclusion With FireMonkey and XE8’s native compilers, you can efficiently build and deploy high-performance cross-platform C++ applications. Structure your code for separation of concerns, use FMX’s responsive layout system, and handle platform-specific needs with clean abstractions to maintain a single, maintainable codebase.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *