Question

There is a simple cxMaskEdit, having standard mask: '## ### ###;1; '. Also, the AutoSelect is False.

All good, but when I return to the cxMaskEdit using cxMaskEdit.SetFocus, it changes the last character from cxMaskEdit.

For example: 12 141 141 is becoming 12 141 140 on cxMaskEdit enter (by mouse. by setFocus).

Any help with this behaviour ? l.e: This behaviour is given by

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;
Was it helpful?

Solution

Solved by using Selection Start and Length.

  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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top