繁体   English   中英

Pascal分段故障解析文本文件

[英]Pascal Segmentation Fault parsing Text File

我正在Pascal / Lazarus中使用Question / Answer UI应用程序。 我的问题是,通过单击按钮调用以下代码后,程序崩溃并出现Segmentation Fault错误。

// more declarations... (UI Form, Buttons, ...)

type
  TQuestion = class(TObject)
    title: string;
    answers: array of string;
    correct: integer;
  end;

var
  questions: array of TQuestion;

procedure TForm1.BStartClick(Sender: TObject);
var
  i: integer;
  j: integer;
  line: string;
  arrayLength: integer;
  question: TQuestion;
  stringList: TStringList;
begin
  stringList := TStringList.create;
  stringList.LoadFromFile('questions.txt');

  for i := 0 to stringList.Count - 1 do ;
  begin
    line := stringList[i];
    if (length(line) >= 2) then
      if (line[2] = ' ') and ((line[1] = '-') or (line[1] = '+')) then
      begin
        arrayLength := length(question.answers);
        SetLength(question.answers, arrayLength + 1);
        question.answers[arrayLength] :=
          Copy(line, 2, Length(line) - 1);

        if zeile[1] = '+' then
          question.correct := arrayLength;
      end
      else
      begin
        question := TQuestion.Create;
        question.title := line;

        arrayLength := length(questions);
        setLength(questions, arrayLength + 1);
        questions[arrayLength] := question;
      end;
  end;
  BStart.Visible := False;
end;

好吧,我的Pascal知识可以追溯到10至15年前。 但是,我可以看到在此行的末尾有一个多余的分号:

for i := 0 to stringList.Count - 1 do ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM