2014-04-10 23 views
1

有一個簡單的cxMaskEdit,它有標準的掩碼:'## ### ###; 1; 」。 另外,AutoSelect是False。MaskEdit覆蓋輸入的最後一個字符

一切都很好,但是當我使用cxMaskEdit.SetFocus返回到cxMaskEdit時,它會更改cxMaskEdit中的最後一個字符。

例如: 12 141 141在cxMaskEdit上變爲12 141 140(通過鼠標。通過setFocus)。

這種行爲的任何幫助? l.e:此行爲由

procedure TForm1.cxMaskEdit1KeyDown(Sender: TObject; var Key: Word; 
    Shift: TShiftState); 
begin 
    if (cxMaskEdit1.CursorPos = 10) then 
    if ((Key > 48) and (Key < 58)) or ((Key > 95) and (Key < 106)) then 
    begin 
     cxMaskEdit2.SetFocus; 
     // cxMaskEdit2.SelStart := 0; 
    end; 
end; 
+1

此MaskEdit上的任何事件?如果你只是打開一個新項目,在窗體上拖動一個cxMaskEdit並設置其掩碼,它是否顯示相同的行爲?將第二個編輯添加到表單以便能夠更改焦點。 – GabrielF

+0

作爲事件,只在按下按鈕。將在明天進行一項新項目的檢查。 – Vladds7

+0

@GabrielF:我設法通過使用我添加到問題中的代碼來重現新項目上的行爲。 – Vladds7

回答

0

通過使用選擇開始和長度來解決。

if ((MaskEdit1.SelStart = 9) and (((47 < Key) and (Key < 58)) or (95 < Key) 
    and (Key < 106))) then 
    begin 
    MaskEdit2.SetFocus; 
    MaskEdit2.SelStart := 0; 
    MaskEdit2.SelLength := 1; 
    end; 
相關問題