Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to intercept Paste within a TMemo 1

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi folks. I'm in a good mood today.
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.
 
maybe you can add this to the FAQ pages?

anyway, a good tip always deserves a star...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Hi there...
Your wish is granted, FAQ added.... :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top