【问题标题】:Inno Setup -- cannot see drive comboboxInno Setup - 看不到驱动器组合框
【发布时间】:2017-08-28 22:49:24
【问题描述】:

我想查看驱动器组合框,以便用户选择要安装的驱动器。

但是当我运行安装时,我根本看不到组合框?

也许有人可以看出这段代码有什么问题?我从另一个网站复制了它,但它只是没有显示驱动器组合框,因此我无法选择要安装的驱动器。

这是我的代码:

var
// combo box for drives
cbDrive : TComboBox ;
// array fo string that keep the drive letters
DrvLetters: array of String;

function GetDriveType( lpDisk: String ): Integer;
external 'GetDriveTypeA@kernel32.dll stdcall';

function GetLogicalDriveStrings( nLenDrives: LongInt; lpDrives: String ): Integer;
external 'GetLogicalDriveStringsA@kernel32.dll stdcall';

const
  DRIVE_UNKNOWN = 0; // The drive type cannot be determined.
  DRIVE_NO_ROOT_DIR = 1; // The root path is invalid. For example, no volume is mounted at the path.
  DRIVE_REMOVABLE = 2; // The disk can be removed from the drive.
  DRIVE_FIXED = 3; // The disk cannot be removed from the drive.
  DRIVE_REMOTE = 4; // The drive is a remote (network) drive.
  DRIVE_CDROM = 5; // The drive is a CD-ROM drive.
  DRIVE_RAMDISK = 6; // The drive is a RAM disk.


// function to convert disk type to string
function DriveTypeString( dtype: Integer ): String ;
begin
  case dtype of
    DRIVE_NO_ROOT_DIR : Result := 'Root path invalid';
    DRIVE_REMOVABLE : Result := 'Removable';
    DRIVE_FIXED : Result := 'Fixed';
    DRIVE_REMOTE : Result := 'Network';
    DRIVE_CDROM : Result := 'CD-ROM';
    DRIVE_RAMDISK : Result := 'Ram disk';
  else
    Result := 'Unknown';
  end;
end;

// change folder accordigly to the drive letter selected
procedure cbDriveOnClick(Sender: TObject);
begin
WizardForm.DirEdit.Text := DrvLetters[ cbDrive.ItemIndex ] + UpperCase(ExpandConstant('{#MyAppName}'));
end;

procedure FillCombo();
var
  n: Integer;
  drivesletters: String; lenletters: Integer;
  drive: String;
  disktype, posnull: Integer;
  sd: String;

begin
  //get the system drive
  sd := UpperCase(ExpandConstant('{sd}'));

  //get all drives letters of system
  drivesletters := StringOfChar( ' ', 64 );
  lenletters := GetLogicalDriveStrings( 63, drivesletters );
  SetLength( drivesletters , lenletters );

  drive := '';
  n := 0;
  while ( (Length(drivesletters) > 0) ) do
  begin
    posnull := Pos( #0, drivesletters );
  if posnull > 0 then
  begin
      drive:= UpperCase( Copy( drivesletters, 1, posnull - 1 ) );

      // get number type of disk
      disktype := GetDriveType( drive );

      // add it only if it is not a floppy
      if ( not ( disktype = DRIVE_REMOVABLE ) ) then
      begin

    cbDrive.Items.Add( drive + '   [' + DriveTypeString( disktype ) + ']' )

        SetArrayLength(DrvLetters, N+1);
        DrvLetters[n] := drive;

        // default select C: Drive
        //if ( Copy(drive,1,2) = 'C:' ) then cbDrive.ItemIndex := n;
        // or default to system drive
        if ( Copy(drive,1,2) = sd ) then cbDrive.ItemIndex := n;

        n := n + 1;
      end

    drivesletters := Copy( drivesletters, posnull+1, Length(drivesletters));
  end
  end;

  cbDriveOnClick( cbDrive );

end;


procedure InitializeWizard();
begin

// create the combo box for drives
cbDrive:= TComboBox.Create(WizardForm.SelectDirPage);
    with cbDrive do
    begin
      Parent := WizardForm.DirEdit.Parent;

      Left := WizardForm.DirEdit.Left;
      Top := WizardForm.DirEdit.Top + WizardForm.DirEdit.Height * 2;
      Width := WizardForm.DirEdit.Width;

      Style := csDropDownList;
    end;

// hide the Browse button
WizardForm.DirBrowseButton.Visible := true;

// Edit box for folder don't have to be editable
WizardForm.DirEdit.Enabled := true;

// fill combo box with Drives
FillCombo;

// set the event on combo change
cbDrive.OnClick := @cbDriveOnClick ;
end;

procedure MyAfterInstall2(FileName: String);
begin
  MsgBox('Just installed ' + FileName + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

【问题讨论】:

    标签: inno-setup


    【解决方案1】:

    为我工作。至少在 Inno Setup 的 Unicode 版本中,一旦我通过以下方式使代码与 Unicode 版本兼容:

    • end 之后在drivesletters := Copy( drivesletters, posnull+1, Length(drivesletters)); 之前添加缺少的;
    • 使用GetDriveTypeGetLogicalDriveStrings 的Unicode 版本,将A@ 替换为W@

    【讨论】:

    • 我进行了这些更改,但现在在这一行出现超出范围的运行时错误:WizardForm.DirEdit.Text := DrvLetters[ cbDrive.ItemIndex ] + UpperCase(ExpandConstant('{#MyAppName}' ));
    • 在您的屏幕截图中,我看到文本“我的程序应该安装在哪里?”我的代码中没有看到该文本。
    • 这是SelectDirPage 的标准内容,您的代码会在其中添加组合框。 + 您使用的是 Unicode 版本的 Inno Setup?
    • 我不知道我是否使用 Unicode 版本。我怎么知道?
    • 它应该在窗口标题中显示 (a) 或 (u)。或选中“关于”框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    相关资源
    最近更新 更多