为什么此记录结构正在编译但出现运行时错误

恩索

我正在尝试使用简单的字符串和整数记录的以下代码:

program Progrecords; 

Type  
    Progrec = Record  
        pname : string;  
        pnum : integer; 
        end;  

var 
    Progs : Array of Progrec; 
    aprog, pp: Progrec; 

begin 
    aprog.pname := 'abc';
    aprog.pnum := 4; 
    Progs[0] := aprog;

    aprog.pname := 'def';
    aprog.pnum := 6; 
    Progs[1] := aprog;

    for pp in Progs do begin
        writeln('Name: ',pp.pname, '; Num: ', pp.pnum); 
    end;
end. 

它可以编译,但会给出运行时错误:

$ fpc rnrecords.pas && ./rnrecords
Free Pascal Compiler version 3.0.0+dfsg-11+deb9u1 [2017/06/10] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling rnrecords.pas
rnrecords.pas(17,2) Warning: Variable "Progs" of a managed type does not seem to be initialized
Linking rnrecords
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
27 lines compiled, 0.1 sec
1 warning(s) issued

Runtime error 216 at $0000000000400226
  $0000000000400226
  $000000000040018C

我正在使用fpc版本3.0.0的Debian Stable Linux

问题在哪里,如何解决?谢谢你的帮助。

鲁道德

Progs 是动态数组,必须在使用前分配。

例如:

SetLength(Progs,2);  // Allocates two records

请参阅动态数组

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么Typescript类中的这种结构在编译时会很好地导致运行时错误?

为什么此代码编译并在执行时给出运行时错误

为什么在Codechef中提交此代码时出现运行时错误(SIGABRT)?

为什么在联机提交此代码时出现运行时错误?(jdk 1.7)

为什么在运行时出现Typescript编译错误?

为什么该程序在运行时出现错误

为什么io.WriterString出现运行时错误?

为什么会出现运行时错误?

为什么会出现访问冲突运行时错误?

为什么我的代码出现运行时错误?

为什么在IntelliJ中运行Scala 2.13测试而不是在Scala 2.12中运行时出现此错误?

为什么 `constexpr` 函数在编译和运行时会产生不同的结果?

为什么在编译时无法解决运行时多态性?

为什么在编写编译器时需要运行时库?

为什么BufferedReader类在编译时而不是在运行时产生异常

谁能帮助我了解为什么我的leetcode问题出现此运行时错误?最长前缀

为什么此代码使用UndecidableInstances进行编译,然后生成运行时无限循环?

在编译时和/或运行时检测正在运行的Linux发行版?

为什么在运行时而不是在编译时评估使用constexpr初始化变量

为什么某些类型的Set缺少运行时错误而不是编译错误?

为什么在运行简单的docker映像时出现oci运行时错误?

为什么此C程序在运行时引发分段错误?

为什么此函数应用程序会在purescript中生成运行时错误?

为什么此代码打印第n个数字会给出运行时错误?

为什么此错误仅在Clojure REPL的运行时显示?

为什么此C ++程序未产生运行时错误

为什么此代码在 URI Online Judge 中给出“运行时错误”

编译Java运行时库时出现Protobuf错误

为什么正确编译C ++类构造函数后发生运行时错误