Insert multiple lines in TEdit

Regarding the TEdit component, can the component handle multi-line pastes from the Windows clipboard by converting line breaks to spaces?

In other words, if the following data were in the Windows clipboard:

Hello world ! 

... and the user placed his cursor in TEdit, and then pressed CTRL + V, is it possible for TEdit to display the input as:

Hello World!

+7
source share
1 answer

You need to subclass TEdit using the middleware class and add a handler for the WM_PASTE message:

 unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, adsdata, adsfunc, adstable; type TEdit= class(StdCtrls.TEdit) procedure WMPaste(var Msg: TWMPaste); message WM_PASTE; end; type TForm3 = class(TForm) AdsTable1: TAdsTable; Edit1: TEdit; private { Private declarations } public { Public declarations } end; var Form3: TForm3; implementation {$R *.dfm} uses Clipbrd; { TEdit } procedure TEdit.WMPaste(var Msg: TWMPaste); var TempTxt: string; begin TempTxt := Clipboard.AsText; TempTxt := StringReplace(TempTxt, #13#10, #32, [rfReplaceAll]); Text := TempTxt; end; end. 
+12
source

All Articles