Autor Beitrag
Muffi
Hält's aus hier
Beiträge: 14

Win XP Prof
Delphi 4-7
BeitragVerfasst: Mi 08.10.03 11:31 
Moin Jungs :D

Bin mal wieder vom Programmiervirus befallen. Habe schon mal vor längerer Zeit angefangen mit Delphi zu programmieren. Hatte dann aber keine Zeit mehr wegen Beruf und so. Jetzt will ich mal wieder so richtig loslegen. Leider merke ich, dass ich doch vieles wieder vergessen habe. Drum bin ich hier :D und meine heutige Frage ist:

Habe in der Delphi-Hilfe ein Beispiel gefunden welches Dateioperationen mit FindFirst/FindNext realisiert. Habe diese Beispiel in ein Delphi-Grundgerüst eingebaut. Aber leider funktioniert das nicht. :? :?

Wer kann da einem Newbie mal helfen, damit ich das Beispiel wenigstens zum Laufen kriege.
Den Rest schraub ich mir dann schon selbst zusammen. 8) 8)

Glaube habe irgendeine Deklaration übersehen oder nicht richtig implementiert.
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

procedure TForm1.Button1Click(Sender: TObject);

var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  StringGrid1.RowCount := 1;
  if CheckBox1.Checked then
    FileAttrs := faReadOnly
  else
    FileAttrs := 0;
  if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
  if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
  if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
  if CheckBox5.Checked then

    FileAttrs := FileAttrs + faDirectory;
  if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
  if CheckBox7.Checked then

    FileAttrs := FileAttrs + faAnyFile;

  with StringGrid1 do
  begin
    RowCount := 0;

    if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

    begin
      repeat
        if (sr.Attr and FileAttrs) = sr.Attr then
        begin
        RowCount := RowCount + 1;
        Cells[1,RowCount-1] := sr.Name;
        Cells[2,RowCount-1] := IntToStr(sr.Size);
        end;
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;
  end;
end;


implementation

{$R *.dfm}

end.

Schnelle Hilfe wäre suuuper !!!!!!

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
joerg68
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 116

Win 2000
D5Enterprise
BeitragVerfasst: Mi 08.10.03 12:06 
Titel: Deklaration
Du bist schon auf der richtigen Spur. Die Implementation Deiner prozedur kommt natürlich erst nach dem Keyword implementation
Im Deklarationsteil (also oben) darfs du nur die erste Zeile deier prozedur also Name der Prozedur, Übergabeparameter und bei Funktionen den Typ des Rückgabewerts angeben.
Gruss
Jörg

PS außerdem solltest du darauf achten das die prozedur auch dem onclick ereignis Deines Buttons zugewiesen wurde. Wenn du einfach den Code kopierst passiert das nämlich nicht automatisch

_________________
Aus den Chaos sprach eine Stimme " Lächele und sei froh denn es könnte schlimmer kommen". Und ich lächelte und ich war froh.
UND ES KAM SCHLIMMER
Muffi Threadstarter
Hält's aus hier
Beiträge: 14

Win XP Prof
Delphi 4-7
BeitragVerfasst: Mi 08.10.03 13:08 
HI Jörg68!!!!

Welch ein Zufall. Denn eigentlich würde ich Jörg71 heißen. Aber ich hab mich dann doch für Muffi entschieden :wink:

Naja habe auch etwas am Sourcecode probiert. So schlimm ist das gar nicht. So langsam kommen die Erinnerungen wieder wie das alles so läuft. 8)

Daraus ist der folgende Quellcode entstanden
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:
unit BSPCOPY;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    Edit1: TEdit;
     procedure Button1Click(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

procedure TForm1.Button1Click(Sender: TObject);

var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  StringGrid1.RowCount := 1;
  if CheckBox1.Checked then
    FileAttrs := faReadOnly
  else
    FileAttrs := 0;
  if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
  if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
  if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
  if CheckBox5.Checked then

    FileAttrs := FileAttrs + faDirectory;
  if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
  if CheckBox7.Checked then

    FileAttrs := FileAttrs + faAnyFile;

  with StringGrid1 do
  begin
    RowCount := 0;
    if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

    begin
      repeat
        if (sr.Attr and FileAttrs) = sr.Attr then
        begin
        RowCount := RowCount + 1;
        Cells[1,RowCount-1] := sr.Name;
        Cells[2,RowCount-1] := IntToStr(sr.Size);
        end;
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;
  end;
end;

{$R *.dfm}

end.

So weit so gut. Das Programm startet. Aber trotz Auswahl per Checkbox und Eingabe eines Pfades in Edit passiert nix. Keine Anzeige !!!!!!!

Wat nu :( :( :(

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 08.10.03 13:46 
Hallo und :welcome: hier im Delphi-Forum.de!

Hast du im Objektinspektor beim OnClick-Event des Buttons auch die Procedure Button1Click ausgewählt?

Gruß
Tino
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mi 08.10.03 14:02 
Hi,

das hier
ausblenden Delphi-Quelltext
1:
{$R *.dfm}					

sollte unmittelbar nach Iplementation stehen. Ausserdem solltest du den Rahmencode der Komponenten-Ereignisse immer über den Objekt-Inspektor erstellen. Dann kann sowas nämlich gar nicht erst passieren.

Einfach im OI in den Ereignisse-Reiter wechseln. Zum gewünschten Ereignis gehen und doppelt darauf klicken.

MFG

- Ernesto -