procedure TForm1.Edit1Change(Sender: TObject);
begin
if length(edit1.text)=4 then
edit1.SelText:='-';
if length(edit1.text)=7 then
edit1.SelText:='-';
end;
解决了,大家看看是否有更好的办法:
procedure TForm1.medt1KeyPress(Sender: TObject; var Key: Char);
begin
if (medt1.SelStart=5) and (Key in ['2'..'9']) then
begin
medt1.SelLength:=2;
medt1.SelText:='0'+key;
end;
if (medt1.SelStart=8) and (Key in ['4'..'9']) then
begin
medt1.SelLength:=2;
medt1.SelText:='0'+key;
end;
end;