我正在尝试为使用 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;