Hi folks. I'm in a good mood today.
This is how to intercept cut'n'paste in a TMemo.
Enjoy......
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
This is how to intercept cut'n'paste in a TMemo.
Enjoy......
Code:
unit MemoEx;
interface
uses
ClipBrd, Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TStringEvent = procedure(Sender: TObject; var s: String) of object;
TMemoEx = class(TMemo)
private
FOnBeforePaste: TStringEvent;
FOnAfterPaste: TNotifyEvent;
procedure WMPaste(var Message: TMessage); message WM_PASTE;
protected
public
published
property OnBeforePaste: TStringEvent read FOnBeforePaste write FOnBeforePaste;
property OnAfterPaste: TNotifyEvent read FOnAfterPaste write FOnAfterPaste;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Andreas Nordlund', [TMemoEx]);
end;
{ TMemoEx }
procedure TMemoEx.WMPaste(var Message: TMessage);
var
strClpText: String;
begin
if Assigned(FOnBeforePaste) and Clipboard.HasFormat(CF_TEXT) then
begin
strClpText := ClipBoard.AsText;
FOnBeforePaste(self, strClpText);
Clipboard.Clear;
Clipboard.AsText := strClpText;
end;
inherited;
if Assigned(FOnAfterPaste) then
FOnAfterPaste(self);
end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.