调用函数时出现不兼容的类型错误

时间:2018-11-04 23:42:27

标签: arrays pascal delphi-2007 delphi

我有两个函数是动态数组。一个是用于拆分字符串的函数,另一个是正在调用该函数的位置。我在这行代码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

是双精度数组,而SplitString(line)是字符串的数组。我曾尝试将字符串转换为浮点数,但错误因过载而持续存在。不太确定此时该怎么办。任何人都可以帮助我做错什么。谢谢

0 个答案:

没有答案