如何在const中定义数组? [英] How to define an array in const?

查看:981
本文介绍了如何在const中定义数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Inno Setup的代码部分下的const中定义字符串数组时遇到一些问题,我有以下问题:

I'm having some problems defining an array of strings in const under the code section in Inno Setup, I have the following:

[Code]

const
  listvar: array [0..4] of string =
     ('one', 'two', 'three', 'four', 'five');

这是说我需要=所在的=,但是我不能将其定义为数组.

It's saying I need an = where the : is, but then I can't define it as an array.

推荐答案

我不久前做了一个实用程序功能.它不允许您在常量上分配数组,但是可以在一个衬里中完成变量的操作.希望获得帮助.

I made a little utility function a little while ago. It won't allow you to assign an array on a constant but it could do the trick for a variable in a one liner. Hoping this help.

您可以通过以下方式使用它:

You can use it this way:

listvar := Split('one,two,three,four,five', ',');

{ ============================================================================ }
{ Split()                                                                      }
{ ---------------------------------------------------------------------------- }
{ Split a string into an array using passed delimeter.                         }
{ ============================================================================ }
Function Split(Expression: String; Separator: String): TArrayOfString;
Var
    i, p : Integer;
    tmpArray : TArrayOfString;
    curString : String;

Begin
    i := 0;
    curString := Expression;

    Repeat
        SetArrayLength(tmpArray, i+1);
        If Pos(Separator,curString) > 0 Then
        Begin
            p := Pos(Separator, curString);
            tmpArray[i] := Copy(curString, 1, p - 1);
            curString := Copy(curString, p + Length(Separator), Length(curString));
            i := i + 1;
        End Else Begin
             tmpArray[i] := curString;
             curString := '';
        End;
    Until Length(curString)=0;

    Result:= tmpArray;
End;

这篇关于如何在const中定义数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