AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Event innerhalb einer Klasse umleiten

Ein Thema von annotar · begonnen am 24. Mär 2013 · letzter Beitrag vom 25. Mär 2013
 
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#4

AW: Event innerhalb einer Klasse umleiten

  Alt 24. Mär 2013, 23:16
aufs mindeste beschränkt....

Delphi-Quellcode:
unit lal;

interface

uses
  Windows, SysUtils, Variants, Classes, Graphics, Controls, ExtCtrls, StdCtrls;

type

  TMyPanel = class(TPanel)
  private
    FmyEdit: Tedit;
    function GetEvent: TKeyPressEvent;
    procedure SetEvent(const Value: TKeyPressEvent);
  public
    constructor Create(AOwner: TComponent); override;

  published
    property OnMyKeyPress: TKeyPressEvent read GetEvent Write SetEvent;
  end;

implementation

{ TMyPanel }

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
  Width := 100;
  Height := 50;
  FmyEdit := Tedit.Create(self);
  FmyEdit.Parent := self;
  FmyEdit.Width := 50;
end;

function TMyPanel.GetEvent: TKeyPressEvent;
begin
  Result := FmyEdit.OnKeyPress;
end;

procedure TMyPanel.SetEvent(const Value: TKeyPressEvent);
begin
  FmyEdit.OnKeyPress := Value;
end;

end.
Anwendungsbeispiel

Delphi-Quellcode:
implementation
uses lal;
{$R *.dfm}
procedure TForm4.AKeyPressEvent(Sender: TObject; var Key: Char);
begin
   Caption := Caption + Key;
end;

procedure TForm4.Button1Click(Sender: TObject);
begin
  With TMyPanel.Create(self) do
    begin
      Parent := self;
      OnMyKeyPress := AKeyPressEvent;
    end;
end;
Da ich nicht sicher bin was genau Du suchst hier eine Version mit einer zusätzlichen internen Behandlung ...

Delphi-Quellcode:
unit lal;

interface

uses
  Windows, SysUtils, Variants, Classes, Graphics, Controls, ExtCtrls, StdCtrls;

type

  TMyPanel = class(TPanel)
  private
    FmyEdit: Tedit;
    FKeyPressEvent: TKeyPressEvent;
    procedure AInternalKeyPressEvent(Sender: TObject; var Key: Char);
  public
    constructor Create(AOwner: TComponent); override;

  published

    property OnMyKeyPress: TKeyPressEvent read FKeyPressEvent Write FKeyPressEvent;
  end;

implementation

{ TMyPanel }

procedure TMyPanel.AInternalKeyPressEvent(Sender: TObject; var Key: Char);
begin
  if Key='Athen Key := 'B';

  if assigned(FKeyPressEvent) then FKeyPressEvent(Self,Key);

end;

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
  Width := 100;
  Height := 50;
  FmyEdit := Tedit.Create(self);
  FmyEdit.Parent := self;
  FmyEdit.Width := 50;
  FmyEdit.OnKeyPress := AInternalKeyPressEvent;
end;



end.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)

Geändert von Bummi (24. Mär 2013 um 23:51 Uhr) Grund: Erweiterung, wg. möglicherweise missverstandener Anforderung
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:47 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz