gpt4 book ai didi

casting - Inno Setup/Pascal 脚本 - 类型转换返回 Nil

转载 作者:行者123 更新时间:2023-12-02 18:14:09 29 4
gpt4 key购买 nike

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

最佳答案

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

[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;

关于casting - Inno Setup/Pascal 脚本 - 类型转换返回 Nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11688878/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com