delphi - 在 livebindings CustomFormat 中使用 Format

标签 delphi delphi-xe4 livebindings

我正在尝试使用 LiveBindings 来格式化数字,以便在 FireMonkey 表单上的 TEdit 中显示。

我正在尝试使用绑定(bind)的 CustomFormat 中的 Format 方法来格式化具有两位小数的数字。

我可以对输出进行“硬编码”:

Format("Hello", %s)

它正在工作,但我无法弄清楚要使用什么格式字符串。如果我尝试使用标准格式字符串,例如,

Format("%.2f", %s)

我收到运行时错误“格式无效或与参数不兼容”。

事实上,每当我在格式字符串中包含 % 符号时,我都会收到错误,所以我猜测 Format 采用不同类型的参数,但我找不到任何文档来说明正确的格式字符串是什么。

最佳答案

您不能在 LiveBindings -> CustomFormat 中使用 Format('%.2f',[%s])

%s 是为数据保留的,对于 TEdit 来说,它是一个字符串

d : double;
s : string;
...
d := 1234.5678;
s:=Format('%.2f',[d]);

Format() 是将 [int、decimal、double、float] 转换为 字符串
所有其他都会给你一个错误:无效参数
例如,有效

TLinkControlToField1 -> CustomFormat : "Double : "+UpperCase(%s)

将在Edit1.text中给你

Double : 1234.5678

好的,我们知道“1234.5678”的 Uppercase() 没有任何效果。
只是为了显示(%s)是一个字符串

解决方案:

<小时/>

enter image description here

关于delphi - 在 livebindings CustomFormat 中使用 Format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18801484/

相关文章:

delphi - Delphi中如何自动生成getter和setter方法?

delphi - TDelphiTwain 组件,损坏 delphi 表单(dfm 文件)

delphi - 如何更改 FireMonkey 中的编辑控件背景颜色?

delphi - 如何对 TComboBox 进行编程更改以与 LiveBindings 配合良好?

delphi - Livebound 列表框保持为空,网格已填充

delphi - 在 D2010 中可以做类似 XE2 LiveBindings 的事情吗?

delphi - delphi 和 C++ Builder 中的组件?

delphi - 编译器是否优化(关闭)相同的 FieldByName 调用?

delphi - 如何拥有绘制弹出菜单项复选标记

json - 如何在 XE4 中使用 TFDJSONDataSets 或类似的?