Autor Beitrag
McFarlane
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

WIN XP Prof.
Delphi 2005 PE, Turbo Delphi 2006, PHP (Eclipse)
BeitragVerfasst: Do 25.01.07 15:18 
Hallo,
ich habe hier ein Form mit ganzt vielen TShapes drauf.
Nun soll sich ein Shape bei ONMouseDown färben und bei nochmaligem klicken zurückfärben.
Bis hier hin kein Problem, doch kann ich irgendwie eine Prozedur für alle erstellen, oder muss ichs für jedes einzeln machen?

Danke im Vorraus, McFarlane

_________________
21 ist nur die halbe Wahrheit...
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Do 25.01.07 15:22 
Hi Mcfarlane,

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure einfaerben(Shape: TShape);
begin
 Shape.Pen.Color := clRed;
 Shape.Brush.Color := clRed;
end;


procedure TForm1.Button1Click(Sender: TObject); // z.B.
begin
 einfaerben(Shape1);
end;


Gruß

Saubäär
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 25.01.07 15:25 
Wieso so kompliziert? In Sender wird das Aufrufende Objekt übergeben, nur weiß Delphi nicht, dass es ein Shape ist, und deshalb musst du erst sagen "ich will das als Shape ansprechen". So siehts dann aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button1Click(Sender: TObject); // z.B.
begin
(sender as TShape).Pen.Color := clRed;
(sender as TShape).Brush.Color := clRed;
end;

Dann musste nur noch allen Shapes diese Ereignisbehandlung zuweisen.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Do 25.01.07 15:26 
nein brauchst du nicht,

du brauchst den Event nur einmal und hängst diese an jedes Shape an

ungefähr so
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  TShape(sender).Brush.Color := clred;
end;
]

Wichtig ist der "Sender" denn der gibt Delphi die Information weiter welcher TShape geklickt wurde.n

Edit: Mist zu langsam.

_________________
mfg. Joel


Zuletzt bearbeitet von JoelH am Do 25.01.07 15:27, insgesamt 1-mal bearbeitet
McFarlane Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

WIN XP Prof.
Delphi 2005 PE, Turbo Delphi 2006, PHP (Eclipse)
BeitragVerfasst: Do 25.01.07 15:26 
Perfekt!
Vielen Dank.

_________________
21 ist nur die halbe Wahrheit...