3

我正在尝试为使用 Inno Setup Compiler 5.5.1 制作的安装程序编写一些 Pascal 脚本。我目前正在尝试添加一个执行命令的自定义向导页面,从文本字段(TEdit 组件)获取用户输入。我定义了 NextButtonClick 函数,它检查页面 ID 是否是我定义的自定义页面,并尝试从字段中检索用户输入。当我从 Page 的 Surface 属性的组件中获取它时,它会作为 TComponent 返回。为了获得下一个,我需要将它转换为 TEdit,所以我尝试转换它,它似乎返回 nil。除了过去几天我一直在为 Inno 编写脚本之外,我对 Pascal 没有太多经验,所以我可能做错了什么。但我会很感激帮助!

这是给我一个参考问题的代码块(保留调试行):

function NextButtonClick(CurPageID: Integer): Boolean;
var
    ResultCode: Integer;
    CurrPage: TWizardPage;
    Server : TComponent;
    Server2: TEdit;
    SurfacePage : TNewNotebookPage;
    ServerStr : String;
begin
    if CurPageID = 100 then
    begin
      CurrPage := PageFromID(100);
      SurfacePage := CurrPage.Surface;
      Server := SurfacePage.Controls[0];
      Server2 := TEdit(Server);  // RETURNS NIL HERE
      if Server2 = nil then
        MsgBox('', mbInformation, MB_OK);
      ServerStr := Server2.Text;
      MsgBox(ServerStr, mbInformation, MB_OK);
      //ShellExec('', 'sqlcmd', '-S ' + ServerStr + ' -Q ":r setMemUsage.sql"', ExpandConstant('{app}') + '\sql', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    end;
    Result := True;
end;
4

1 回答 1

1

我无法模拟你的问题。我使用了这个简约的代码:

[Code]
var
  CustomPageID: Integer;

procedure InitializeWizard;
var
  EditBox: TEdit;
  CustomPage: TWizardPage;
begin
  CustomPage := CreateCustomPage(wpWelcome, '', '');
  CustomPageID := CustomPage.ID;
  EditBox := TEdit.Create(WizardForm);
  EditBox.Parent := CustomPage.Surface;
end;

procedure CurPageChanged(CurPageID: Integer);
var
  EditBox: TEdit;
  Component: TComponent;
  CustomPage: TWizardPage;
begin
  if (CurPageID = CustomPageID) then
  begin
    CustomPage := PageFromID(CustomPageID);
    Component := CustomPage.Surface.Controls[0];
    if (Component is TEdit) then
    begin
      MsgBox('Controls[0] is assigned and is TEdit', mbInformation, MB_OK);
      EditBox := TEdit(Component);
      EditBox.Text := 'Hi, I''m just a modified edit text!';
    end;
  end;
end;
于 2012-07-27T13:53:43.483 回答