Autor Beitrag
patrick dee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Sa 09.06.07 07:23 
Morgen zusammen,

Habe in der ListBox eine Liste geladen. Nun soll mit Button Klick diese durchlaufen werden. Wenn ein Eintrag mit einer 5 beginnt, sollen die ersten 7 Zeichen an Label 1 übergeben werden. Ansonsten alle anderen Einträge - also alle die nicht mit einer 5 beginnen soolen 1 : 1 an die ListBox 2 als Add übergeben werden.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
ver
 sl, zeile: TStringlist;
 maxInterpretLength, maxTitelLength, x, y, i, t: integer;
 s, Interpret, Titel: string;
  Azeile    : string;
 teilzeile : string;
 k : Integer ;
beginn
  for k := 0 to ListBox1.Items.Count -1 do
begin
  ListBox1.Itemindex := k;
Azeile := ListBox1.Items.Strings[Listbox1.ItemIndex];
teilzeile := copy(Azeile,0,7);
Label1.Caption := teilzeile;
Application.ProcessMessages;
Sleep(10);
end;
end;



So habe ich es mal gebastelt. Funzt auch. ABER da auch in der Liste Einträge sind die nicht mit einer 5 beginnen sollen die natürlich auch in die ListBox2 übernommen werden.
So nun kommt die Frage was passiert mit dem Eintrag aus dem Label1. ?


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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
s := Trim(Ansiuppercase(Label1.Caption)); // ABFRAGE TEXT

  s := stringreplace(s, #32#32, #32, [rfReplaceall]);

  sl := TStringlist.create;

  zeile := TStringlist.create;

  sl.loadfromfile(Edit2.text); // hier ligt die hdtitel.txt

  for x := 0 to sl.count - 1 do begin

    zeile.clear;

    SplitString(sl[x], ['#'], zeile);

    for y := 0 to zeile.count - 1 do begin

      i := ansipos(s, zeile[y]);

      if (i = 1) or (i > 1) and (zeile[y][i - 1] = #32)

        then begin

        Interpret := copy(zeile[1], 1, maxInterpretLength);

        Titel := copy(zeile[2], 1, maxTitelLength);

        Listbox2.items.add(zeile[0] + '  ' + Interpret

          + stringofchar(#32, maxInterpretLength - length(Interpret)) +

          '  ' + Titel + stringofchar(#32, maxTitelLength - length(Titel)) +

          '  ' + zeile[3]);

        break;

      end;

    end;

  end;

  Listbox2.items.endupdate;
  //ListBox2.Items.SaveToFile('C:\Back\' + datum + '.pl1');
  zeile.free;

  sl.free;
 end;
 end;



Ich hoffe es kann mir jemand weiterhelfen.
Danke schon mal im Voraus

Patrick

_________________
Glauben heißt nichts wissen ...
zongo-joe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 134

win xp prof
D3, D4, D7
BeitragVerfasst: Sa 09.06.07 11:26 
hm, so ganz hab ich Deinen Code nich verstanden, aber für Deine Aufgabenstellung hätte ich eine kürzere Lösung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=1 to listbox1.items.count do
  if listbox1.items[i-1][1]='5' then 
    label1.caption := copy(listbox1.items[i-1],1,7)
    else listbox2.items.add( listbox1.items[i-1] );
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Sa 09.06.07 11:52 
Hei zongo-joe

danke für deine Hilfe aber hier kracht es :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.Button2Click(Sender: TObject);
var
 sl, zeile: TStringlist;
 maxInterpretLength, maxTitelLength, x, y, i,k : integer;
 s, Interpret, Titel: string;

 begin
for k:=1 to listbox1.items.count do
  if listbox1.items[k-1][1]='5' then
    label1.caption := copy(listbox1.items[k-1],1,7)
    else listbox2.lines.add( listbox1.items[i-1] );
    ListBox1.Itemindex := k;




   Listbox2.lines.beginupdate;
  // Label2.caption := 'Lade Titel '+  inttostr(listbox2.lines.count);


FEHLER MELDUNG !!!!!

--- List Index out of Bounds -----

_________________
Glauben heißt nichts wissen ...
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Sa 09.06.07 11:57 
NACHTRAG :

auch wenn ich nur den Teil benutze um zu sehen was im Label überhaupt eingtragen wird,
kracht das Programm zusammen :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  begin
  for k:=1 to listbox1.items.count -1 do
  if listbox1.items[k-1][1]='5' then
    label1.caption := copy(listbox1.items[k-1],1,7);
  end;


lg Patrick

_________________
Glauben heißt nichts wissen ...
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Sa 09.06.07 11:59 
die Einträge in der ListBox sehen so aus :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
5340-13 MITTEN IN DER NACHT NIK P 04:23
5035-05 WHERE DO BROKEN HEARTS GO WHITNEY HOUSTON 04:34
5555-55 SONGS ZUM TRÄUMEN .... 00:17
5060-17 GELL DU MOGST MI LUDWIG HIRSCH 03:51
5000-15 BRIDGE OVER TROUBLED WATER SIMON & GARFUNKEL 04:51
5307-17 *ROCKING SAX PEPE SOLERA 03:29
0000-00 ------------------------------------------------ 00:00
          1 Uhr
blabla *Uhr*

5024-18 HOTEL CALIFORNIA EAGLES 05:36
5053-13 MEIN GEFÜHL PETER CORNELIUS 04:18
5075-15 *LE MATIN SUR LA RIVIERE EVE BRENNER 03:56

_________________
Glauben heißt nichts wissen ...
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Sa 09.06.07 12:42 
ist doch klar dass es kracht:

listbox.count gibt dir die anzahl der einträge in der listbox wieder, aber die Einträge sind "durchnummeriert" und zwar beginnend mit der null. Sind drei Einträge in der listbox, haben die Einträge also die Nummern 0,1,2

dein schleifendurchlauf muss also nicht so:

ausblenden Delphi-Quelltext
1:
for k:=1 to listbox1.items.count -1 do					


sondern so aussehen:
ausblenden Delphi-Quelltext
1:
for k:=0 to listbox1.items.count -1 do					
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Sa 09.06.07 12:48 
Hei Jann1k

Danke für den Tip. Hast natüröich recht gehabt damit. aber es kracht immer noch.
FEHLER :

ListIndex Out of Bounds (-1)

bei der Zeile : if listbox1.items[k-1][1]='5' then

Danke

Patrick

_________________
Glauben heißt nichts wissen ...
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Sa 09.06.07 20:38 
mach aus k-1 einfach k, bei k=0 macht k-1 ) -1 die listbox hat keinen eintrag mit nummer -1
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 10.06.07 05:55 
Hallo Jan11k

habe es nun so probiert :


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
 begin
    for k:=1 to listbox1.items.count do
    if listbox1.items[k][1]='5' then
    label1.caption := copy(listbox1.items[k],1,7)
    else listbox2.lines.add( listbox1.items[k] );
    ListBox1.Itemindex := k;
   Listbox2.lines.beginupdate;
    Label2.caption := 'Lade Titel '+  inttostr(listbox2.lines.count);
 end;


ein Paa Einträge gibt es und dann säuft das Programm wieder ab. Also, ich blicke es nimmer warum.

Patrick

_________________
Glauben heißt nichts wissen ...
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 10.06.07 08:48 
user profile iconJann1k hat folgendes geschrieben:
sondern so aussehen:
ausblenden Delphi-Quelltext
1:
for k:=0 to listbox1.items.count -1 do					

Außerdem k in Zeile 6 nicht mehr verwenden, weil das außerhalb der Schleife liegt.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 10.06.07 09:37 
Morgen Danke GTAPlace

für deine Hilfe. Habe festgestellt das es bei dieser Zeile Kracht :

ausblenden Delphi-Quelltext
1:
  if listbox1.items[k][1]='5' then					


Habe es bisher so stehen :

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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
procedure TForm1.Button2Click(Sender: TObject);
var
 datum     : string;
 sl, zeile: TStringlist;
 maxInterpretLength, maxTitelLength, x, y, i,k : integer;
 s, Interpret, Titel: string;

begin
 datum:= FormatDateTime('dd-mm-yy',NOW);
 begin  
 for k:=0 to listbox1.items.count -1 do
  if listbox1.items[k][1]='5' then
   label1.caption := copy(listbox1.items[k],0,7)
    else listbox2.lines.add( listbox1.items[k]);
     Application.ProcessMessages;
      Sleep(100);
       ListBox1.Itemindex := k;

       Label2.caption := 'Lade Titel '+  inttostr(listbox2.lines.count);
     
//Listbox2.lines.beginupdate;
    
// --- zum Ausrichten ----------------

  Listbox2.Font.Name := 'Courier New';

  maxInterpretLength := 17; // z.B.

  maxTitelLength := 27; // z.B.

// -----------------------------------

  s := Trim(Ansiuppercase(Label1.Caption)); // ABFRAGE TEXT

  s := stringreplace(s, #32#32, #32, [rfReplaceall]);

  sl := TStringlist.create;

  zeile := TStringlist.create;

  sl.loadfromfile(Edit2.text); // hier ligt die hdtitel.txt

  for x := 0 to sl.count - 1 do begin

    zeile.clear;

    SplitString(sl[x], ['#'], zeile);

    for y := 0 to zeile.count - 1 do begin

      i := ansipos(s, zeile[y]);

      if (i = 1) or (i > 1) and (zeile[y][i - 1] = #32)

        then begin

        Interpret := copy(zeile[1], 1, maxInterpretLength);

        Titel := copy(zeile[2], 1, maxTitelLength);

        Listbox2.lines.add(zeile[0] + '  ' + Interpret

          + stringofchar(#32, maxInterpretLength - length(Interpret)) +

          '  ' + Titel + stringofchar(#32, maxTitelLength - length(Titel)) +

          '  ' + zeile[3]);



        break;

      end;

    end;

  end;

  Listbox2.lines.endupdate;

  zeile.free;

  sl.free;
    ListBox2.lines.SaveToFile(edit4.text + datum + '.pl1');
 end;
 end;


Es ist zum Haare raufen :roll:

_________________
Glauben heißt nichts wissen ...
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: So 10.06.07 10:48 
Ich würde mal darauf tippen, dass in Deiner Schleife:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for k:=0 to listbox1.items.count -1 do 
begin
...
end;

fehlt.
zongo-joe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 134

win xp prof
D3, D4, D7
BeitragVerfasst: So 10.06.07 11:16 
Also...

wenn Du das

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Application.ProcessMessages;
 Sleep(100);
 ListBox1.Itemindex := k; // wozu brauchst Du das ? Du verwendest es nie

 Label2.caption := 'Lade Titel '+  inttostr(listbox2.lines.count); // vllt eher 'Lade Titel '+inttostr(k); ?


mit in der Schleife haben willst, musst es natürlich, wie aim65 gesagt hat, mit BEGIN..END zusammenfassen.

und wenn die Fehlermeldung in der Zeile

ausblenden Delphi-Quelltext
1:
 if listbox1.items[k][1]='5' then					

kommt, dann versuch doch mal das ganze in Einzelschritte zu zerlegen, um zu sehen, wo der Fehler genau liegt:

zum Beispiel mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
(var dummy:string)

dummy:=listbox1.items[k];
if dummy [1]='5' then
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 10.06.07 12:15 
Hei zongo-joe


es war das fehlende

begin

...

end;

gewesen. Nun läuft es erstmal ABER nach einer weile bricht das ganze Programm ab. Es arbeitet die Liste in der ListBox ca. 40 Einträge ab - obwohl mehr drinnen sind - und dann kommt Fehler in Modul.

"Access Violation at Adress 0064ba9 in Module Projekt1.Exe Read of Adress FFFFFFFFF
Proess stopped"


Denke aber es liegt daran das da drei Leerzeilen kommen .

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
5299-04 MY LOVE WESTLIFE 03:49
5333-05 NIE MEHR BERNHARD BRINK 03:48
5352-16 KEEP ON RUNNING SPENCER DAVIS GROUP 02:41
0000-00 ------------------------------------------------ 00:00


 
          9 Uhr
Datei: F:\WAVES\Wetter.wav 
5118-02 SVALUTATION ADRIANO CELENTANO 03:04
5132-04 DANCE (WHILE THE MUSIC STILL GOES ON) ABBA 03:08


Und wenn er auf diese trifft säuft das Programm ab, aber es soll sie einfach mit in die ListBox2 schreiben.

Patrick

_________________
Glauben heißt nichts wissen ...
zongo-joe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 134

win xp prof
D3, D4, D7
BeitragVerfasst: So 10.06.07 12:50 
dann würde ich vor der IF-Abfrage eine Prüfung der Stringlänge einbauen:

if length(Listeneintrag) > 0 then...