2013-03-26 48 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

相關問題