Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change character Insert / Overwrite in richedit?

Posted on 1997-05-04
7
Medium Priority
?
1,491 Views
Last Modified: 2013-11-22
Unlike memo's, richedit components handle switching between Insert and Overwrite modes. I would like to know how to progamaticaly detect which mode it is in and also set the mode.

I took a pot shot and tried using
SendMessage( form.Handle, WM_CHAR, VK_INSERT, 24 );
to toggle Insert/Overwrite but no joy.

Thanks in advance
--------------
Jeremy Thomas
mailto:Jeremy.Thomas@netau1.alcatel.com.au

To clarify my situation, I have a made a tabbed multipage editor similar to the one found in the Delphi IDE, along the bottom is a panel which show various things like cursor position, caplocks state etc.. I recently added an Insert / Overwrite status using getkeystate(VK_INSERT) = 1 and SetKeyboardState to set the virtual keys. This works fine except the state it shows bears no relation to the state inside a particular richedit. Furthermore if I press insert while a particular richedit has focus the Insert/Overwrite state for that richedit changes but none of the other ones do. You can imagine how this might piss the users off. In Delphi editor I notice all the windows stay in sync.

My guess is that the richedits each have there own variable which dictates their Insert / Overwrite state and that Borland decided not to wrap this variable in the Trichedit component.
0
Comment
Question by:dufus050497
[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
  • 2
7 Comments
 
LVL 4

Expert Comment

by:StevenB
ID: 1335901
Use GetKeyState to read the virtual keys, i.e. for Insert button:

  if getkeystate(VK_INSERT) = 1 then ...

Use SetKeyboardState to set the virtual keys.

0
 

Author Comment

by:dufus050497
ID: 1335902
Edited text of question
0
 

Author Comment

by:dufus050497
ID: 1335903
You have been succesful at getting a Richedit to change its Insert / Overwrite state? I had already tried that and it didnt work.

To clarify my situation, I have a made a tabbed multipage editor similar to the one found in the Delphi IDE, along the bottom is a panel which show various things like cursor position, caplocks state etc.. I recently added an Insert / Overwrite status using getkeystate(VK_INSERT) = 1 and SetKeyboardState to set the virtual keys. This works fine except the state it shows bears no relation to the state inside a particular richedit. Furthermore if I press insert while a particular richedit has focus the Insert/Overwrite state for that richedit changes but none of the other ones do. You can imagine how this might piss the users off. In Delphi editor I notice all the windows stay in sync.

My guess is that the richedits each have there own variable which dictates their Insert / Overwrite state and that Borland decided not to wrap this variable in the Trichedit component.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:StevenB
ID: 1335904
 Sorry my answer was not what you were looking for. I misunderstood your question, thinking you were having difficulty detecting key presses. I've played with the Rich Edit and run into the same problems that you have. The TRichEdit component is in my opinion not very good. There are many problems with it and this is another on to add to the list. My recomendation is that you search out a better rich edit component on the web, or write your own. I wish you success.
 
  Steven.
0
 
LVL 3

Accepted Solution

by:
sperling earned 400 total points
ID: 1335905
type
  TInsRichEdit = class (TRichEdit)
  protected
    FInsertMode : BOOLEAN;
    procedure WMKeyDown (var message : TMessage); message WM_KEYDOWN;
    procedure SetInsertMode (value : BOOLEAN);
  public
    constructor Create (AOwner : TComponent); override;
    property  InsertMode : BOOLEAN read FInsertMode write SetInsertMode;
  end;

implementation

procedure TInsRichEdit.WMKeyDown (var message : TMessage);
begin
  if (message.wParam = VK_INSERT)
    then FInsertMode := not FInsertMode;
  inherited;
end;

procedure TInsRichEdit.SetInsertMode (value : BOOLEAN);
begin
  SendMessage(Handle, WM_KEYDOWN, VK_INSERT, 0);
  SendMessage(Handle, WM_KEYUP, VK_INSERT, 0);
end;

constructor TInsRichEdit.Create (AOwner : TComponent);
begin
  inherited Create(AOwner);
  FInsertMode := TRUE;
end;

Try using this class instead of TRichEdit.

TRichEdit is just an wrapper around the RichEdit windows class. Therefore, there's not even an internal variable in TRichEdit which knows what state it is in. The TInsRichEdit class will fix this, assuming RichEdits always are in Insert mode when created. (I'm not sure, but I do believe so).

Apart from that, I'll agree with Steven, the TRichEdit is not a very good implementation of richedits. Good enough for simple text formatting, but for your purpose I'll suggest you buy a better one. I know there exist a few shareware/commercial full-blown richedit's for Delphi, but I don't remember which and where...


Regards,

Erik.

0
 

Author Comment

by:dufus050497
ID: 1335906
Thanks Erik, that did the trick.

I needed to make a few mods for my purposes
1: Your SetInsertMode was infact a toggle, Ive fixed that.
2 :Ive set the KeyBoardState to reflect the state of the RichEdit
3: My form needs to know when ins is pressed to keep all the editior windows in synch so Ive added a kludge or two to do that.


public
     InsertNotifier:HWND;

const
  GeneratedVK_INSERT=32;

procedure TSRichEdit.WMKeyDown (var message : TMessage);
 var
   KeyBoardState: TKeyBoardState;
begin
  if (message.wParam = VK_INSERT) then begin
    FInsertMode := not FInsertMode;
    GetKeyboardState(KeyBoardState);
    if FInsertMode then
      KeyBoardState[VK_INSERT] := 1
    else
      KeyBoardState[VK_INSERT] := 0;
    SetKeyboardState(KeyBoardState);
    if (InsertNotifier<>0) and (message.lParam <> GeneratedVK_INSERT) then
     SendMessage(InsertNotifier, WM_KEYUP, VK_INSERT, 0);
  end;
  inherited;
end;

procedure TSRichEdit.SetInsertMode (value : BOOLEAN);
begin
  if FInsertMode <> value then begin
    SendMessage(Handle, WM_KEYDOWN, VK_INSERT, GeneratedVK_INSERT);
    SendMessage(Handle, WM_KEYUP, VK_INSERT, GeneratedVK_INSERT);
  end;
end;
0
 
LVL 3

Expert Comment

by:sperling
ID: 1335907
> 1: Your SetInsertMode was infact a toggle, Ive fixed that.

Ooops. That's what I get for not testing my code....

Regards,

Erik.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 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