Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inno setup 如何通过它查找组件索引';她叫什么名字?_Inno Setup - Fatal编程技术网

Inno setup 如何通过它查找组件索引';她叫什么名字?

Inno setup 如何通过它查找组件索引';她叫什么名字?,inno-setup,Inno Setup,为什么我不能使用此行获取组件的索引之一: WizardForm.ComponentsList.FindComponent('core').ComponentIndex 如果我错了,有人能为我指出一种获取组件索引的方法吗?目前,无法通过组件名称参数在组件列表中找到组件项的索引。Name参数存储在结构中,该结构由ComponentsList.ItemObject[i]对象集合持有,但由于Inno Setup Pascal脚本中缺少指针支持,因此无法访问该结构 在ComponentsList中唯一标

为什么我不能使用此行获取组件的索引之一:

WizardForm.ComponentsList.FindComponent('core').ComponentIndex

如果我错了,有人能为我指出一种获取组件索引的方法吗?

目前,无法通过组件
名称
参数在
组件列表
中找到组件项的索引。
Name
参数存储在结构中,该结构由
ComponentsList.ItemObject[i]
对象集合持有,但由于Inno Setup Pascal脚本中缺少指针支持,因此无法访问该结构

ComponentsList
中唯一标识组件的方法是通过其
Description
参数。要根据某个组件在
组件列表中的描述查找该组件的索引,可以使用以下方法:

[Components]
Name: "mycomponent"; Description: "Component description"; Types: full

[Code]
...
var
  ItemIndex: Integer;
begin
  ItemIndex := WizardForm.ComponentsList.Items.IndexOf('Component description');
  ...
end;

我通过向导SelectedComponents找到了一种方法

在var中定义此字符串数组以保存组件名称:

ComponentsName: array of String;
定义此功能和此过程:

Function StringToArray(const Text: String; const Cut: String): array of String;
var
    i: Integer;
    k: Integer;
Begin
    SetArrayLength(Result, 0);
    if Cut = '' then Cut:= #1310;
    Repeat
        k:= Pos(Cut,Text);
        if k = 1 then
        begin
            Delete(Text, 1, Length(Cut));
            CONTINUE
        end;
        SetArrayLength(Result, GetArrayLength(Result) +1); i:= GetArrayLength(Result) -1;
        if k = 0 then
            Result[i]:=Text
        else begin
            Result[i]:= Copy(Text, 1, k -1); Delete(Text, 1, Length(Result[i]) + Length(Cut));
        end;
    Until Length(Text) * k = 0;
End;

procedure InitializeComponentsName();
var
    I: Integer;
    CheckBack: array of boolean;
begin
    SetArrayLength(CheckBack, WizardForm.ComponentsList.ItemCount);

    for I:=0 to WizardForm.ComponentsList.ItemCount-1 do
    begin
        //Saves state in CheckBack.
        CheckBack[I]:=WizardForm.ComponentsList.Checked[I];
        //Only checks non checked components.
        if not CheckBack[I] then WizardForm.ComponentsList.Checked[I]:=true;
    end;

    //Saves components names in ComponentsName array
    ComponentsName:=StringToArray(WizardSelectedComponents(false), ',');

    //Unchecks components that was uncheck previouly.
    //If we try to check a checked component it may crash the Inno program (tested)
    for I:=0 to WizardForm.ComponentsList.ItemCount-1 do
    begin
        if not CheckBack[I] then WizardForm.ComponentsList.Checked[I]:=false;
    end;

    //LOG components name.
    log('COMPONENTS NAME:');
    for I:=0 to GetArrayLength(ComponentsName) -1 do
    begin
        log(ComponentsName[I]);
    end;

end;
必须在InitializeWizard上调用此过程。 现在我们有了ComponentName数组中的所有组件名称。 您可以使用getComponentName获取组件名称:

//Returns component name by Index.
function getComponentName(Index: Integer): String;
begin
    if ((Index>=0) and (Index<GetArrayLength(ComponentsName))) then Result:=ComponentsName[Index];
end;

如果将另一个组件添加到ComponentList,则必须调用InitializeComponentName以更新ComponentList数组。

。组件名称在内部存储在中,无法从外部访问,因此,您运气不好。因此,根本没有办法让我的组件索引更简单吗Dif我有类似的描述:“{cm:coremod}”;如何访问它?
WizardForm.ComponentsList.Items.IndexOf(ExpandConstant({cm:coremod}))
为您提供该项目的索引。不客气!仅供参考,包含
Name
成员的
TSetupComponentEntry
记录实际上是通过
ComponentsList.ItemObject[i]
发布的。问题是,由于脚本语言中缺少指针支持,我从未找到访问它的方法。@TLama,伙计,如果我有类似
en.test=这是一个测试描述,我知道它的索引,如何从
en.test
自定义消息中获取
test
?您的意思是如何通过给定的索引获取项目的标题?如果是这样,那么您可以使用
S:=WizardForm.ComponentsList.ItemCaption[Index]。或者,如果您询问如何扩展所选语言的自定义消息,则可以使用
S:=CustomMessage('test')
,或展开
{cm:test}
常量。但是,如果你问如何为未选择的语言扩展自定义消息,那么我不确定答案,必须更深入地检查是否可能(并将在一个新问题中回答你)。@Tlama,我不需要该描述的文本。。我只需要自定义消息名(例如:en.comp_name=一些英文描述,自定义消息名为comp_name)这是我创建的过程:这是输出:。。。但我只需要它们的CustomMessage名称,而不需要完整的描述:DCustom消息(通常)在启动时展开。消息的名称扩展到其值后,没有人关心它的名称。因此,无法从字符串值获取消息名称。Inno安装程序不提供所有自定义消息的列表,您可以在其中找到这些信息,除非您编写一些预处理器脚本来构建这样的列表,否则您运气不好。您能帮我吗?我完全不知道如何编写预处理器脚本:(我的意思是我知道它与#ifdefine etc:D一起使用,但我只知道它与单选按钮还不起作用。我需要修改代码。谢谢,特拉玛,但当只有一种方法时,这种方法才是最好的。令人遗憾的是Inno没有为组件名称提供getter方法。您的解决方案太棒了!非常感谢。回答很好,效果很好。谢谢ht需要使用
WizardForm.ComponentsList.Items.Count更改
WizardForm.ComponentsList.Items.Count
//Returns index component by Name. -1 if it doesn't exist.
function GetIndexComponent(ComponentName: String): Integer;
var
    J: Integer;
begin
    Result:= -1;
    for J:=0 to GetArrayLength(ComponentsName)-1 do
    begin
        if (ComponentName=ComponentsName[J]) then
        begin
            Result:=J;
            break;
        end;
    end;
end;