使用 Delphi 12 开发 Android 移动应用时,开发者使用了 FireDAC 数据库组件,通过 SQLite 存储数据,并实现了 FDSSecurity 组件进行数据加密。在 Delphi 11 中可以正常运行,但在 Delphi 12 中运行时出现了错误:
Project raised exception class EFDException with message ‘[FireDAC][Phys][SQLite][sqlite3]-303. Capability is not supported’.
为了解决这个问题,开发者尝试了以下代码:
initialization
FDPhysSQLiteDriverLink := TFDPhysSQLiteDriverLink.Create(nil);
FDPhysSQLiteDriverLink.EngineLinkage := slFDEStatic; // 兼容 Delphi >=12
finalization
FDPhysSQLiteDriverLink.Free;
然而,这导致了新的错误:
Project raised exception class EFDException with message ‘[FireDAC][Phys][SQLite]-1606. SQLite library linkage [FDEStatic] is not found. Hint: If static linkage is requested and supported, include [FireDAC.Phys.SQLiteWrapper.Stat] into your project’.
解决方案
根据错误提示,问题出在 SQLite 的静态链接方式上。Delphi 12 需要显式地包含一个特定的单元来支持静态链接。以下是解决步骤:
确保包含必要的单元:
在项目中包含 FireDAC.Phys.SQLiteWrapper.Stat 单元。这可以通过在项目文件(.dpr)中添加以下代码来实现:
uses
FireDAC.Phys.SQLiteWrapper.Stat;
调整链接方式:
如果仍然需要使用静态链接,确保 EngineLinkage 属性设置为 slFDEStatic,并正确创建和释放 TFDPhysSQLiteDriverLink 对象。
检查 FireDAC 配置:
确保 FireDAC 的配置文件(FireDAC.inc)中没有冲突的设置,特别是关于链接方式的配置。
总结
在 Delphi 12 中使用 FireDAC 和 SQLite 时,如果需要静态链接 SQLite 库,必须显式地包含 FireDAC.Phys.SQLiteWrapper.Stat 单元。通过上述步骤,可以解决链接错误并确保应用正常运行。