Solved

insert/overwrite in Tmemo

Posted on 2000-05-08
5
636 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 100 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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