Autor Beitrag
Hazer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Mo 24.09.07 16:36 
Hi,
also ich habe eine dynamische Liste in der ich TLabels erstelle und dann auch wieder Löschen will. Das Erstellen von den Labels funktioniert einwandfrei:

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:
  tmp := List;
  while tmp.next <> nil do tmp:=tmp.next;
  New(tmp.next);
  tmp.next.mylabel:=Tlabel.Create(ff.formlink);
  with tmp.next.mylabel do begin
    parent:=ff.parentlink;
    caption:=bbtext;
    top:=y;
    left:=x;
    if ff.link then begin
      onclick:=gotourl;
      cursor:=crHandPoint;
    end;
    if ff.alignment <> taLeftJustify then begin
      autosize:=false;
      width:=ff.parentlink.Width-3;
      wordwrap:=true;
      alignment:=ff.alignment;
    end;
  end;
  x:=x+tmp.next.mylabel.Width;
  tmp.next.next := nil;


Aber leider bekomme ich eine "AV", wenn ich die Liste auflösen will:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
begin
  current:=List;
  while current <> nil do begin
    temp:=current.next;
    if current.mylabel <> nil then begin
      current.mylabel.free; //AV! wenn ich mir den Wert von mylabel anschaue zeigt der auf $A
      current.mylabel:=nil;
    end;
    dispose(current);
    current:= temp;
  end;
  list:=nil;
  createList(List);
end;


Weiß leider nicht mehr weiter :(

Gruß
Hazer

_________________
I was too weak to fight | once more i let go
it is a black session | an invitation of sorts
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 24.09.07 16:42 
Moin!

Warum verwendest du nicht eine TObjectList, die ist praktisch für sowas gemacht! :idea: ;)

Damit ginge das Leeren der Liste und Freigeben der Objekte in einem: ObjectList.Free; :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Mo 24.09.07 16:53 
Hi,
danke für deine Antwort. Klingt ja erstmal gut, jedoch wenn ich einer Variablen den Typ TObjectlist gebe, bekomme ich "[Pascal Error] Unitxx.pas(yy): E2003 Undeclared identifier: 'TObjectList'"

Muss ich etwas in der uses-liste einfügen oder wie soll ich das bewerkstelligen?

Gruß
Hazer

_________________
I was too weak to fight | once more i let go
it is a black session | an invitation of sorts
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 24.09.07 16:55 
Moin!

user profile iconHazer hat folgendes geschrieben:
Muss ich etwas in der uses-liste einfügen oder wie soll ich das bewerkstelligen?

Yup: ;)
ausblenden Delphi-Quelltext
1:
2:
uses
  ..., Contnrs;

Steht aber auch in der DOH... :les: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Mo 24.09.07 17:09 
Oh, okay danke.
Aber leider bekomme ich nun bei Objectlist.create eine AV oO? scheint alles sehr verhext zu sein -.-

Ist das normal?
ausblenden Delphi-Quelltext
1:
var labell: TObjectList;					


ausblenden Delphi-Quelltext
1:
labell.create();					


*heul* >_>


Hazer

_________________
I was too weak to fight | once more i let go
it is a black session | an invitation of sorts
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 24.09.07 17:14 
Moin!

Die ObjectList ist natürlich kein Label, sondern ein eigenes Objekt. ;) Probier das mal so: :idea:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
public // TForm-Klasse
  Objects: TObjectList;

begin // z.B. FormCreate
  Objects := TObjectList.Create; // Liste anlegen

begin // z.B. FormDestroy
  FreeAndNil(Objects);

begin // z.B. Button1Click
  ALabel := TLabel.Create(NIL); // kein Owner, wird selbst verwaltet
  with ALabel do begin
    // Eigenschaften setzen, z.B.:
    Caption := 'Ich bin ein Label';
  end;
  Objects.Add(ALabel); // in die Liste

begin // z.B. Button2Click
  FreeAndNil(Objects);

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Mo 24.09.07 17:31 
Omg...das mache ich öfter falsch... tut mir leid, für meinen sinnlosen Post. Danke für die Aufklärung. Hoffentlich hab ich es jetzt geraft -.-"

Leider habe ich immer noch ein Problem mit der objectlist oô
Erstens, werden die Labels nicht angezeigt und zweitens bekomme ich bei der "Zerstörung" des Labels eine Fehlermeldung "invalid pointer operation" oder so...

erzeugen
ausblenden Delphi-Quelltext
1:
labell:=Tobjectlist.create();					


hinzufügen
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:
var tmplabel: Tlabel; //lokale variable
begin
  tmplabel:=Tlabel.Create(nil);
  with tmplabel do begin
    parent:=ff.parentlink; //ist eine scrollbox
    caption:=bbtext;
    top:=y;
    left:=x;
    if ff.link then begin
      onclick:=gotourl;
      cursor:=crHandPoint;
    end;
    if ff.alignment <> taLeftJustify then begin
      autosize:=false;
      width:=ff.parentlink.Width-3;
      wordwrap:=true;
      alignment:=ff.alignment;
    end;
  end;
  labell.Add(tmplabel);
  x:=x+tmplabel.Width;
  tmplabel.Free;


zerstören
ausblenden Delphi-Quelltext
1:
freeandnil(labell);					


Hazer

_________________
I was too weak to fight | once more i let go
it is a black session | an invitation of sorts
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 24.09.07 17:36 
Moin!

user profile iconHazer hat folgendes geschrieben:
Leider habe ich immer noch ein Problem mit der objectlist

Nein, das sieht schonmal ganz gut aus. ;) Allerdings würde ich das Ding nicht Label1nennen, sondern LabelListoder irgendwas anderes sinnvolles... :?

Dein Fehler liegt vermutlich hier:
user profile iconHazer hat folgendes geschrieben:
hinzufügen
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:
var tmplabel: Tlabel; //lokale variable
begin
  tmplabel:=Tlabel.Create(nil);
  with tmplabel do begin
    parent:=ff.parentlink; //ist eine scrollbox
    caption:=bbtext;
    top:=y;
    left:=x;
    if ff.link then begin
      onclick:=gotourl;
      cursor:=crHandPoint;
    end;
    if ff.alignment <> taLeftJustify then begin
      autosize:=false;
      width:=ff.parentlink.Width-3;
      wordwrap:=true;
      alignment:=ff.alignment;
    end;
  end;
  labell.Add(tmplabel);
  x:=x+tmplabel.Width;
  // tmplabel.Free; // du darfst den Label doch nicht wieder freigeben! ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Mo 24.09.07 17:41 
omg
omfg xD
es klappt!!!
DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANKEEEEEEEE!!!!!!!!


Dachte, weil es eine lokale Variable war, muss ich die freigeben weil sie beim nächsten Aufruf ja wieder initiiert wird... Scheint wohl immer neu zu passieren ...

danke ^^ danke danke ^^

_________________
I was too weak to fight | once more i let go
it is a black session | an invitation of sorts