Procedure Time.TimeDB(algorithm: string; Encode, Decode: InputFunction; N, R: Int);
VAR
i : LongInt;
Errors : Array[N] of LongInt;
BEGIN
for i := 0 to N-1 do
Errors[i] := 0;
END;
我得到一个错误,即传递给错误定义的 N 是一个未声明的标识符,尽管它已在过程定义中声明。但是,N 在 BEGIN-END 部分中被识别。知道是什么原因造成的吗?我如何才能在 VAR 部分声明一个可变长度数组?
procedure Time.TimeDB(algorithm: string; Encode, Decode: InputFunction; N, R: Int);
var
i: int;
errors: array of Int;
begin
SetLength(errors, N);
for i := 0 to N - 1 do
Errors[i] := 0;
end;
另请注意,如果数组有 N 个元素,则它们的索引为 0、1、...、N - 1。没有索引为 N 的元素。
(另外,你确定你写的 Int 不是指 integer 吗?)
构造 array[M..N] of Int 称为 static array .在这种情况下,M 和 N 必须是常量,例如 array[0..15] of TColor。您还获得了静态数组声明 array[TMyType] of TMySecondType,其中索引的类型为 TMyType,如 array[byte] of TColor > 或 array[TFontStyle] of cardinal。