Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to set a TEdit or TMemo to overwrite instead of insert Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
63
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to set a TEdit or TMemo to overwrite instead of insert

Answer:

Solve 1:

You have to fake it because the control does not natively support overtype mode. 
Provide overtype capability for edits and memos:
1   
2   procedure TScratchMain.Memo1KeyPress(Sender: TObject; var Key: Char);
3   begin
4     if (Sender is TCustomEdit) and Odd(GetKeyState(VK_INSERT)) then
5       with TCustomEdit(Sender) do
6         if SelLength = 0 then
7           case Key of
8             ' '..#126, #128..#255:
9               begin
10                SelLength := 1;
11                if (SelLength > 0) and (SelText[1] = #13) then
12                  SelLength := 2;
13              end;
14          end;
15  end;


With this handler the control will start out in insert mode since the state of 
VK_INSERT is not toggled by default. Pressing it once will toggle the key and put 
the control in overtype mode. If you want it to start out in overtype, use "not 
Odd(...)" in the If statement.

Solve 2:

I managed to simulate it by doing this (you need to declare the FOverwrite: boolean 
somewhere in the form):
16  
17  procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
18  type
19    TSmallPoint = packed record
20      case integer of
21        0: (x, y: Smallint);
22        1: (long: integer);
23    end;
24  var
25    CaretPos: TPoint;
26    sCaretPos: TSmallPoint;
27  begin
28    if (FOverwrite) and (Edit1.SelLength = 0) then
29    begin
30      GetCaretPos(CaretPos);
31      sCaretPos.x := CaretPos.x;
32      sCaretPos.y := CaretPos.y;
33      Edit1.SelStart := SendMessage(Edit1.Handle, EM_CHARFROMPOS, 0, sCaretPos.long);
34      Edit1.SelLength := 1;
35      Edit1.SelText := Key;
36      Key := #0;
37    end;
38  end;
39  
40  procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
41  begin
42    case Key of
43      VK_INSERT: FOverwrite := not FOverwrite;
44    end;
45  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC