Autor Beitrag
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 12.12.10 14:59 
Ich möchte einer zur Laufzeit erstellten Komponente zwei Events zuweisen. Das habe ich so probiert (ich benutze Lazarus):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
// Deklaration auch bei TForm1.
// Erst bei public, dann dort, wo alle anderen Event-Handler deklariert werden
// ändert nichts am Fehler
procedure TForm1.WidgetMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
...
end;

SetLength(Buttons, Length(Buttons) + 1);
Buttons[Length(Buttons) - 1] := TButtonWidget.Create(TabSheet6);
with Buttons[Length(Buttons) - 1do
begin
  Parent := TabSheet6;
  Name := 'wxButton' + IntToStr(Length(Buttons));
  Caption := Name;
  OnMouseDown := WidgetMouseDown;
  OnClick     := WidgetClick;

end;


Sein Compiler sagt dazu:

ausblenden Quelltext
1:
2:
3:
4:
main.pas(234,39) Error: Wrong number of parameters specified for call to "WidgetMouseDown"
main.pas(185,18) Hint: Found declaration: TForm1.WidgetMouseDown(TObject, TMouseButton, TShiftState, LongInt, LongInt);
main.pas(235,35) Error: Wrong number of parameters specified for call to "WidgetClick"
main.pas(148,15) Hint: Found declaration: TForm1.WidgetClick(TObject);


Ich habe gegooglet und (in einem Thread der DP) wurde das auch genauso gepostet.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 12.12.10 15:05 
hast Du in TButtonWidget die Events anders deklariert?
Sollte so funktionieren.

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Jakob_Ullmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 12.12.10 15:11 
Nein, TButtonWidget wird so deklariert:

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:
  TButtonWidget = class(TToggleBox)
    constructor Create(AOwner: TComponent); override;
  public
    IsSelected: Boolean;
  end;

...

{          TButtonWidget         }
constructor TButtonWidget.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Caption := 'Button';
  IsSelected := False;
  AllowGrayed := True;
  State := cbGrayed;
  Width := 75;
  Height := 25;
end;

{ aus den StdCtrls: }
{ nur als Referenz: Deklaration von TToggleBox }
  TToggleBox = class(TCustomCheckBox)
  private
  public
    constructor Create(TheOwner: TComponent); override;
  published
    property AllowGrayed;
    property Anchors;
    property AutoSize default false;
    property BorderSpacing;
    property Caption;
    property Checked;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Hint;
    property OnChange;
    property OnClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property State;
    property TabOrder;
    property TabStop;
    property Visible;
  end;


Also an den Events habe ich gar nichts gemacht.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 12.12.10 15:38 
Ich kenne TToggleBox nicht, wie sieht die Implementierung dort aus?

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Jakob_Ullmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 12.12.10 15:41 
Deklaration ist im Post oben. Implementation könnte ich jetzt posten. Ist aber unwichtig, denn derselbe Fehler kommt, wenn ich alles auf TButton umändere (Also nicht nur TButtonWidget von TButton ableite, sondern auch Buttons als Array of TButton deklariere und TButton.Create(...) schreibe).
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 12.12.10 15:50 
Lazarus verwendet eine etwas andere Syntax. Stell mal den Syntax-Modus um auf Delphi. Und/oder ersetze $mode objfpc durch $mode delphi. Oder verwende @ vor der Zuweisung.

Für diesen Beitrag haben gedankt: Jakob_Ullmann
Jakob_Ullmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 12.12.10 16:00 
user profile icondelfiphan hat folgendes geschrieben Zum zitierten Posting springen:
Lazarus verwendet eine etwas andere Syntax. Stell mal den Syntax-Modus um auf Delphi. Und/oder ersetze $mode objfpc durch $mode delphi. Oder verwende @ vor der Zuweisung.


Hey cool, das funktioniert!

Hatte das auch gerade mit diesem unschönen Workaround gelöst:

ausblenden Delphi-Quelltext
1:
Buttons[Length(Buttons) - 1].OnMouseDown := PaintBox1.OnMouseDown;					


PaintBox1 hatte auch die WidgetMouseDown verlinkt.