Autor Beitrag
BernddasBrot
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D2005
BeitragVerfasst: Mo 31.01.05 20:22 
Hi!

ich will ein 4 Gewinnt erstellen und habe jetzt diesen Code gemacht:
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:
unit unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
    procedure farbe(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  links,oben:integer;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
zaehler, zaehler2 : Integer;
begin
for zaehler := 1 to 6 do begin
  for zaehler2 := 1 to 8 do begin
    TShape.Create(self).Name := 'shape'+IntToStr(oben)+IntToStr(links);
    with TShape(FindComponent('shape'+IntToStr(oben)+IntToStr(links))) do begin
      parent := Self;
      Left := 52*links;
      Top := 52*oben;
      width := 50;
      height := 50;
      Shape := stcircle;
      onClick := farbe;
    end;
    inc(links);
  end;
  links := 0;
  inc(oben);
end;
end;

procedure TForm1.farbe(Sender: TObject);
begin
TShape(sender).Brush.Color := clred;
end;

end.


Allerdings funktioniert das mit dem Onclick vom Shape nicht. Das Shape soll sich bei onclick rot färben

BernddasBrot

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 31.01.05 20:33 
Wegen der Handhabung der Shapes würde ich mir mal Array anschauen!
Zu deinem Problem:
Wie siehst du überhaupt deine Shapes? Du setzt doch gar keinen Parent :?
Setze mal als Parent Form1, genauso wie du die Shapes auch mit TShape.Create(Form1) erstellen solltest.
BernddasBrot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D2005
BeitragVerfasst: Mo 31.01.05 20:40 
Elite hat folgendes geschrieben:
Wie siehst du überhaupt deine Shapes? Du setzt doch gar keinen Parent :?

Doch, ich seh die ;) Ich hab doch parent := Self; gesetzt
Wenn ich self überall durch Form1 ersetze, wirdd die Prozedur immer noch nur bei onclick auf Form1 und nicht bei onclick auf die Shapes ausgeführt

BernddasBrot
BernddasBrot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D2005
BeitragVerfasst: Mo 31.01.05 22:54 
ah, ich hab den Fehler vieleicht gefunden: Ein Shape hat kein OnClick Event.
Wenn ich allerdings onMouseDown := farbe; verwende, kommt ein Fehler.
Danke schonmal für die bisherigen Antworten

BernddasBrot

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 31.01.05 22:59 
OnMouseDown hat AFAIK mehr Parameter als nur Sender, wie z.B. auch die Mauskoordinaten x und y sowie Infos über den Button (links/rechts) etc.

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


D2005
BeitragVerfasst: Mo 31.01.05 23:10 
also ist das Problem jetzt glaub ich, dass der Sender net gscheit übergeben wird.
onclick := farbe(Sender); geht nicht ebenso wie diverse Kombinationen, die ich schon ausprobiert habe, wie z.B. onclick := farbe(FindComponent('shape'+IntToStr(oben)+IntToStr(links)))

BernddasBrot

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 31.01.05 23:31 
du musst das ereignis in einer eigenen klasse definieren, z.b. so

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
type

tmyshape = class (TShape)
  private
  procedure Click(Sender:Tobject);
end;

tform1 = class(tform)
  myshape: tmyshape;
....

myshape := tmyshape.create(bla);
myshape.onclick := click;
BernddasBrot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D2005
BeitragVerfasst: Di 01.02.05 07:10 
ah, danke es geht jetzt!
super!
für alle, dies interessiert, mein Code sieht jetzt so aus:
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:
unit unit1;

interface

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

type
tmyshape = class (TShape);
  TForm1 = class(TForm)
    Shape1: TShape;
    myshape: tmyshape;
    procedure FormShow(Sender: TObject);
    procedure farbe(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  links,oben:integer;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
zaehler, zaehler2 : Integer;
begin
for zaehler := 1 to 6 do begin
  for zaehler2 := 1 to 8 do begin
    Tmyshape.Create(Form1).Name := 'shape'+IntToStr(oben)+IntToStr(links);
    with Tmyshape(FindComponent('shape'+IntToStr(oben)+IntToStr(links))) do begin
      parent := Form1;
      Left := 52*links;
      Top := 52*oben;
      width := 50;
      height := 50;
      Shape := stcircle;
      onClick := farbe;
    end;

    inc(links);
  end;
  links := 0;
  inc(oben);
end;
end;

procedure TForm1.farbe(Sender: TObject);
begin
TShape(sender).Brush.Color := clred;
end;

end.


BernddasBrot

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Stauch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 140

Win 2000, Win XP
D4
BeitragVerfasst: Fr 04.02.05 13:44 
Das funktioniert genial - mit OnClick. Wenn ich aber das gleiche mit OnKeyDown versuche, erhalte eine Fehlermeldung:
unbekannter Bezeichner 'onkeydown'

Was ist denn hier der Unterschied?

Carsten

_________________
Geht das? Und wenn ja, warum nicht?