Autor Beitrag
TiRoCkx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 17.03.19 17:10 
Hey Leute,

Folgender 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:
private
    { Private-Deklarationen }
    Shapes: array of TShape;
public
    Madn: TMadn;
    procedure OnShapeClick(Sender: TObject);
  end;

var
  Form2: TForm2;
  count,anz,z: byte;

procedure TForm2.CreateShapes(n: word; wc: TWinControl);
begin
  SetLength(Shapes, n);
  Field.Parent := Panel1;
  while n > 0 do
  begin
    Shapes[n] := TShape.Create(Self);
    Shapes[n].Parent := wc;
    case n of
      1,2,3,4: Shapes[n].Brush.Color := rgb(255,0,0);
      5,6,7,8: Shapes[n].Brush.Color := RGB(255,216,0);
      9,10,11,12: Shapes[n].Brush.Color := RGB(58,196,0);
      13,14,15,16: Shapes[n].Brush.Color := RGB(0,148,255);
    end;
    Shapes[n].Shape := stcircle;
    Shapes[n].Height := 30;
    Shapes[n].Width := 30;
    Shapes[n].Left := UMadn.Start[n].X;
    Shapes[n].Top := UMadn.Start[n].Y;
    Shapes[n].Pen.Width := 3;
    Shapes[n].Visible := true;
    Shapes[n].Enabled := false;
    n := n-1;
    OnClick := Self.OnShapeClick(Self); //hier liegt das Problem --> siehe 2. Quelltext
  end;
end;

procedure TForm2.OnShapeClick(Sender: TObject);
begin
  showmessage('Läuft');
end;


Mein Problem ist folgendes:

Ich habe je nach Spieleranzahl verschieden viele Figuren (Anzahl stellt Übergabewert n dar).
Diese Figuren stelle ich somit in einem dynamischem Array dar, um sie leichter ansprechen zu können.
Nun möchte ich durch die OnClick Methode der Figuren(Shapes) diese setzen.

Ich habe ein bisschen rumprobiert, komme aber auf keine Lösung.
Wie setze ich das um?

ausblenden Delphi-Quelltext
1:
[Fehler] Unewgame.pas(105): Inkompatible Typen: 'TNotifyEvent' und 'procedure, untyped pointer or untyped parameter'					



Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am So 17.03.2019 um 19:02
Holgerx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62
Erhaltene Danke: 27

Win95 - Win11 / MSServer2000 - MSServer2019
Delphi 6pro / XE4
BeitragVerfasst: So 17.03.19 17:28 
Hmm..

Mal ne Frage:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
    Shapes[n].Enabled := false;
    n := n-1;
    OnClick := Self.OnShapeClick(Self); //hier liegt das Problem --> siehe 2. Quelltext
  end;



Wessen OnCLick wird da das Self.OnShapeClick zugewiesen?

Könnte es sein, dass das so lauten müsste ( ohne das (self))?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
    Shapes[n].Enabled := false;
    Shapes[n].OnClick := Self.OnShapeClick;
    n := n-1;
  end;


Mit dem (self) würdest Du nicht die Methode zuweisen, sondern das Ergebnis des Methodenaufruf Self.OnShapeClick(Self) ;)

Für diesen Beitrag haben gedankt: TiRoCkx
TiRoCkx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 17.03.19 20:22 
Ja das mit dem Shapes[n]. habe ich vergessen.

Aber das wirft immer mehr Fragen auf:

Es gibt ja nur ein MouseDown und MouseUp Event für Shapes.
Und ich muss ja einen Sender übergeben....

Es wird immer komplizierter. :oops: :(
Holgerx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62
Erhaltene Danke: 27

Win95 - Win11 / MSServer2000 - MSServer2019
Delphi 6pro / XE4
BeitragVerfasst: So 17.03.19 20:27 
Hmm..

Wenn Du einem Object eine Event-Methode zuweißt, dann wird beim Aufrufen (vom Object selber, wenn innerhalb dessen das Event passiert) als 'Sender' das Object selber übergeben.

Somit kannst Du in deiner zugewiesenen Methode über 'Sender' auf das Object zugreifen, welches die Methode aufgerufen hat... ;)

Für diesen Beitrag haben gedankt: TiRoCkx
TiRoCkx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 17.03.19 20:36 
ok ich probiers dann gleich mal und schreibe evtl. noch mal. Danke erst mal!
TiRoCkx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 17.03.19 21:33 
Hab es jetzt so geschrieben:

ausblenden Delphi-Quelltext
1:
Shapes[n].OnMouseDown := OnShapeClick;					


Fehlermeldung:

ausblenden Delphi-Quelltext
1:
[Fehler] Unewgame.pas(103): Inkompatible Typen: 'Liste der Parameter ist unterschiedlich'					


Ich verzweifel...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 17.03.19 22:03 
Vielleicht so?
ausblenden Delphi-Quelltext
1:
Shapes[n].OnClick:= OnShapeClick;					


Das OnClick-Event hat nunmal andere Parameter als OnMouseDown. ;-)

_________________
We are, we were and will not be.
TiRoCkx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 17.03.19 23:49 
Aber Shapes haben kein OnClick Event...

Moderiert von user profile iconNarses: Beiträge zusammengefasst

Wenn ich es als OnClick schreibe, stimmen die Parameter wahrscheinlich.

Wie könnte ich denn dem Array von TShape eine OnClick-Methode zuweisen?
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 18.03.19 07:30 
- Nachträglich durch die Entwickler-Ecke gelöscht -

Für diesen Beitrag haben gedankt: TiRoCkx
TiRoCkx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 18.03.19 11:04 
Ich habs endlich!

Danke an alle bemühten Helfer! :D :wink: