Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to now where is the curser location in Tedit

Status
Not open for further replies.

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?
 
There are formatting functions that will do this for you. Are you working through this problem to learn something?
 
hi
I do not know what you mean is the function
delphi library function? or forigen pakage?
Please specify what exactly function you mean
and last yes i want to control the curser in Tedit for several use
 
As to your question:

Where is the cursor in a TEdit Component..

Edit1.SelStart;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top