Autor Beitrag
crakos
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: Sa 14.05.05 23:13 
//////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
///////////////Erkentnisse aus diesem Thread:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Habs mir panel nicht hinbekommen: Meine Lösung hier
//////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Also diesen Code hab ich mir nun jetzt zusammengereimt:
ausblenden Delphi-Quelltext
1:
2:
var
  smpanel:Tpanel;//global

Nun aus einer procedure eines buttons
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
if FindComponent('smpanel')<>nil 
  then smpanel.free;//Wenn der Pannel schon existiert, soll er freigegeben werden(also gelöscht) Habs auch mal mit destroy versucht, machta aber net
smpanel:=Tpanel.Create(form2); 
with smpanel do
  begin
    Height:=Form2.Height; 
    left:=Form2.Height;
    parent:=Form2;
    top:=Form2.Height;
    Height:=Form2.Height;
    Width:=Form2.Height;
    name:='smpanel';
    caption:='';
  end;

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.


Zuletzt bearbeitet von crakos am So 15.05.05 17:23, insgesamt 1-mal bearbeitet
Moony
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 97

Win XP
D7 Prof
BeitragVerfasst: Sa 14.05.05 23:50 
Also so wie ich das gelernt hab, müssen vor den := immer schön brav Leerzeichen hin. Oder ist das gar nicht notwendig??
Und wenn ich das richtig sehen. Dann gibst du den smpanel frei und dann initialisierst du gleich einen neuen? ahaha, jaja, ich hab keine Ahung :mrgreen: sorry
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: Sa 14.05.05 23:56 
die Leerzeichen müssen da nicht hin, dem compiler ist das schnuppe, der liest alles eh nacheinander :>
Aber danke für den versuch :)

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 14.05.05 23:58 
die leerzeichen sind nur für die Übersicht. es wäre natürlich praktisch zu wissen, WAS nicht klappt bzw. welche fehlermeldung kommt.

edit:Bleibt es einfach liegen? Versuchs mal mit Application.Processmessages...

edit2: Letztendlich brauchst du das Panel doch nicht freizugeben, oder? Wenn du die neuen eigenschaften setzt, dann klappt das doch trotzdem oder?

edit3: Dashier klappt bei mir prima:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var Form1:TForm;
    Panel1:TPanel;
{...}

procedure TForm1.Button1Click(Sender: TObject);
begin
Panel1.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Panel1:=TPanel.Create(Form1);
Panel1.Parent:=Form1;
panel1.Top:=10;
panel1.left:=10;
panel1.Width:=100;
panel1.height:=100;
end;

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.


Zuletzt bearbeitet von JayEff am So 15.05.05 00:05, insgesamt 1-mal bearbeitet
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 00:05 
achso der fehler ist einfach, das das panel nicht gelöscht wird. denn beim wiederholten klicken auf den button, sagt delphi mir das es einen panel mit diesem namen schon gibt.
Also wurde es nicht gelöscht! So und nun warum?
Application... hat nicht geholfen
genausowenig wie form2.update oder mainform.update

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 15.05.05 00:06 
dann lass das freeen und das createn einfach mal weg...?

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 00:09 
äh das geht ja net, hab das ja extra gemacht, auf dem panel liegen über 100 button ^^ die sollten verschwinden, wenn ich panel free mache(wurde in nem anderen thread gesagt)

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 00:12 
ah der fehler liegt in
ausblenden Delphi-Quelltext
1:
if FindComponent('smpanel')<>nil then					

das trit nicht ein, aber warum?

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 15.05.05 00:20 
oh. ähm. hm.
Bei mir tritt if FindComponent ... <>nil immer ein.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm2.Button2Click(Sender: TObject);
begin
if FindComponent('smpanel') <> nil then showmessage('123');
if FindComponent('smpanel') <> nil
  then smpanel.free;
smpanel:=Tpanel.Create(form2);
with smpanel do
  begin
    parent:=Form2;
    Top:=1;
    left:=1;
    Height:=10;
    Width:=10;
    name:='smpanel';
    caption:='';
  end;
end;

Macht er bei mir einwandfrei... also er sagt, Panel existiert, und gibt es somit auch frei und erzeugt es auch gleich neu. werden vielleicht die buttons nicht freigegeben? versuchs doch so: Lösche die Buttons einzeln. ich hab zumbeispiel dashier getestet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm2.Button1Click(Sender: TObject);
var i:integer;
begin
for i:=0 to 10 do begin
  with TPanel.Create(Form2) do begin
    parent:=Form2;
    Top:=1+i*10;
    left:=1+i*10;
    Height:=10;
    Width:=10;
    name:='smpanel'+IntToStr(i);
    caption:='';
  end;
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
var i:integer;
begin
for i:=0 to 10 do begin
  if FindComponent('smpanel'+IntToStr(i)) <> nil then
    (FindComponent('smpanel'+IntToStr(i)) as TPanel).free;
end;
end;

Klappt einwandfrei. Damit sind die Panels alle wieder weg.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 00:39 
es ist nur ein panel, auf dem 100 buttons sind.
rall ich nicht, warum geht das bei dir, aber bei mir nicht?
Warum geht das nicht ..... if FindComponent('smpanel') ist immer 0 '%&'$'§#
Da es ja nur um eine abfrage geht, hab ich es mit einer boolschen variablen geregelt
aber nun sind grad gar keine buttons da :/ omg

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.


