Compter le nombre de labels

cs_Dagnir Messages postés 18 Date d'inscription jeudi 24 avril 2003 Statut Membre Dernière intervention 11 février 2009 - 19 mai 2003 à 21:38
Jean44 Messages postés 26 Date d'inscription mardi 25 février 2003 Statut Membre Dernière intervention 27 juin 2003 - 20 mai 2003 à 14:41
Salut,
Je voudrais savoir s'il est possible d'attribuer à une variable x le nombre de labels que la fiche comporte. Dans le même esprit, si on peut ajouter un label disons sur un clic de bouton.

Dagnir

1 réponse

Jean44 Messages postés 26 Date d'inscription mardi 25 février 2003 Statut Membre Dernière intervention 27 juin 2003
20 mai 2003 à 14:41
Voici un petit exemple.
C'est la réponse de la fiche principale (TFMain ici) à l'événement OnMouseDown.

procedure TFMain.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  i : Integer;
  LabelCount : Integer;
  NewLabel : TLabel;
begin
  LabelCount := 0;
  for i := 0 to FMain.ComponentCount-1 do
  begin
    if FMain.Components[i] is TLabel then
      Inc( LabelCount);
  end;

  NewLabel := TLabel.Create( FMain);
  NewLabel.Caption := 'Label' + IntToStr( LabelCount+1);
  NewLabel.Top  := Y;
  NewLabel.Left := X;
  NewLabel.Parent := FMain;
  NewLabel.Show;
end;
0
Rejoignez-nous