tooraj30
Programmer
- Jul 29, 2012
- 2
first i do apologize for my bad english so...
I want my numbers to be three digits separated by three digits in Tedit when user type number in Tedit.
like this :
1234 ---> 1,234
12345 ---> 12,345
1234567890 ---> 1,234,567,890
i use this code and its good but not enough.
in Tedit.onchange :
edit1.text:=seperate(edit1.text);
edit1.selstart:=length(edit1.text);
and seperate function :
function seperate(s:string):string;
var
i:integer;
s1:string;
begin
s1:='';
for i:=1 to length(s) do if copy(s,i,1)<>',' then s1:=s1+copy(s,i,1);
{for delete exist seperator from digit}
if length(s1)<4 then seperate:=s;
if length(s1)=4 then seperate:=copy(s1,1,1)+','+copy(s1,2,3);
if length(s1)=5 then seperate:=copy(s1,1,2)+','+copy(s1,3,3);
if length(s1)=6 then seperate:=copy(s1,1,3)+','+copy(s1,4,3);
if length(s1)=7 then seperate:=copy(s1,1,1)+','+copy(s1,2,3)+copy(s1,5,3);
if length(s1)=8 then seperate:=copy(s1,1,2)+','+copy(s1,3,3)+copy(s1,6,3);
if length(s1)=9 then seperate:=copy(s1,1,3)+','+copy(s1,4,3)+copy(s1,7,3);
...
{etc. on how many digit length that user want it}
end;
now if you write digit simple or delete the last digit by bkspace or delete the code is do right but if you want to delete on of the digit that is in between of digit after the delete curser jump to the end of line becuse of selstart order it means in 123,456,789 if you move the curser behind the 4 and delete it the curser jump to the end but i want to stop the curser in its location down the 5 digit In the above example.
Can someone help?
I want my numbers to be three digits separated by three digits in Tedit when user type number in Tedit.
like this :
1234 ---> 1,234
12345 ---> 12,345
1234567890 ---> 1,234,567,890
i use this code and its good but not enough.
in Tedit.onchange :
edit1.text:=seperate(edit1.text);
edit1.selstart:=length(edit1.text);
and seperate function :
function seperate(s:string):string;
var
i:integer;
s1:string;
begin
s1:='';
for i:=1 to length(s) do if copy(s,i,1)<>',' then s1:=s1+copy(s,i,1);
{for delete exist seperator from digit}
if length(s1)<4 then seperate:=s;
if length(s1)=4 then seperate:=copy(s1,1,1)+','+copy(s1,2,3);
if length(s1)=5 then seperate:=copy(s1,1,2)+','+copy(s1,3,3);
if length(s1)=6 then seperate:=copy(s1,1,3)+','+copy(s1,4,3);
if length(s1)=7 then seperate:=copy(s1,1,1)+','+copy(s1,2,3)+copy(s1,5,3);
if length(s1)=8 then seperate:=copy(s1,1,2)+','+copy(s1,3,3)+copy(s1,6,3);
if length(s1)=9 then seperate:=copy(s1,1,3)+','+copy(s1,4,3)+copy(s1,7,3);
...
{etc. on how many digit length that user want it}
end;
now if you write digit simple or delete the last digit by bkspace or delete the code is do right but if you want to delete on of the digit that is in between of digit after the delete curser jump to the end of line becuse of selstart order it means in 123,456,789 if you move the curser behind the 4 and delete it the curser jump to the end but i want to stop the curser in its location down the 5 digit In the above example.
Can someone help?