Einzelnen Beitrag anzeigen

Benutzerbild von Jasocul
Jasocul

Registriert seit: 22. Sep 2004
Ort: Delmenhorst
1.337 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Dateipfad in Variable speichern?

  Alt 19. Okt 2022, 12:57
Delphi-Quellcode:
const
  DirArray: array[0..3] of String = ('H:\testend\profil1', 'H:\testend\profil2', 'H:\testend\profil3', 'H:\testend\profil4');

function DirCheck(const AIndex: Integer): Boolean;
begin
  if ((AIndex < Low(DirArray)) or (AIndex > High(DirArray))) then
    Exit(False);
  Result := ForceDirectories(DirArray[AIndex]);
end;
Vielleicht so in der Art... ?
Ich hasse unnötige Exits (In diesem Fall noch übersichtlich, aber ich habe schon schlechte Erfahrungen bei größeren Methoden damit gemacht):
Delphi-Quellcode:
const
  DirArray: array[0..3] of String = ('H:\testend\profil1', 'H:\testend\profil2', 'H:\testend\profil3', 'H:\testend\profil4');

function DirCheck(const AIndex: Integer): Boolean;
begin
  Result := ((AIndex >= Low(DirArray)) and (AIndex <= High(DirArray)));
  if Result then
    Result := ForceDirectories(DirArray[AIndex]);
end;
Peter
  Mit Zitat antworten Zitat