Autor Beitrag
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Fr 08.04.05 14:25 
Kann mir jemand sagen wie ich ListView-Einträge zählen kann??
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure Tfrm_Main.lvRaum1Insert(Sender: TObject; Item: TListItem);
begin
  if {anzahl einträge} then
      begin
      end;
end;
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Fr 08.04.05 14:26 
ausblenden Delphi-Quelltext
1:
ListView.Items.Count;					


Liefert integer zurück!

_________________
Aus dem Urlaub zurück!
csigg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Fr 08.04.05 14:35 
OK, dankeschön
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Sa 27.01.07 00:08 
Zitat:
ListView.Items.Count


genau damit habe ich ein Problem gerade. Und zwar wird der Wert, der durch Count zurückgeliefert wird, durch ListView.Items.Clear nur temporär zurückgesetzt. Angenommen ich habe 30 Einträge, und mache dann items.clear, dann liefert Count 0. Dann mache ich items.add; und er zeigt bei Count 31 Einträge an. Das ganze habe ich reproduzierbar. Wie kann man das umgehen? :?

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 27.01.07 11:01 
Das kann ja fast nicht sein. Poste doch bitte mal den Quelltextabschnitt in dem du das machst (mit ein bisschen von deinem Code aussenrum)
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Sa 27.01.07 17:53 
eigentlich nichts besonderes:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  
  lb_EmuFamilys.items.clear;
  i:=0;
  while i<=high(tmpEmuFamilys) do begin
    if high(tmpEmuFamilys[0])>=0 then begin
      if trim(tmpEmuFamilys[i,0])<>'' then begin
        lb_EmuFamilys.Items.Add;
        lb_EmuFamilys.Items.Item[lb_EmuFamilys.Items.Count-1].SubItems.clear;
        lb_EmuFamilys.Items.Item[lb_EmuFamilys.Items.Count-1].Caption:=(trim(tmpEmuFamilys[i,0]));
      end;
    end;
    i:=i+1;
  end;


Ich habe Delphi 7 Prof. mit SP1. Es handelt sich um ein tlistview.

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 27.01.07 18:24 
Also mir siehst das so aus, als würdest du hier mehrfach Items.Add benutzen. Und wenn du die 30 Einträge nach dem Clear wieder hinzufügst, dann sind die natürlich auch wieder da.
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Sa 27.01.07 18:53 
ja klar rufe ich das mehrmals auf. Ok also zur Verdeutlichung: ich verändere die Routine folgendermaßen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
  lb_EmuFamilys.items.clear;
  i:=0;
  while i<=high(tmpEmuFamilys) do begin
    if high(tmpEmuFamilys[0])>=0 then begin
      if trim(tmpEmuFamilys[i,0])<>'' then begin
        lb_EmuFamilys.Items.Add;
        lb_EmuFamilys.Items.Item[lb_EmuFamilys.Items.Count-1].SubItems.clear;
        lb_EmuFamilys.Items.Item[lb_EmuFamilys.Items.Count-1].Caption:=(trim(tmpEmuFamilys[i,0]));
      end;
    end;
    i:=i+1;
  end;
  showmessage(inttostr(i));
  showmessage(inttostr(lb_EmuFamilys.Items.Count));


rufe ich die Routine das erste mal auf, zeigt er mir 30 und 29 in der Messagebox an. Rufe ich sie ein zweites Mal auf, zeigt er 30 und 58 in der Messagebox. An der ersten Zahl sieht man, das sich am Array nix verändert hat.

Gestern habe ich nicht gesehen, das beim zweiten mal alle Einträge doppelt drin sind, ich habe nur gesehen das die erste Zeile frei war und dann die Einträge kamen. Es sind also beim zweiten Aufruf alle Einträge doppelt drin obwohl ich clear mache und sich am Array nix verändert hat (demnach scheint count doch richtig zu zählen). Woran liegt das?

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 28.01.07 11:10 
was ist denn tmpEmuFamilys ist das dein ListView ?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 28.01.07 11:28 
user profile iconmatze hat folgendes geschrieben:
was ist denn tmpEmuFamilys ist das dein ListView ?

user profile iconAmiga-Fan hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
  while i<=high(tmpEmuFamilys) do begin					

user profile iconAmiga-Fan hat folgendes geschrieben:
An der ersten Zahl sieht man, das sich am Array nix verändert hat.

Nein, ein Array ;-)
lb_EmuFamilys ist die ListView, der Name mit lb_ ist zwar irreführend, aber was solls.

Nachvollziehen kann ich den Fehler jedenfalls nicht, hier mein Testprojekt, und da geht alles wie es soll:
ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
var
  Form1: TForm1;
  tmpEmuFamilys: array[0..29of array[0..1of String;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: Integer;
begin
  for i := 0 to High(tmpEmuFamilys) do
    for j := 0 to High(tmpEmuFamilys[i]) do
      tmpEmuFamilys[i, j] := 'aaa';


  lb_EmuFamilys.items.clear;
  i:=0;
  while i<=high(tmpEmuFamilys) do
  begin
    if high(tmpEmuFamilys[0])>=0 then
    begin
      if trim(tmpEmuFamilys[i,0])<>'' then
      begin
        lb_EmuFamilys.Items.Add;
        lb_EmuFamilys.Items.Item[lb_EmuFamilys.Items.Count-1].SubItems.clear;
        lb_EmuFamilys.Items.Item[lb_EmuFamilys.Items.Count-1].Caption:=(trim(tmpEmuFamilys[i,0]));
      end;
    end;
    i:=i+1;
  end;
  showmessage(inttostr(i));
  showmessage(inttostr(lb_EmuFamilys.Items.Count));
end;

Beide Ausgaben sind 30, egal wie oft ich klicke. Aber was anderes hatte ich auch nicht erwartet...

// EDIT: Ach so: Habe auch Delphi 7 genommen, weil du geschrieben hast, dass du es benutzt. ;-)
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: So 28.01.07 15:40 
das war vor kurzem noch eine listbox, habe das ausgetauscht. Nunja aber bei mir gibt es wie gesagt andere zahlen. Werde weiter suchen.... aber sp1 hast du nicht drauf, oder? Vielleicht hat es auch mit dem bs zu tun... nehme an, das er eine windows-kompo kapselt, oder?

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Do 15.02.07 19:09 
wenn ich lb_EmuFamilys.clear statt lb_EmuFamilys.items.clear mache scheints zu gehen.

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen