起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 187|回复: 4

【结贴】DisplayText和Text有什么区别

[复制链接]
发表于 2010-3-19 17:36:40 | 显示全部楼层 |阅读模式
除了前者是只读后者可读可写以外
回复

使用道具 举报

发表于 2010-3-19 17:44:00 | 显示全部楼层
似乎是因为都是继承的一个基类,然后衍生后出现的两个属性。 有些控件这两个除了readonly没什么区别。
咱们都没源码,也不能准确知道。否则看下源码就清楚了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-3-19 22:09:57 | 显示全部楼层
那麻烦问问开发吧
回复 支持 反对

使用道具 举报

发表于 2010-3-22 10:03:50 | 显示全部楼层
这个问题非要解释的话,似乎也不太容易说的明白。还是看源文档吧:
这是DisplayText
Represents the field’s value as it is displayed in a data-aware control.

property DisplayText: String;

Description

DisplayText is a read-only string representation of a field’s value for displaying in data-aware controls. It represents the field’s value when it is not being edited. When the field is being edited, use the Text property.

If the field has an OnGetText event handler, DisplayText is the value returned in the Text parameter of the OnGetText event handler when its DisplayText parameter is True. Otherwise, DisplayText is the value of the AsString property.

这是Text
Contains the string to display in a data-aware control when the field is in edit mode.

property Text: String;

Description

Data-aware controls rely on the Text property to provide the editing format for each field. For example, by default the Text property of a currency field omits the thousands separators and currency symbol.

Text can differ from the DisplayText property if the field uses a different string representation when the value is being edited. To implement two different string representations of a field’s value, use the OnGetText event handler. If an OnGetText event handler is assigned, Text is the value returned in the Text parameter of the event handler when the DisplayText parameter is False. If there is no OnGetText event handler, Text is the value of the AsString property.

再来看源代码
function TField.GetDisplayText: string;
begin
  Result := '';
  if Assigned(FOnGetText) then
    FOnGetText(Self, Result, True) else
    GetText(Result, True);
end;

function TField.GetEditText: string;
begin
  Result := '';
  if Assigned(FOnGetText) then
    FOnGetText(Self, Result, False) else
    GetText(Result, False);
end;
可以比较容易的看到其差别主要是在OnGetText事件的处理上,可以通过最后一个参数DisplayText,来决定对同一个数据做不同的显示,一般常见的用法是枚举,delphi编码的时候都是E文的,显然直接表现给操作者界面不太友好,所以要用汉字(DisplayText)的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-3-22 10:36:39 | 显示全部楼层
好,我们再看看Delphi相关资料,谢谢解答,请结贴。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-10 05:54 , Processed in 0.039142 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表