I'm trying to use EM_SETTEXTMODE on a RichEdit control in Delphi 7.
Just create a new project, add a TRichEdit control and a TButton control and add the following code to the button's click handler:
SendMessage(RichEdit1.Handle, WM_SETTEXT, 0, LPARAM(PChar('')));
Button1.Caption := IntToStr(SendMessage(RichEdit1.Handle, EM_GETTEXTMODE, 0, 0));
Button1.Caption := Button1.Caption + ' ' + IntToStr(SendMessage(RichEdit1.Handle, EM_SETTEXTMODE, TM_PLAINTEXT, 0));
Button1.Caption := Button1.Caption + ' ' + IntToStr(SendMessage(RichEdit1.Handle, EM_GETTEXTMODE, 0, 0));
The button's caption is set to 38 0 38 after clicking on the button, meaning the text mode didn't change at all - initially it was 38 (TM_RICHTEXT or TM_SINGLELEVELUNDO or TM_MULTICODEPAGE), then SETTEXTMODE was successful (0) but even after that it is still 38.
The RichEdit's text is cleared before using EM_SETTEXTMODE as suggested by the documentation.
I've tried setting different values with EM_SETTEXTMODE and it always stays 38.
I noticed that EM_SETTEXTMODE always returns 0 (success) even if the RichEdit control contains text before calling it.
I tried using RichEdit1.Perform instead of SendMessage - no difference.
I've found several threads in various forums on this issue, and it wasn't resolved in any of them.
Any idea why isn't this working?
