DelphiMistralAI icon indicating copy to clipboard operation
DelphiMistralAI copied to clipboard

vcl/fmx compatility in mistralAI.files.pas

Open herveescriou opened this issue 7 months ago • 3 comments

mistralAI.files

is it possible to add a directive to use fmx

implementation

uses System.StrUtils, Rest.Json, System.Rtti, MistralAI.NetEncoding.Base64, {$ifdef fmx} fmx.Dialogs; {$else} Vcl.Dialogs; {$endif}

herveescriou avatar Sep 18 '25 22:09 herveescriou

Thanks for the suggestion

I’m keeping the wrapper 100% UI-agnostic (no VCL or FMX in the core) to ensure:

  • Separation of concerns: API logic ≠ UI.
  • Portability & testing: works in VCL, FMX, console, services, etc., with no extra dependencies or bloat.
  • Clean linking: avoids pulling in an unnecessary UI framework.

[!note] Embarcadero strongly advises against mixing VCL and FMX code in the same unit. A Delphi unit should be either VCL or FMX, but never both.

Recommended approach (on your side): create an adapter unit in your project that uses either VCL or FMX. Even cleaner: use callbacks/DI (the wrapper exposes OnLog, OnError, and your app plugs in VCL/FM X as needed). This keeps the wrapper platform-independent, and everyone can choose their preferred UI.

MaxiDonkey avatar Sep 19 '25 07:09 MaxiDonkey

Thank for the feedback

My app is only fmx and target android, ios, windows

In the 2 mistralAI units : mistraAI.files.pas and mistralAI.httpx.pas there is reference to vcl (vcl.dialogs) in mistraAI.files.pas and reference with windows api ( Winapi.Windows, Winapi.ShellAP ) in misltralAI.httpx.pas in the uses part of the units. It was the reason of my remark. With these dependencies i can't compile for Android delphi 12.3

herveescriou avatar Sep 19 '25 08:09 herveescriou

Honestly, we should have started with that and just told me I’d made a blunder ;)

I’ve removed the VCL.Dialogs unit, which definitely didn’t belong in MistralAI.Files.pas, and fixed the issue in MistralAI.Httpx.pas as well.

Version 1.3.1 has just been published. Feel free to grab it and let me know if you’re still having any issues compiling on Android.

MaxiDonkey avatar Sep 19 '25 09:09 MaxiDonkey