Solved

insert/overwrite in Tmemo

Posted on 2000-05-08
5
610 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
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ronvp
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
look s interessting, as soon as i get a bit of time, i'll look into it.

 
0
 

Author Comment

by:hatecapletters
Comment Utility
sorry for the delay :-)

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now