Mozes koristiti .Tag property buttona recimo:
Code:
procedure TButton.OnClick(Sender : TObject);
begin
Button.Tag := Button.Tag + 1;
Case Button.Tag of
1 : Button.Color := clGreen;
2 : Button.Color := clRed;
3 : Begin
Button.Color := DEFAULT_COLOR;
Button.Tag := 0;
End;
end;
end;
Kako bi izbrojao koliko crvenih buttona imas na formi, treba ti nesto ovako:
Code:
function Buttons_CountForColor(const AColor : TColor) : Integer;
var
C1 : Integer;
begin
result := 0;
For C1 := 0 to Form.ComponentCount - 1 Do
If (Form.Component[C1].InheritsFrom(TButton)) and
(TButton(Form.Component[C1]).Color = AColor) Then
Inc(result);
end;
..i onda prosledis ovoj funkciji boju koju hoces, recimo Buttons_CountForColor(clRed) i ona ti vrati broj crvenih dugmica. Pisao sam kodove iz glave, sorry na losem formatiranju.