Solved

Making Edit1 always replace, and not insert

Posted on 2001-07-26
12
320 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 88
Help on project with Soap 10 54
Delphi Form ownership 4 90
Error E2158 compiling with Delphi XE10 Seattle 2 100
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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