Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#8

Re: Onclick und rechte Maustaste!

  Alt 31. Dez 2005, 12:13
Hallo,
ich würde im protected Abschnitt die Methoden DoLeftMouseButtonDown und DoRightMouseButtonDown einführen. Das vereinfacht das Überschreiben der Events in Nachfahren erheblich.

Delphi-Quellcode:
unit AdvMainMenu;

interface

uses
  Windows, Menus, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TAdvMainMenu = class(TMainMenu)
  private
    { Private-Deklarationen }
    FOnLMBClicked: TNotifyEvent;
    FOnRMBClicked: TNotifyEvent;
    procedure LeftMouseButtonDown(var Msg : TMouseInput); message WM_LBUTTONDOWN;
    procedure RightMouseButtonDown(var Msg : TMouseInput); message WM_RBUTTONDOWN;
  protected
    { Protected-Deklarationen }
    procedure DoLeftMouseButtonDown(var Msg : TMouseInput); dynamic;
    procedure DoRightMouseButtonDown(var Msg : TMouseInput); dynamic;
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
   published
    { Published-Deklarationen }
     property OnLMBClick: TNotifyEvent read FOnLMBClicked write FOnLMBClick;
     property OnRMBClick: TNotifyEvent read FOnRMBClicked write FOnRMBClick;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TAdvMainMenu]);
end;

constructor TAdvMainMenu.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor TAdvMainMenu.Destroy;
begin
  inherited Destroy;
end;

procedure TAdvMainMenu.DoLeftMouseButtonDown(var Msg: TMouseInput);
begin
  If Assigned(FOnLMBClicked) then
    FOnLMBClicked(Self);
end;

procedure TAdvMainMenu.DoRightMouseButtonDown(var Msg: TMouseInput);
begin
  If Assigned(FOnRMBClicked) then
    FOnRMBClicked(Self);
end;

procedure TAdvMainMenu.LeftMouseButtonDown(var Msg: TMouseInput);
begin
  DoLeftMouseButtonDown(Msg);
end;

procedure TAdvMainMenu.RightMouseButtonDown(var Msg: TMouseInput);
begin
  DoRightMouseButtonDown(Msg);
end;

end.
I come from outer space to save the human race
  Mit Zitat antworten Zitat