Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pasting multiple lines into a TEdit

With respect to a TEdit component, would it be possible for the component to handle a multi-line paste from the Windows Clipboard by converting line breaks to spaces?

In other words, if the following data was on the Windows Clipboard:

Hello
world
!

...and the user placed their cursor in a TEdit then pressed CTRL+V, would it be possible to have the TEdit display the input as:

Hello world !

like image 357
user1527613 Avatar asked Jun 21 '13 03:06

user1527613


1 Answers

You'd need to subclass the TEdit using an interposer 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.
like image 117
Ken White Avatar answered Sep 21 '22 10:09

Ken White