procedure TForm1.Edit1Change(Sender: TObject);
var
li,lk, Commas: integer;
ls,ls1: string;
hasdigit: boolean;
begin
with (Sender as TEdit) do begin
lk:=SelStart;
Commas:=0; hasdigit:=false;
ls:=text; ls1:=ls;
for li:=1 to length(ls) do begin
case ls[li] of
'0'..'9': hasdigit:=true;
',': if Commas=0 then inc(Commas) else delete(ls1,li,1);
'-': if li>1 then delete(ls1,li,1);
else
delete(ls1,li,1); // remove wrong charcaters
end;
end;
if hasdigit then text:=ls1 else text:=ls+'0';
SelStart:=lk; //restore cursor pos
end;
end;
|