![]() |
Delphi-Version: 5
Array von TShapes visible machen
Hallo alle zusammen,
ich habe ein Problem und zwar habe ich mit einem Programm 50 Tshapes sichtbar gemacht. Jetzt möchte ich aber alle auf einmal wieder unsichtbar machen. Die Variante alle Shapes nacheinander sichtbar zu machen ist mir zu aufwendig, deswegen habe ich ein Array erstellt. Jedoch bekomme ich immer eine Fehlermeldung, wenn ich diese mit dem Button starte. Bitte erklärt mir die Schritte, da ich erst vor wenigen Wochen mit dem Programmieren angefangen habe. LG Shoqez
Delphi-Quellcode:
var i:integer;
shape: array [1..50] of tshape for i:=1 to 50 do begin shape[i].visible:=false; end; |
AW: Array von TShapes visible machen
.. wie füllst Du denn Dein Array?
Grüße Klaus |
AW: Array von TShapes visible machen
Gehe einmal in die Zeile, in der du die Sichtbarkeit umschaltest (die Zeile in der Schleife). Drücke dann F5 um einen Haltepunkt zu setzen. Dann führe das Programm mit F9 aus. Wenn du am Haltepunkt ankommst, kannst du schauen was in deinem Array enthalten ist. (Maus über die Variable shape halten oder links in den lokalen Variablen schauen oder mit Strg + F7 z.B. shape[i] auswerten...)
Wenn in dem Array ein Eintrag nil ist, ist dort kein Shape zugewiesen. Dann knallt es deshalb. |
AW: Array von TShapes visible machen
Zitat:
Ich fülle den array mit den shapes 1 bis 50 aber ich dachte wenn der array [1..50] eingestellt ist, nimmt das Programm automatisch die ersten 50 Shapes in meiner Form. Grüße |
AW: Array von TShapes visible machen
Zitat:
Wie wäre es, wenn du einfach mal mehr Quelltext zeigst? |
AW: Array von TShapes visible machen
Zitat:
Delphi-Quellcode:
unit Unit1;
{$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Buttons; type { TForm1 } TForm1 = class(TForm) btngo: TButton; Button1: TButton; Image1: TImage; Shape1: TShape; Shape10: TShape; Shape11: TShape; Shape12: TShape; Shape13: TShape; Shape14: TShape; Shape15: TShape; Shape16: TShape; Shape17: TShape; Shape18: TShape; Shape19: TShape; Shape2: TShape; Shape20: TShape; Shape21: TShape; Shape22: TShape; Shape23: TShape; Shape24: TShape; Shape25: TShape; Shape26: TShape; Shape27: TShape; Shape28: TShape; Shape29: TShape; Shape3: TShape; Shape30: TShape; Shape31: TShape; Shape32: TShape; Shape33: TShape; Shape34: TShape; Shape35: TShape; Shape36: TShape; Shape37: TShape; Shape38: TShape; Shape39: TShape; Shape4: TShape; Shape40: TShape; Shape41: TShape; Shape42: TShape; Shape43: TShape; Shape44: TShape; Shape45: TShape; Shape46: TShape; Shape47: TShape; Shape48: TShape; Shape49: TShape; Shape5: TShape; Shape50: TShape; Shape6: TShape; Shape7: TShape; Shape8: TShape; Shape9: TShape; procedure btngoClick(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Image1Click(Sender: TObject); procedure Timer1StartTimer(Sender: TObject); procedure Timer1Timer(Sender: TObject); private public end; var Form1: TForm1; inils,iemmi,iphillip,ipauline,imichi,z1,z2,z3,z4,i:integer; shape: array [1..50] of tshape; implementation {$R *.lfm} { TForm1 } procedure TForm1.Image1Click(Sender: TObject); begin end; procedure TForm1.Timer1StartTimer(Sender: TObject); begin end; procedure TForm1.Timer1Timer(Sender: TObject); begin end; procedure TForm1.FormCreate(Sender: TObject); begin inils:=0; iemmi:=0; iphillip:=0; ipauline:=0; imichi:=0; end; procedure TForm1.btngoClick(Sender: TObject); begin //Zufallsgen randomize; z1:=random(2); z2:=random(2); z3:=random(2); z4:=random(2); //Implementation If z1 =0 then if z2=0 then if z3=0 then if z4=0 then inils:=inils+1 else iemmi:=iemmi+1 else if z4=0 then iemmi:=iemmi+1 else iphillip:=iphillip+1 else if z3=0 then if z4=0 then iemmi:=iemmi+1 else iphillip:=iphillip+1 else if z4=0 then iphillip:=iphillip+1 else ipauline:=ipauline+1 else if z2=0 then if z3=0 then if z4=0 then iemmi:=iemmi+1 else iphillip:=iphillip+1 else if z4=0 then iphillip:=iphillip+1 else ipauline:=ipauline+1 else if z3=0 then if z4=0 then iphillip:=iphillip+1 else ipauline:=ipauline+1 else if z4=0 then ipauline:=ipauline+1 else imichi:=imichi+1; //button deaktivieren if imichi+ipauline+iemmi+iphillip+inils=10 then btngo.enabled:= false; //Kugel sichtbarkeit case inils of 1: shape1.visible:=true; 2: shape2.visible:=true; 3: shape3.visible:=true; 4: shape4.visible:=true; 5: shape5.visible:=true; 6: shape6.visible:=true; 7: shape7.visible:=true; 8: shape8.visible:=true; 9: shape9.visible:=true; 10: shape10.visible:=true; end; case iemmi of 1: shape11.visible:=true; 2: shape12.visible:=true; 3: shape13.visible:=true; 4: shape14.visible:=true; 5: shape15.visible:=true; 6: shape16.visible:=true; 7: shape17.visible:=true; 8: shape18.visible:=true; 9: shape19.visible:=true; 10: shape20.visible:=true; end; case iphillip of 1: shape21.visible:=true; 2: shape22.visible:=true; 3: shape23.visible:=true; 4: shape24.visible:=true; 5: shape25.visible:=true; 6: shape26.visible:=true; 7: shape27.visible:=true; 8: shape28.visible:=true; 9: shape29.visible:=true; 10: shape30.visible:=true; end; case ipauline of 1: shape31.visible:=true; 2: shape32.visible:=true; 3: shape33.visible:=true; 4: shape34.visible:=true; 5: shape35.visible:=true; 6: shape36.visible:=true; 7: shape37.visible:=true; 8: shape38.visible:=true; 9: shape39.visible:=true; 10: shape40.visible:=true; end; case imichi of 1: shape41.visible:=true; 2: shape42.visible:=true; 3: shape43.visible:=true; 4: shape44.visible:=true; 5: shape45.visible:=true; 6: shape46.visible:=true; 7: shape47.visible:=true; 8: shape48.visible:=true; 9: shape49.visible:=true; 10: shape50.visible:=true; end; end; procedure TForm1.Button1Click(Sender: TObject); begin inils:=0; iemmi:=0; iphillip:=0; ipauline:=0; imichi:=0; btngo.enabled:=true; for i:=1 to 50 do begin shape[i].visible:=false; end; end ; end. |
AW: Array von TShapes visible machen
Also kurz zur Erklärung: Das Programm simuliert ein Galtonbrett, jedoch ist nach 10 Kugeln ende. Ich möchte einen Reset Button einbauen, der alles auf Anfang setzt.
|
AW: Array von TShapes visible machen
mal ohne Array
Delphi-Quellcode:
Grüße
for i := 1 to 50 do begin
(FindComponent('Shape' + IntToStr(i)) as TShape).visible := false; end; Klaus |
AW: Array von TShapes visible machen
Oder auch
Delphi-Quellcode:
(ungetestet). Dann kann man den Shapes auch aussagefähigere Namen geben, und sie werden trotzdem gefunden.
for i := 0 to ControlCount - 1 do
if Controls[i] is TShape then TShape(Controls[i]).Visible := false; |
AW: Array von TShapes visible machen
Zitat:
Funktioniert 1A. Werde mich jetzt wahrscheinlich öfter bei euch im Forum melden. :-D Schönen Tag euch noch! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:37 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz