Solved

Making Edit1 always replace, and not insert

Posted on 2001-07-26
12
322 Views
Last Modified: 2010-04-06
Hi.  Is there an easy way to program the Edit1 component so that everything I type into it, *always* gets replaced? (i.e it must replace the character at the correct position with the new one, and not insert it)

I tried thinking of an easy solution but couldn't come up with one.  I thought of KeyPerform and OnKeyPressed, but it doesn't give you a position as parameter, only the key pressed. ;(

Any suggestions would be appreciated, thanks
Lmoen
0
Comment
Question by:Lmoen
12 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 6324494
This might be useful for you.  The following code will determine the position of the caret in the edit control (it is stored in CPos).  This value should be the index after the character that was just inserted.  You can then use that to manipulate the text in the edit control.

This snippet of code will display the value in CPos in the Form caption.


procedure TForm1.Edit1Change(Sender: TObject);
var
    LPos, CPos :integer;
begin
    Lpos := SendMessage(Edit1.Handle,EM_LINEFROMCHAR,Edit1.SelStart,0);
    Cpos := SendMessage(Edit1.Handle,EM_LINEINDEX,Lpos,0);
    CPos := Edit1.SelStart-CPos;

    //CPos now contains the index of the caret

    Caption := IntToStr(CPos);

end;
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6324501
Couldn't you grab the value of edit1.text with the onchange event, store it as a string, error check as needed, etc?
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6324511
Note:

the above works on a Memo as well.  If you are only using an Edit, which is only one line, you can omit the Lpos := ...

procedure TForm1.Edit1Change(Sender: TObject);
var
   CPos :integer;
begin
   Cpos := SendMessage(Edit1.Handle,EM_LINEINDEX,0,0);
   CPos := Edit1.SelStart-CPos;

   //CPos now contains the index of the caret

   Caption := IntToStr(CPos);

end;

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6325547
simple use this

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key in [VK_LEFT,VK_RIGHT] then //maybe morekeys
    //nothing
  else
    edit1.sellength := 1;
end;

meikl ;-)
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6325610
That's pretty clever =)
0
 

Author Comment

by:Lmoen
ID: 6325684
Thanks for the help
Appreciated
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6325688
seems, i was a bit too late :-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6325755
oops, wrong symbol
:-)->:-(

;-)
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6325768
LOL
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6325775
 The early dog gets the meat.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6325782
:-) yup, scrap
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6325787
i have a corner in my eyes :-)

yup, steven
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question