Einzelnen Beitrag anzeigen

SoGraDEs

Registriert seit: 12. Mär 2005
Ort: Bremen
28 Beiträge
 
Delphi XE7 Professional
 
#5

Re: Events einer Komponenete in einer NEUEN ererbten Kompone

  Alt 10. Mai 2007, 12:42
Hallo Der Unwissende,
in diesem Bereich habe ich deutliche Verständnisprobleme,
Wissensdefizite.
Brauch also noch ein paar Tips.
Ich habe Deinen Vorschlag umgesetzt (siehe Code)

In dem Programm wird bei dem die Procdure Click vom TPanel
überschrieben, damit ein Click auf das Panel eine Änderung der
BevelOuter hervorruft.
Wenn ich jetzt ein (oder mehrere) Label auf dem Panel habe, und
mit der Mouse(links) auf das/die Label clicke, dann soll das GLEICHE
passieren, als wenn ich auf das Panel geclicked hätte.

Wenn ich Deinen Vorschlag richtig (was nicht sicher ist) verstanden
habe, dann wird dabei aber der Panel Click-Event auf den Label Click-Event
gelegt ?? Oder habe icch es überhaupt nicht verstanden ??
Wenn ich den beiliegenden Code verwende, regiert die Procedure
TMyPanel.Click wenn ich auf das Panel cklicke aber nicht, wenn ich auf das
Label clicke.
Ich würde mich sehr freuen, wenn ich Hilfe bekomme.

Hallo Cruiser,
ich habe Deine Version auch getestet, aber da bekomme ich eine ein Problem
mit OnLabelClick , weil das nicht bekannt ist.
Wie hätte ich es deklarieren sollen ?
Und habe ich dann nicht auch das Problem, dass das Panel - Event auf das Label-Event
zugewiesen wird ? Ich will aber meine Procdure Click vom TPanel ausgeführt haben.

Hier der Code nach dem Vorschlag von Der Unwissende :

Delphi-Quellcode:
unit Switch;

interface

uses
  SysUtils , Classes, Controls, ExtCtrls,
  StdCtrls ,
  Dialogs ,
  Graphics ;
   {
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Switch
   }

type
  TMyPanel = class(TPanel)
  private { Private-Deklarationen }
   bDown : boolean ;
   L1 : TLabel ;
   L2 : TLabel ;
   L3 : TLabel ;

   xL1_Top : integer ;
   xL1_Left : integer ;
   xL1_Width : integer ;
   xL1_Height : integer ;
   xL1_Color : TColor ;
   xL1_FontName : TFontName ;
   xL1_FontColor : TColor ;
   xL1_FontSize : integer ;
   xL1_Caption : TCaption ;

   constructor Create(AOwner: TComponent) ; override ;
   destructor Destroy ; override ;

   procedure Click ; override ;
   procedure SetState(bValue : boolean );
   procedure Set_L1_Color(yL1_Color : TColor );
   procedure Set_L1_FontColor(yL1_FontColor : TColor );

   procedure MyLabelOnClick(Sender: TObject);

  protected { Protected-Deklarationen }

  public { Public-Deklarationen }


  published { Published-Deklarationen }
  property L1_Top : integer read xL1_Top write xL1_Top ;
  property L1_Left : integer read xL1_Left write xL1_Left ;
  property L1_Width : integer read xL1_Width write xL1_Width ;
  property L1_Height : integer read xL1_Height write xL1_Height ;
  property L1_Color : TColor read xL1_Color write Set_L1_Color ; //xL1_Color ;
  property L1_FontName : TFontName read xL1_FontName write xL1_FontName ;
  property L1_FontColor : TColor read xL1_FontColor write Set_L1_FontColor ; //xL1_FontColor ;
  property L1_FontSize : integer read xL1_FontSize write xL1_FontSize ;
  property L1_Caption : TCaption read xL1_Caption write xL1_Caption ;

  property Down : boolean read bDown write SetState ;

  end;

procedure Register;


implementation

procedure Register;
begin
  RegisterComponents('Dirk', [TMyPanel]);
end;

constructor TMyPanel.Create(AOwner: TComponent);
begin
 inherited create(AOwner) ;

 L1 := TLabel.Create(self);
 L1.Parent := self ;
 L1.Visible := TRUE ;
 L1.OnClick := Self.MyLabelOnClick ;

 //Self.Onclick := L1.OnClick ;

 xL1_Left := 25 ;
 xL1_Top := 5 ;
 xL1_Height := 17 ;
 xL1_Width := 75 ;
 xL1_Color := clWhite ;
 xL1_FontName := 'Arial'       ;
 xL1_FontColor := clRed ;
 xL1_FontSize := 8 ;
 xL1_Caption := 'L1 = Label1' ;

 L1.AutoSize := FALSE ; // Festgeschrieben nicht änderbar !!

 L1.Left := xL1_Left ;
 L1.Top := xL1_Top ;
 L1.Height := xL1_Height ;
 L1.Width := xL1_Width ;
 L1.Color := xL1_Color ;
 L1.Font.Name := xL1_FontName ;
 L1.Font.Color := xL1_FontColor ;
 L1.Font.Size := xL1_FontSize ;
 L1.Caption := xL1_Caption ;

 //==================================
 L2 := TLabel.Create(self);
 L2.Parent := self ;
 L2.Visible := TRUE ;

 L2.Left := 30 ;
 L2.Top := 30 ;
 L2.Height := 10 ;
 L2.Width := 10 ;
 L2.Caption := 'y2'  ;

end;

procedure TMyPanel.MyLabelOnClick;
begin
   if Assigned(Self.OnClick) then
   begin
      self.OnClick(self) ;
   end;
end;



destructor TMyPanel.Destroy ;
begin
  L1.Free ;
  L2.Free ;
  L3.Free ;

  inherited destroy ;
end;



procedure TMyPanel.Set_L1_Color(yL1_Color : TColor );
begin
  xL1_Color := yL1_Color ; L1.Color := xL1_Color ;
end;
procedure TMyPanel.Set_L1_FontColor(yL1_FontColor : TColor );
begin
  xL1_FontColor := yL1_FontColor ; L1.Font.Color := xL1_FontColor ;
end;


procedure TMyPanel.Click ;
begin
  if BevelOuter = bvRaised then
    begin
    BevelOuter := bvLowered ;
    bDown := TRUE ;
    end
  else
    begin
    BevelOuter := bvRaised ;
    bDown := FALSE ;
    end;

  inherited Click ;
end;

procedure TMyPanel.SetState(bValue: Boolean);
begin
  if bValue = TRUE then
    begin
    bDown := TRUE ;
    BevelOuter := bvLowered ;
    end
    else
    begin
    bDown := FALSE ;
    BevelOuter := bvRaised ;
    end;
end;



end.
Viele Grüße aus Bremen
  Mit Zitat antworten Zitat