Autor Beitrag
mtm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

Windows 10 Pro 64 Bit
Delphi XE 6
BeitragVerfasst: Di 14.09.10 22:59 
Hallöle zusammen.

Ich schreibe gerade zu Probierzwecken eine Komponente (von TCustomControl abgeleitet). Ich habe aber ein Problem mit dem Abfangen des DblClick-Events.
In ControlStyle habe ich auch schon "ssDouble" hinzugefügt aber trotzdem...keine Reaktion.

Kennt jemand das Problem und vor allem, hat es schon jemand gelöst ?

Danke im Voraus
mtm
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 15.09.10 09:29 
ich weiß nicht recht was bei Dir nicht funktioniert.
Folgender Code funtioniert bei mir...

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
unit Unit5;

interface

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

type
  TMy=Class(TCustomControl)
  End;
  TForm5 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure TestDblClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.Button1Click(Sender: TObject);
var
  my:TMy;
begin
   my:=TMy.Create(Self);
   my.Parent := self;
   my.Color := clBlue;
   my.SetBounds(10,10,200,200);
   my.OnDblClick :=TestDblClick;
end;

procedure TForm5.TestDblClick(Sender: TObject);
begin
     Showmessage('Test');
end;

end
mtm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

Windows 10 Pro 64 Bit
Delphi XE 6
BeitragVerfasst: Mi 15.09.10 14:34 
So, wie bei Deinem Beispiel funktioniert das bei mir auch. Das Problem besteht aber darin, dass ich auch einen normalen Click abfangen möchte. Jetzt tritt ausschließlich der normale Click auf, zum Doppelclick kommt es gar nicht. Wie kann man das umgehen.

Hier mal der Code :
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
unit Tester;

interface

uses ExtCtrls, Types, Graphics, Controls, Classes;

type TClick = procedure(Sender: TObject) of object;
type TDblClick = procedure(Sender: TObject) of object;

type
  test = class(TCustomControl)
    private
      FClick: TClick;
      FDblClick: TDblClick;

      procedure Click(Sender: TObject);
      procedure DoppelClick(Sender: TObject);
    protected
      procedure Paint;override;
    public
      constructor Create(AOwner: TComponent);override;
    published
      property onClicked:TClick read FClick write FClick;
      property onDblClicked:TDblClick read FDblClick write FDblClick;
  end;

implementation

constructor test.Create(AOwner: TComponent);
begin
  inherited;
  OnClick := Click;
  OnDblClick := DoppelClick;
end;

procedure test.Paint;
var
  rt:TRect;
begin
  rt := Bounds(0,0,Self.Width,Self.Height);
  with Canvas do begin
    Brush.Color := clBtnFace;
    FillRect(rt);
    Brush.Color := clWhite;
    Pen.Color := clBlack;
    Rectangle(rt);
  end;
end;

procedure test.Click(Sender: TObject);
begin
  if Assigned(onClicked) then onClicked(Sender);
end;

procedure test.DoppelClick(Sender: TObject);
begin
  if Assigned(onDblClicked) then onDblClicked(Sender);
end;

end.


EDIT : Wenn ich den Click-Teil weglasse wird der Doppelclick erkannt.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 15.09.10 14:43 
Ich fürchte ich verstehe Dein Problem nicht richtig???

TCustomControl ist von TWinControl abgeleited und kennt OnClick bereits
oder fehlt Dir nur die Darstellung im Objektinspektor, dann brauchst Du die public gesetzte Property nur published zu setzen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  TMy=Class(TCustomControl)
  published
  Property OnClick;
  End;
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 15.09.10 14:46 
>>EDIT : Wenn ich den Click-Teil weglasse wird der Doppelclick erkannt.
my.OnDblClick :=TestDblClick;
my.OnClick :=TestClick;

erkannt wird beides:

procedure TForm5.TestDblClick(Sender: TObject);
begin
Memo1.lines.add('Doppelklick');
end;

procedure TForm5.TestClick(Sender: TObject);
begin
Memo1.lines.add('klick');
end;
mtm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

Windows 10 Pro 64 Bit
Delphi XE 6
BeitragVerfasst: Mi 15.09.10 15:06 
Danke Dir, jetzt funktioniert's !

Manchmal ist man aber auch schon ein wenig zerstreut.