Andrea Artoni
Andrea Artoni

Reputation: 165

CreateInputDirPage/TInputDirWizardPage does not create the selected directory

I need to browse or create a new directory at the end of my setup for my database files.

I create an TInputDirWizardPage to choose the directory, and I use a button to launch database installation.

My problem is that the new directory is not created and installation of database fails.

This is my code:

[Code]
var         
    Page0: TInputQueryWizardPage;
    Page1: TInputDirWizardPage;        

{ Launch DB CLIP installation }
procedure ButtonOnClick(Sender: TObject);
var
    Params: string;
    ScriptPath: string;
    ResultCode: Integer;
    DBPath: string;
    Server: String;
    Instance: String;
    SQL_User: String; 
    SQL_Password: String;

begin
    DBPath := Page1.Values[0];
    Server:= Page0.Values[0];
    Instance:= Page0.Values[1];
    SQL_User:= Page0.Values[2]; 
    SQL_Password:= Page0.Values[3];
    ScriptPath := ExpandConstant('"{app}\DB\Create Database 2.12.3.sql"');
    Params := '-v CLIPDATA="'+DBPath+'" CLIPINDEX="'+DBPath+'" CLIPLOG="'+DBPath+'" -S '+Server+'\'+Instance+' -U '+SQL_User+' -P '+SQL_Password+' -i '+ScriptPath ;

    if  MsgBox('' + Params + '', mbInformation, mb_YesNo) = idYes then
        Exec ('sqlcmd',Params, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
    Exit;
end;

procedure InitializeWizard();
var
    DBButton: TNewButton;        
begin
    Page0 := CreateInputQueryPage(wpInfoAfter,
        'SQL Informations', '',
        'Please specify Server and Instance name , then click Next.');

    Page0.Add('Server:', False);
    Page0.Add('Instance:', False);
    Page0.Add('SQL User:', False);
    Page0.Add('SQL Password:', True);
    Page0.Values[0] := ('localhost');
    Page0.Values[1] := ('CLIP');
    Page0.Values[2] := ('sa');
    Page0.Values[3] := ('clip');

    Page1 := CreateInputDirPage(Page0.ID,
        'Select CLIP Database files Location', '',
        'CLIP DB data files will be stored in the following folder.'#13#10#13#10 +
        'To continue, click Next. ' +
        'If you would like to select a different folder, click Browse.',
        False, 'New Folder');

    Page1.Add('Database Folder');
    Page1.Values[0] := ExpandConstant('{pf}\CLIP\CLIP_DATA\DB\');

    DBButton := TNewButton.Create(Page1);
    DBButton.Left := ScaleX(16);
    DBButton.Top := ScaleY(205);
    DBButton.Width := ScaleX(100);
    DBButton.Height := ScaleY(25);
    DBButton.Caption := 'Install DB CLIP';
    DBButton.OnClick := @ButtonOnClick;
    DBButton.Parent := Page1.Surface;
end;

Upvotes: 3

Views: 751

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202330

CreateInputDirPage does not create the selected directory on its own.

The Make New Folder button does not create a physical folder. It only creates a virtual node in the tree.

I'm aware that this somewhat contradicts the documentation, which says:

Make New Folder button will be shown that creates a new folder with the specified default name.


If you want to really create a physical folder for the selected path, use CreateDir function in your ButtonOnClick handler.

if not DirExists(DBPath) then
begin
  CreateDir(DBPath);
end;

Upvotes: 3

Related Questions