У меня есть две функции, которые являются динамическими массивами. одна - это функция, используемая для разделения строк, а вторая - где вызывается функция. Я получаю сообщение об ошибке в этой строке кода tempArr := SplitString(line);
Ниже указан мой точный код:
type
TArrayStr = array Of string;
function SplitString(stringToSplit: string): TArrayStr;
var
intIdx: Integer;
intIdxOutput: Integer;
const
Delimiter = ';'; // made the delimeter a constant
begin
//set the length of the single dimension array
intIdxOutput := 0;
SetLength(Result, 1);
Result[0] := '';
//furnish this array
for intIdx := 1 to Length(stringTosplit) do
begin
if stringTosplit[intIdx] = Delimiter then
begin
intIdxOutput := intIdxOutput + 1;
SetLength(Result, Length(Result)); // set the length of the dynamic array
end
else
Result[intIdxOutput] := Result[intIdxOutput] + stringTosplit[intIdx];
end;
end;
type
TDoubleDynArray = array of double;
function ReadColumn(filename: string; colNumber: integer):TDoubleDynArray;
var
myFile: TextFile;
line: String;
tempArr: array of double;
colValue: double;
colArray: array of double;
i: integer;
j: integer;
edtcolumnNo: Tedit;
// colNumber: int;
begin
// Open the text file for reading
AssignFile(myFile, filename);
Reset(myfile);
// Skip the header lines
while not Eof(myFile) do
begin
ReadLn(myFile, line);
if AnsiStartsStr('chapters', line) then Break;
end;
// Read each line, but keep only the desired column
j := 0;
while not Eof(myFile) do
begin
ReadLn(myFile, line);
tempArr := SplitString(line); // this is the problem
// go through array
colNumber := strToint(edtcolumnNo.text);
colValue := tempArr[colNumber];
colArray[j] := colValue;
j := j + 1;
end;
close(myFile);
result := colArray;
end;
для строки tempArr
- это массив значений типа double, а SplitString(line)
- это массив строк. Я пытался преобразовать строку в плавающее, но ошибка сохранилась с перегрузкой. не слишком уверен, что делать на этом этапе. Может ли кто-нибудь помочь, пожалуйста, относительно того, что я могу делать неправильно. Спасибо