Reputation: 707
I have a custom uninstall page, which is invoked with this line:
UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigsPage;
Now, this just shows the page every time the uninstaller is run, but I need it to show only if certain folders exist (there's 6 of them). I could make an if
statement with a bunch of or
's, but I'm wondering if there's a neater way to do it.
Upvotes: 1
Views: 1027
Reputation: 202118
In general, there's no better way than calling DirExists
for each folder:
if DirExists('C:\path1') or
DirExists('C:\path2') or
DirExists('C:\path3') then
begin
// ...
end;
Though, when processing a set of files/folders, it's advisable to have their list stored in some container (like TStringList
or array of string
), to allow their (repeated) bulk-processing. You already have that (Dirs: TStringList
) from my solution to your other question.
var
Dirs: TStringList;
begin
Dirs := TStringList.Create();
Dirs.Add('C:\path1');
Dirs.Add('C:\path2');
Dirs.Add('C:\path2');
end;
function AnyDirExists(Dirs: TStringList): Boolean;
var
I: Integer;
begin
for I := 0 to Dirs.Count - 1 do
begin
if DirExists(Dirs[I]) then
begin
Result := True;
Exit;
end;
end;
Result := False;
end;
But I know from your other question, that you map all the paths to checkboxes. Hence, all you need to do, is to check, if there's any checkbox:
if CheckListBox.Items.Count > 0 then
begin
UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigssPage;
// ...
if UninstallProgressForm.ShowModal = mrCancel then Abort;
// ...
UninstallProgressForm.InnerNotebook.ActivePage := UninstallProgressForm.InstallingPage;
end;
Upvotes: 2