我有以下函数,它应该将字符串拆分为字符串数组(我使用的是 Geany IDE 和 fpc 编译器):
function Split(const str: string; const separator: string): array of string;
var
i, n: integer;
strline, strfield: string;
begin
n:= Occurs(str, separator);
SetLength(Result, n + 1);
i := 0;
strline:= str;
repeat
if Pos(separator, strline) > 0 then
begin
strfield:= Copy(strline, 1, Pos(separator, strline) - 1);
strline:= Copy(strline, Pos(separator, strline) + 1,
Length(strline) - pos(separator,strline));
end
else
begin
strfield:= strline;
strline:= '';
end;
Result[i]:= strfield;
Inc(i);
until strline= '';
if Result[High(Result)] = '' then SetLength(Result, Length(Result) -1);
end;
编译器报错:
calc.pas(24,61) Error: Type identifier expected
calc.pas(24,61) Fatal: Syntax error, ";" expected but "ARRAY" found
据我所见语法是正确的,这里有什么问题?