Zuletzt bearbeitet von crakos am So 15.05.05 00:44, insgesamt 2-mal bearbeitet
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 15.05.05 00:41 
wie hast du die Buttons genannt? versuch sie, so wie ich die panels, in einer schleife freizugeben...

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 00:46 
mh das panel hab ich ja extra gemacht, weil mir auf meine frage, wie bekomme ich die buttons weg, gesagt wurde: auf ein panel machen dann panel free und alle buttons wech.
oder TobjectListe <--- hab aber bis jetzt kein gescheites Tutorial gefunden

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 15.05.05 00:49 
hast du den buttons das Panel als Parent gegeben? ich glaube, dass das sein muss. aber die Buttons in einer schleife freigeben klappt doch auh, jenachdem, wie sie genannt sind...?

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 00:55 
hab die panel sachen nun alle weg commentiert, wollte nun so eine schleife machen.
Nun ich weiss die id von den buttons aber wie frage ich die mit FindComponent ab?

die buttons sind in einem array of array of tbutton
die namen sind alle anders
das einzige was man von den buttons weiss, ist die id

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 15.05.05 00:58 
wenn die in einem array of array of TButton sind, dann mach doch einfach

ausblenden Delphi-Quelltext
1:
2:
3:
for x:=0 to 10 do
  for y:=0 to 10 do
    buttons[x][y].free;

odrer so ähnlich?

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 01:02 
ausblenden Delphi-Quelltext
1:
2:
3:
  for x:=0 to 13 do
  for y:=0 to 8 do  
    buttonliste[x,y].free;

funzt net :(

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 15.05.05 01:10 
user profile iconJayEff hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
for x:=0 to 10 do
  for y:=0 to 10 do
    buttons[x][y].free;


*räusper* getestet und funzt.

guck mal:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.Button1Click(Sender: TObject);
var x,y:integer;
begin
  for x:=0 to 10 do
  for y:=0 to 10 do begin
  Buttons[x][y]:=TButton.Create(Form1);
  with Buttons[x][y] do begin
  parent:=Form1;
  top:=y*10+100;
  left:=x*10+100;
  width:=10;
  height:=10;
  name:='b'+IntToStr(x)+intToStr(y);
  caption:='o';
  end;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var x,y:integer;
begin
  for x:=0 to 10 do
  for y:=0 to 10 do
  buttons[x][y].Free;
end;


klappt perfekt.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 15.05.05 08:55 
user profile iconcrakos hat folgendes geschrieben:
auf ein panel machen dann panel free und alle buttons wech.
oder TobjectListe <--- hab aber bis jetzt kein gescheites Tutorial gefunden

ausblenden Delphi-Quelltext
1:
2:
uses
  Contnrs;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
type
  TForm1 = class(TForm)
    ...
  private
    { Private-Deklarationen }
    MyButtonList: TObjectList;
    ...
  end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
procedure TForm1.Button1Click(Sender: TObject);
var
  MyButton: TButton;
  I: Integer;
begin

  // 10 TButton erstellen und mit TObjectList verwalten

  if not Assigned(MyButtonList) then
  begin
    MyButtonList := TObjectList.Create(True);
    for I := 0 to 9 do
    begin
      MyButton := TButton.Create(nil);
      MyButtonList.Add(MyButton);
      with MyButton do
      begin
        Parent := Self;
        SetBounds(I * 20, 0, 20, 20);
      end;
    end;
  end;

end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button2Click(Sender: TObject);
begin

  // Alle MyButton's und MyButtonList entfernen

  if Assigned(MyButtonList) then
    FreeAndNil(MyButtonList);

end;

_________________
Ciao, Sprint.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 13:46 
yeah, genau sowas hab ich gesucht :) einfach,unkompliziert und man versteht es sofort :D
Vielen dank :D

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
crakos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: So 15.05.05 16:53 
also ich habs ohne panel gemacht:
habs mit TObjectlist die buttons free gemacht
und die länge des arrays auf 0 gesetzt
ausblenden Delphi-Quelltext
1:
2:
3:
  var  //global
  MyButtonList: TObjectList;
  Buttonliste : array of array of tbutton;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
   
  SetLength(buttonliste,0); //array zurücksetzen
  if Assigned(MyButtonList) then //wenn die Objekliste vorhanden ist löschen
    FreeAndNil(MyButtonList);
  if not Assigned(MyButtonList) then //das if eigentlich überflüßig, wollte nur sichergehen ^^
    MyButtonList := TObjectList.Create(True);

Und nachem button erstellen zur liste hinzufügen(habs vereinfacht
ausblenden Delphi-Quelltext
1:
2:
  Buttonliste[x,y]:=TButton.Create(self);
  MyButtonList.Add(Buttonliste[x,y];

Original stand da
ausblenden Delphi-Quelltext
1:
2:
  Buttonliste[laenge,high(buttonliste[laenge])]:=TButton.Create(self);//laenge ist die nummer der Reihe, in der der Button erstellt werden soll
  MyButtonList.Add(Buttonliste[laenge,high(buttonliste[laenge])]);

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.