2013-03-26 47 views

回答

2

我发现使用DisplayFormat

9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999;0; 

感谢所有的答案。

+0

你使用什么数据类型? – jachguate 2013-03-27 00:31:06

+0

我正在使用一个字符串。 – dataol 2013-03-27 00:46:00

2

您不能像使用DisplayFormat属性那样格式化,但可以依赖OnGetText事件来实现此目的。

我假设你的领域是字符串类型,例如:

function InsertBlankEach4Chars(S: string): string; 
begin 
    Result := ''; 
    while S <> '' do 
    begin 
    Result := Result + Copy(S, 1, 4) + ' '; 
    Delete(S, 1, 4); 
    end; 
    Result := Trim(Result); 
end; 

procedure TMyForm.MyQueryFieldGetText(Sender: TField; 
    var Text: string; DisplayText: Boolean); 
begin 
    if DisplayText then 
    Text := InsertBlankEach4Chars(Sender.AsString) 
    else 
    Text := Sender.AsString; 
end; 

免责声明:此代码写在浏览器中,并没有进行测试。如果你打算在时间敏感的过程中使用它,我警告你可以优化这个函数以获得更好的性能。

+0

这不是如何使用''标签,但我不能争辩结果...... – 2013-03-26 21:08:19

+0

注意:如果字段类型是整型或largeInt,则可以使用DisplayText属性。只要将它设置为'0000 0000 0000 0000 ...'。 – alzaimar 2013-03-26 21:11:42

+0

我认为这是最好的解决方案。 – 2013-03-27 07:20:29

相关问题