Solved

insert/overwrite in Tmemo

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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