?
Solved

insert/overwrite in Tmemo

Posted on 2000-05-08
5
Medium Priority
?
648 Views
Last Modified: 2010-04-04
I need to know how to set up a TMemo, so that i can either insert or overwrite the text, depending on what the user chooses. And if someone knows, how come borland haven't made that option available, considering that they use it in the IDE ?? ;-)
0
Comment
Question by:hatecapletters
[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
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ronvp
ID: 2791404
Allthough not difficult There is no buildin way to do this with a standard memo control. So if you do want to use it, you would need to write a onkeydown event handler, and when a key is pressed, check if the user wants to overwrite and then delete the character immediately after the cursor. To do this proparly, you would also need to have a method to correctly handle a paste 0peration of multiple characters. i.e.: Delete from cursor position the number of characters that is on the clipboard before the paste operation is executed.

I do have a much easier method and that is to use a TRichEdit control which has all the functionality you want build in. You would not have to do anything else then to replace the Tmemo with a TRichEdit..
0
 

Author Comment

by:hatecapletters
ID: 2791663
i was thinking about that, but i'm using a colormemo, with elaborate colorcoding, and i'm not really reasy to re-write a trichedit to do that yet.
0
 
LVL 1

Accepted Solution

by:
ronvp earned 400 total points
ID: 2792048
Below is the code you need to add in your memo OnKeyPress handler
It will check if the overwrite mode is active and then checks if the esc or backspace keys are pressed if. It then call the windows sendmessage function to simulate a key press of the delete key.

   procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
   //Do not process Escape and Backspace keys
   If (Lo(GetKeystate(VK_INSERT)) = 1) and  Not(Ord(Key) in [8, 27]) then
         SendMessage(Memo1.Handle, WM_KEYDOWN, VK_DELETE, 1);
end;

You may want to check if there are more keys besides the esc and backspace keys that should not activate the call to sendmessage.. Also, if you do have onkeydown handler allready, you may need to provide some extra code to stop the above routine calling it..
0
 

Author Comment

by:hatecapletters
ID: 2803460
look s interessting, as soon as i get a bit of time, i'll look into it.

 
0
 

Author Comment

by:hatecapletters
ID: 2818735
sorry for the delay :-)

i had to work a bit on it, but you sent me in the right direction, thanks :-)
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

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