这个问题非要解释的话,似乎也不太容易说的明白。还是看源文档吧:
这是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)的。 |