Thema: Delphi paste abfangen

Einzelnen Beitrag anzeigen

eyeless

Registriert seit: 12. Aug 2005
49 Beiträge
 
#9

Re: paste abfangen

  Alt 17. Aug 2005, 22:20
hmm, wohl zu früh gefreut, passiert nix ...

hier mal die komponente:

Delphi-Quellcode:
unit JEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, stdctrls, clipbrd;

type
  TPasteNotifyEvent = procedure(Sender: TObject; Text: string) of object;
  
type
  TJEdit = class(TEdit)
  private
    { Private declarations }
    FOnPaste: TPasteNotifyEvent;
    procedure WMPaste(var Message: TMessage); message WM_COPY;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
    property OnPaste: TPasteNotifyEvent read FOnPaste write FOnPaste;
  end;

procedure Register;

implementation

uses Variants;

constructor TJEdit.Create(AOwner: TComponent);
begin
inherited create(AOwner);
BorderStyle := bsNone;
BevelKind := bkTile;
end;

procedure TJEdit.WMPaste(var Message: TMessage);
var
  Accept: Boolean;
  Handle: THandle;
  CText: string;
  LText: string;
  AText: string;
begin
  if IsClipboardFormatAvailable(CF_TEXT) then
  begin
    try
      OpenClipBoard(Self.Handle);
      Handle := GetClipboardData(CF_TEXT);
      if Handle = 0 then
        Exit;
      CText := StrPas(GlobalLock(Handle));
      GlobalUnlock(Handle);
      Accept := True;
      if Assigned(FOnPaste) then
        FOnPaste(Self, CText);
      if not Accept then
        Exit;
      LText := '';
      if SelStart > 0 then
        LText := Copy(Text, 1, SelStart);
      LText := LText + CText;
      AText := '';
      if (SelStart + 1) < Length(Text) then
        AText := Copy(Text, SelStart + SelLength + 1, Length(Text) - SelStart + SelLength + 1);
      Text := LText + AText;
    finally
      CloseClipBoard;
    end;
  end;
end;


procedure Register;
begin
  RegisterComponents('selfmade', [TJEdit]);
end;

end.
wenn ich dann in der anwendung im onpaste showmessage(text) mache passiert nichts! NIX!

warum?

mfg, eyeless
  Mit Zitat antworten Zitat