1
我已這應該分割一個字符串轉換爲字符串數組(我使用Geany IDE和FPC編譯器)下面的函數:類型標識符預期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
據我所看到的語法是正確的,這裏有什麼問題?
編譯器告訴你,你不能返回一個無類型的動態數組。申報f.i. 'type TStringArray = string of array;'你可以從函數返回'TStringArray'。 –
啊thx,發佈這個答案,我會接受它。 Pascal看起來很奇怪,經過多年的java>< – Droidman
完成,歡迎您。但請注意你的問題一段時間,因爲我不確定這種行爲是否取決於某種「模式」。如果是,有人可能會提供一個擴展答案。 –