在 delphi 7 中使用 unidac 时计算字段为空

Calculated fields are empty when using unidac in delphi 7

我在 Delphi 7 项目中使用 unidac 组件连接到 SQLite 数据库。 连接和查询工作正常,计算字段除外。

我的查询是这样的:

select  c.CardID,
    c.FirstName,
    c.SurName,
    c.Street,
    c.City,
    c.PostCode,
    c.Points,
    (select count(1) from FullCard f where f.CardID = c.CardID and f.Paid = 1) as PaidCards,
    (select count(1) from FullCard f where f.CardID = c.CardID and f.Paid = 0) as OpenCards,
    (select count(1) from FullCard f where f.CardID = c.CardID) as FullCards
from    Card c

当我在 SQLiteStudio 中 运行 时,此查询 returns 是一个正确的结果集,但是当我在 delphi 中 运行 时,计算字段是都是空的。

unidac 版本为 5.0.1 for Delphi 7.
我有一个 UniConnection 组件和一个 UniQuery 组件。连接属性似乎正确,因为我可以连接并从数据库查询。
UniQuery 组件有 SQL 属性 填充了上述查询,并且所有字段都被持久化。
当我执行 UniQuery1.Open 时,DBGrid 会填满所有记录,但字段 PaidCards、OpenCards 和 FullCards 都是空的。
相同的查询 returns 在 SQLiteStudio 中执行时这些字段已正确填充,所以我想查询本身没有任何问题。

我希望其他人也遇到过同样的问题,并且可以为我指出解决这个问题的方法。

此错误的解决方法是不使用持久字段。 当我不创建持久字段时,所有字段都被正确填充并且一切正常。 唯一的缺点是我必须在我的代码中使用 query1.FieldByName('FirstName').asString 而不是 query1FirstName.asString。