maskedit / CustomEdit and allignment

fabreti
fabreti used Ask the Experts™
on
Hi there,

  I want to insert a number like 123.232.456 and found that a mask edit would be great.
  But if I set SelStart:=10 I can only insert 1 number.

  Is there a way numbers shift to the left while I insert them ?

  I've seen in the help that TCustomEdit have an allignment property, but where is the CustomEdit button ? (so I can insert one in my form).

thanks,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
there is no TCustomEdit, there is no TCustomForm, or TCustomDBGrid or any other "Custom" Class, These custom classes are "Parent" classes for other Components, The TCustomEdit is the parent class for the TEdit and TMaskEdit, and others. I don't understand your question, shift left? ? You can move the SelStart to whereever you want, for instance

Edit1.SelStart:=10;
{insert a charater here at the SelStart}
Edit1.SelStart:=10;
{move the claret back to where it was, or any other location}
{insert another charater here at the SelStart}

Author

Commented:
Humm...Ok, thanks for your custom advice :-)

Well, let me explain:
  if my mask is 999.999.999 then I can insert a number like 123.456.789 and it looks great.
  But if my number is 1234 it will look like 123.4
  Instead, if I had a way to "shift left" every digit inserted, always inserting new numbers on the right, it would look like 1.234 (looks much more like one thousand two hundred thirty for THAN 123.4, doesn't it?)
  That's what I meant. Got it ?
it sounds like you want something like

MaskEdit1.ShiftToLeft := True;

but there is no property to do what you want, So you will have to take over what the MaskEdit does with the Charaters, I could subclass it but it already has extensive charater manipulation, being a Mask Edit. So here's my version, get the OnKeyPress event for the maskEdit in the object inspector -


procedure TForm1.MaskEdit1KeyPress(Sender: TObject; var Key: Char);
var
i: Integer;
Str1: String;
begin
Label1.Caption := MaskEdit1.Text;
Str1 := MaskEdit1.Text;
{this MaskEdit1.SelStart = 10 could be different for yours
but it's the position of the last character}
if MaskEdit1.SelStart = 10 then
  begin
  MaskEdit1.SelText := Key;
  for i := Length(Str1)-1 downto 1 do
    begin
    if Str1[i+1] <> '.' then
    if Str1[i] <> '.' then
      begin
      MaskEdit1.SelStart := i-1;
      MaskEdit1.SelLength := 1;
      MaskEdit1.SelText := Str1[i+1];
      end else
      begin
      MaskEdit1.SelStart := i-2;
      MaskEdit1.SelLength := 1;
      MaskEdit1.SelText := Str1[i+1];
      end;
    end;
  MaskEdit1.SelStart := 10;
  MaskEdit1.SelLength := 1;
  Key := #0;
  end;
end;

Author

Commented:
Slick,

  Didn't test it yet. But gave me ideas...

  Thank you for your time,

Fabreti.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial