Autor Beitrag
fritz_07
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Do 17.12.09 00:30 
Hallo an alle!

Das Formular erstellt mehrere Ordner,es funktioniert auch soweit.
Nur,wie sieht eine Prozedur aus,die abfragt,ob alle Verzeichnisse erstellt wurden.

Hier der Quellcode:
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:
23:
24:
25:
procedure TForm2.Button1Click(Sender: TObject);
var Dir1, Dir2, Dir3, a, b : String;

begin
  a := 'Projektordner wurde erstellt.';
  b := 'Projektordner wurde nicht erstellt.';
  Dir1 := Edit1.Text;
  Dir2 := Edit2.Text;
  Dir3 := Edit3.Text;

  begin
     SysUtils.ForceDirectories(Dir1);
     SysUtils.ForceDirectories(Dir2);
     SysUtils.ForceDirectories(Dir3);
  end;

//dieses Beispiel überprüft nur ein Verzeichnis,ich habe aber mehrere
if DirectoryExists(Dir1) then
        begin
          showmessage(a);
        end
      else
        showmessage(b);
 
end;



Mfg fritz_07


Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am Do 17.12.2009 um 12:14
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 17.12.09 01:34 
Hallo und :welcome: !

Was meinst du wohl warum ForceDirectories einen Boolean-Wert zurückgibt? :zwinker:
Das gibt direkt den Erfolg an...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm2.Button1Click(Sender: TObject);
var
  Dir1, Dir2, Dir3, a, b : String;
begin
  a := 'Projektordner wurde erstellt.';
  b := 'Projektordner wurde nicht erstellt.';
  Dir1 := Edit1.Text;
  Dir2 := Edit2.Text;
  Dir3 := Edit3.Text;

  if SysUtils.ForceDirectories(Dir1)
    and SysUtils.ForceDirectories(Dir2)
    and SysUtils.ForceDirectories(Dir3) then
    ShowMessage(a)
  else
    ShowMessage(b);
end;
fritz_07 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Fr 18.12.09 17:46 
Hallo!

Danke,soweit funktioniert es auch gut.
Wenn aber eine Dir-Variable leer ist,bekomme ich die Exeption (Verzeichnis konnte nicht erstellt werden).
Wie muß ich die Prozedur jetzt ändern,das sie diese Fehlermeldung nicht mehr anzeigt?


Mfg fritz_07
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 19.12.09 01:00 
Du kannst zusätzlich noch jeweils abfragen ob Dir1 usw. nicht leer ist (Dir1 <> '').
fritz_07 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 22.12.09 00:17 
Hallo!

Mit der Anweisung prüfe ich jetzt,ob Inhalt von z.B. Dir1 leer ist.
Ist dies so gemeint?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if (Dir1=''then  Form3.Label1.Caption := b
      else
      
      SysUtils.ForceDirectories(Dir1);


Ich habe 3 Dir-Variablen,wie gestalte ich die Abfrage,wenn folgender Fall vorliegt?

Dir1 und Dir2 sind leer,aber Dir3 nicht?


Mfg fritz_07