begin process at 2008 08 29 21:45:34
1 233 910 membres
431 nouveaux aujourd'hui
14 294 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CREER DYNAMIQUEMENT PLUSIEURS STRINGGRID


Information sur la source

Catégorie :Maths Niveau : Débutant Date de création : 18/04/2003 Date de mise à jour : 18/04/2003 11:25:52 Vu : 3 191

Note :
Aucune note

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

Description

Ce code permet de créer dynamiquement autant de StringGrid qu'on veut rien qu'on entrant le nombre et on cliquant sur le bouton;

Source

  • procedure TForm1.Button1Click(Sender: TObject);
  • var i,n:integer;
  • Mat : TStringGrid;
  • begin
  • n:=strtoint(edit1.text);
  • for i:=1 to n do
  • TStringGrid(FindComponent('Mat'+inttostr(i))).free; //pour effacer les stringgrid existant
  • Mat := TStringGrid.Create(self);
  • Mat.Parent := Self;
  • Mat.Name := 'Mat1';
  • Mat.Width := 235;
  • Mat.Height := 130;
  • Mat.Left := 18;
  • Mat.Top := 30;
  • Mat.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goTabs];
  • Mat.DefaultColWidth :=45;
  • Mat := TStringGrid.Create(self);
  • Mat.Parent := Self;
  • Mat.Name := 'Mat2';
  • Mat.Width := 235;
  • Mat.Height := 130;
  • Mat.Left := 280;
  • Mat.Top := 30;
  • Mat.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goTabs];
  • Mat.DefaultColWidth :=45;
  • i:=3;
  • while (i<= n) do
  • begin Mat := TStringGrid.Create(self);
  • Mat.Parent := Self;
  • Mat.Name := 'Mat'+inttostr(i); // un nom différent pour chaque stringgrid créer
  • Mat.Width := 235;
  • Mat.Height := 130;
  • Mat.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goTabs];
  • Mat.DefaultColWidth :=45;
  • if ((i mod 2) = 0) then
  • begin Mat.Left := 280;
  • Mat.Top:= TStringGrid(FindComponent('Mat'+inttostr(i-2))).Top+TStringGrid(FindComponent('Mat'+inttostr(i-2))).Height+10;
  • end
  • else begin Mat.Left := 18;
  • Mat.Top := TStringGrid(FindComponent('Mat'+inttostr(i-2))).Top+TStringGrid(FindComponent('Mat'+inttostr(i-2))).Height+10;
  • end;
  • i:=i+1;
  • end;
  • end;
procedure TForm1.Button1Click(Sender: TObject);
var       i,n:integer;
          Mat : TStringGrid;
begin
n:=strtoint(edit1.text);
for i:=1 to n do
 TStringGrid(FindComponent('Mat'+inttostr(i))).free; //pour effacer les stringgrid existant

Mat := TStringGrid.Create(self);
Mat.Parent := Self;
Mat.Name := 'Mat1';
Mat.Width := 235;
Mat.Height := 130;
Mat.Left := 18;
Mat.Top := 30;
Mat.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goTabs];
Mat.DefaultColWidth :=45;

Mat := TStringGrid.Create(self);
Mat.Parent := Self;
Mat.Name := 'Mat2';
Mat.Width := 235;
Mat.Height := 130;
Mat.Left := 280;
Mat.Top := 30;
Mat.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goTabs];
Mat.DefaultColWidth :=45;

i:=3;
while (i<= n) do
begin Mat := TStringGrid.Create(self);
      Mat.Parent := Self;
      Mat.Name := 'Mat'+inttostr(i);  // un nom différent pour chaque stringgrid créer
      Mat.Width := 235;
      Mat.Height := 130;
      Mat.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goTabs];
      Mat.DefaultColWidth :=45;
       if ((i mod 2) = 0) then
         begin Mat.Left := 280;
               Mat.Top:= TStringGrid(FindComponent('Mat'+inttostr(i-2))).Top+TStringGrid(FindComponent('Mat'+inttostr(i-2))).Height+10;
         end
       else begin  Mat.Left := 18;
                   Mat.Top := TStringGrid(FindComponent('Mat'+inttostr(i-2))).Top+TStringGrid(FindComponent('Mat'+inttostr(i-2))).Height+10;
            end;

      i:=i+1;
end;

end;

Conclusion

Je créer d'abord 2 StringGrid comme réference, et je créer les autres par rapport à la poisition des 2 premiers, car ma dsposition est 2 par ligne;
  • signaler à un administrateur
    Commentaire de Adkiks le 21/07/2004 20:29:12

    Ce n'est pas un avis ,mais plutot une demande d'aide.Voilà!Je prépare mon diplome de Technitien supérieur en informatique de gestion,actuellement je travaille sur mon logiciel.J'utilise un stringgrid poua la saisie des documents.le probleme c'est que pour les controles des champs il faut taper ENTREE por qu'il y est un controle sur ce champ ,alors que je veux déclencher le controle avec d'autres touches (par éxemple TABULATION ou FLECHES de DIRECTION).J'espère  avoir une réponse .Merci !!

Ajouter un commentaire

Pub



Appels d'offres

Recherche developpeur ...
Budget : 700€
SITE MARCHAND LOCATION...
Budget : 3 000€
SITE MARCHAND POUR HOTEL
Budget : 4 000€

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

Boutique

Boutique de goodies CodeS-SourceS