1

I am getting blank tree view for my Start menu folder browser form, I created using TStartMenuFolderTreeView.

I the problem that I do not call the TStartMenuFolderTreeView.SetPaths?

Here is the Inno Setup code:

[Code]

var
  Form2: TSetupForm;
  GFLabel1: TLabel;
  GFButton1, GFButton2: TButton;
  gEdit: TEdit;
  GroupTreeView: TStartMenuFolderTreeView;

procedure Button1Click (Sender: TObject);
begin
  Form2.Close
  WizardForm.Enabled:=True;
  WizardForm.GroupEdit.Text:=gEdit.Text;
end;

procedure Button2Click (Sender: TObject);
begin
  Form2.Close
  WizardForm.Enabled:=True;
end;

procedure EditOnChange(Sender:Tobject);
begin
  gEdit.Text:=AddBackSlash(GroupTreeView.Directory) + '{#GroupName}';
end;

procedure Close (Sender:Tobject; var Action: TCloseAction);
begin
  Form2.close
  WizardForm.Enabled:=True;
end;

procedure GroupButtonClick(Sender:Tobject);
begin
  Form2:=CreateCustomForm;
  with Form2 do
  begin
    Width:=470;
    Height:=296;
    Position:=poScreenCenter;
    CenterInsideControl(WizardForm, False);
    Caption:='Browse For Folder';
    OnClose:=@Close;
  end;

  GFLabel1:=TLabel.Create(Form2);
  with GFLabel1 do
  begin
    Parent:=Form2;
    SetBounds(5,5,100,10)
    Caption:='Select a folder in list below, Then click OK.';
  end;

  GFButton1:=TButton.Create(Form2);
  with GFButton1 do
  begin
    Parent:=Form2;
    SetBounds(285,22,80,25)
    Caption:='OK';
    OnClick:=@Button1Click;
  end;

  GFButton2:=TButton.Create(Form2);
  with GFButton2 do
  begin
    Parent:=Form2;
    SetBounds(370,22,80,25)
    Caption:='Cancel';
    OnClick:=@Button2Click;
  end;

  gEdit:=TEdit.Create(Form2);
  with gEdit do
  begin
    Parent:=Form2;
    SetBounds(5,25,275,15)
    Text:=WizardForm.GroupEdit.Text;
    OnChange:=@EditOnChange;
  end;

  GroupTreeView:=TStartMenuFolderTreeView.Create(Form2);
  with GroupTreeView do
  begin
    Parent:=Form2;
    SetBounds(5,53,445,205)
    OnChange:=@EditOnChange;
  end;

  GroupTreeView.ChangeDirectory(AddBackslash(WizardForm.GroupEdit.Text), true);
  gEdit.Text:=AddBackslash(GroupTreeView.Directory);
  Form2.Show;
  WizardForm.Enabled:=false;
end;

procedure InitializeWizard();
begin
  with WizardForm.GroupBrowseButton do
  begin
    OnClick:=@GroupButtonClick;
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Joe Ny
  • 23
  • 3

1 Answers1

1

Yes, you have to call TStartMenuFolderTreeView.SetPaths:

GroupTreeView.SetPaths(
  ExpandConstant('{userprograms}'),
  ExpandConstant('{commonprograms}'),
  ExpandConstant('{userstartup}'),
  ExpandConstant('{commonstartup}'));

On top of that, your implementation of the form execution is completely wrong.

You have to use TForm.ShowModal for modal dialogs, not TForm.Show. Then, you won't have to do all that main form disabling/enabling (what does not work anyway, your code crashes for me every time I close the dialog).

You also do not need the TButton.OnClick. Use TButton.ModalResult to get the buttons close the dialog automatically. Additionally, for "OK" button, set the TButton.Default, for "Cancel" button, set the TButton.Cancel. This makes Enter and Esc keys working.

with GFButton1 do
begin
  { ... }
  Default := True;
  ModalResult := mrOK;
end;

with GFButton2 do
begin
  { ... }
  Cancel := True;
  ModalResult := mrCancel;
end;

{ ... }

if Form2.ShowModal = mrOK then
begin
  WizardForm.GroupEdit.Text := gEdit.Text;
end;

And remove the Button1Click, Button2Click and Close.


More observations:

  • No need for all those global variables. They all can be local to the GroupButtonClick.
  • Assigning the EditOnChange to the gEdit.OnChange is nonsense. It will prevent you from editing the folder path manually.
  • Do not use fixed sizes and offsets. Always use ScaleX and ScaleY functions.
    E.g. Width := ScaleX(470);
    Otherwise your dialog will be small on high-DPI displays.
    See Inno Setup Placing image/control on custom page.
  • Note that in general, use of the Start menu groups is discouraged in recent version of Windows. There should be a single icon per application only.
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992