Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Making Edit1 always replace, and not insert

Posted on 2001-07-26
12
Medium Priority
?
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 400 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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