Autor Beitrag
Nemesis II
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: So 13.08.06 12:38 
Hallo Leute,

hab wiedermal eine simple Frage, nach stundenlanger Suche :lupe: und keinen Ergebnissen :eyes: im Forum, dachte ich, ich mache einfach ein neues Thema auf!

Ich schreib ein einfaches Prog, welches mir in einer Memo alle gefundenen Dateien (mit komplettem Pfad) anzeigt. Jetzt klappt bei mir nicht diese Anzahl der gefundenen Dateien (ich lese praktisch die Zeilen der Memo aus) auf einem Label zu aktualisieren und gleichtzeitig eine ProgressBar zu füllen.

Hat jemand ein paar Tipps für nen Anfänger, ich wäre sehr dankbar.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 13.08.06 12:47 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
progressbar1.max := //Anzahl aller Pfade

//Aktualisierung
label1.caption := inttostr(memo1.lines.count);
progressbar1.position := progressbar1.position + 1;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Nemesis II Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: So 13.08.06 13:06 
Danke für die schnelle Antwort, aber soweit hab ich das auch schon, nur das die Pfade der Dateien in der Memo untereinander erscheinen, aber die Anzahl der Dateien auf dem Label, sie bleibt 0 weil der Befehl nur einmal und zwar am Anfang ausgeführt wurde, aber danach nicht mehr. Deshalb möchte ich das eben diese Anzahl der Zeilen im Memo ständig aktualisiert auf dem Label angezeigt wird!
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 13.08.06 13:12 
Dann such mal in der Einlese-Routine den Befehl 'memo1.lines.add(irgendwas)'. Dort fügst du die Ausgabe mit dem Label ein.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Nemesis II Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: So 13.08.06 14:18 
Ich habs zwar nicht verstanden wie du es gemeint hast, aber ich hab eine andere Lösung, ich lass einfach den Befehl zum aktualisieren der Variable mit einem Timer alle 50ms wiederholen, die 50ms ist auch die Zeit wie schnell die Dateien gefunden werden! :think:
muss den Code noch etwas verfeiner, und dann füge ich ihn hier ins Thema ein!

Trotzdem vielen Dank
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 13.08.06 14:26 
Würde ich nicht mit einem Timer machen. Poste mal den Code, mit dem du die Dateien ausliest bitte.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Nemesis II Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: So 13.08.06 14:39 
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:
Procedure FindFiles (aPath, aFindMask: String; aWithSub: Boolean; aResult: tStrings);
Var
  FindRec: tSearchRec;

  Begin
   cancel := False;

  If (aPath = '') or (aFindMask = '') or Not Assigned (aResult) Then
    Exit;

  If aPath[Length (aPath)] <> '\' Then
    aPath := aPath + '\';
  If FindFirst (aPath + aFindMask, faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        aResult.Add (aPath + FindRec.Name);
Sleep (50); //Das ist die Zeit in ms, wie schnell die Dateien in der Memo angezeigt/gefunden werden
begin
    Application.ProcessMessages;
  If cancel = true then abort;
end;

    Until FindNext (FindRec) <> 0;
  FindClose (FindRec);
  If Not aWithSub Then
    Exit;
  If FindFirst (aPath + '*.*', faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        If Boolean (FindRec.Attr and faDirectory) Then
          FindFiles (aPath + FindRec.Name, aFindMask, aWithSub, aResult);
    Until FindNext (FindRec) <> 0;
   FindClose (FindRec);

   End;

procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled:= true;
Label1.Caption := 'Status: suchen';
Button1.Enabled := false;
Button2.Enabled := true;
Memo1.Lines.Clear;
FindFiles ('c:\', '*.*', True, Memo1.Lines);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := false;
Label1.Caption := 'Status: abgebrochen';
ShowMessage('Wirklich abbrechen?');
cancel := true;
Button2.Enabled := false;
Button3.Enabled := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var progress : INTEGER;
begin
count := Memo1.Lines.Count;
Label4.Caption := IntToStr(count);
If count >=0 then
ProgressBar1.Max := 100;
for progress := 0 to count do
ProgressBar1.Position := progress;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

END.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 13.08.06 15:03 
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:
private
  Procedure FindFiles (aPath, aFindMask: String; aWithSub: Boolean; aResult: tStrings);


Procedure TForm1.FindFiles (aPath, aFindMask: String; aWithSub: Boolean; aResult: tStrings);
Var
  FindRec: tSearchRec;

  Begin
   cancel := False;
   label1.caption := '0';

  If (aPath = '') or (aFindMask = '') or Not Assigned (aResult) Then
    Exit;

  If aPath[Length (aPath)] <> '\' Then
    aPath := aPath + '\';
  If FindFirst (aPath + aFindMask, faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
      begin
        aResult.Add (aPath + FindRec.Name);
        label1.caption := inttostr(strtoint(label1.caption) + 1);
      end;
//fehlt hier nicht was?!?!
begin
    Application.ProcessMessages;
  If cancel = true then abort;
end;

    Until FindNext (FindRec) <> 0;
  FindClose (FindRec);
  If Not aWithSub Then
    Exit;
  If FindFirst (aPath + '*.*', faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        If Boolean (FindRec.Attr and faDirectory) Then
          FindFiles (aPath + FindRec.Name, aFindMask, aWithSub, aResult);
    Until FindNext (FindRec) <> 0;
   FindClose (FindRec);

   End;

procedure TForm1.Button1Click(Sender: TObject);
begin
  timer1.Enabled:= true;
  Label1.Caption := 'Status: suchen';
  Button1.Enabled := false;
  Button2.Enabled := true;
  Memo1.Lines.Clear;
  FindFiles ('c:\', '*.*', True, Memo1.Lines);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Timer1.Enabled := false;
  Label1.Caption := 'Status: abgebrochen';
  ShowMessage('Wirklich abbrechen?');
  cancel := true;
  Button2.Enabled := false;
  Button3.Enabled := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var progress : INTEGER;
begin
  count := Memo1.Lines.Count;
  Label4.Caption := IntToStr(count);
  If count >=0 then
      ProgressBar1.Max := 100;
  for progress := 0 to count do
    ProgressBar1.Position := progress;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  close;
end;

END.

Formatiere deinen Code mal etwas. Habe ich jetzt schon gemacht.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Nemesis II Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: So 13.08.06 15:23 
also habs jetzt so geändert wie du es gepostet hast, aber da tut sich nichts, und bei dem Sleep(50) Befehl da fehlt eigentlich nichts, ich hab halt nur vergessen das die Variable cancel global ist und den Typ Boolean trägt.