警告:托管类型的函数结果变量似乎未初始化

问题描述 投票:-3回答:1

我的任务要求我创建两个例程,其中一个从终端读取数据,另一个向终端输出数据,另外两个例程利用数组循环这两个例程来多次执行它们。

我遇到的问题是终端在一次运行ReadComputer函数后崩溃而不是循环多次。编译器还向我提供以下警告:

“警告:托管类型的函数结果变量似乎未初始化”

虽然经过广泛的研究,并且由于没有人使用pascal我无法找到解决方案。任何帮助深表感谢! :)

我在这里提供了我的代码副本供参考:

program CompupterProgram;
uses TerminalUserInput;
type 
    Computer = Record
        id: integer;
        manafacturer: String;
        year: integer;
        warranty: integer;
    end;

type Computers = Array of Computer;

function ReadComputer(): Computer;
begin
    ReadComputer.id := ReadInteger('PLease Enter Computer Id:');
    ReadComputer.manafacturer := ReadString('PLease Enter Computer Manafacturer:');
    ReadComputer.year := ReadInteger('PLease Enter Computer Year:');
    ReadComputer.warranty := ReadInteger('PLease Enter Computer Warranty:');
    result := ReadComputer;
end;

procedure WriteComputer(c: Computer);
begin
    WriteLn('Computer ID: ', c.id);
    WriteLn('Computer Manafacturer ', c.manafacturer);
    WriteLn('Computer Year ', c.year);
    WriteLn('Computer Warranty ', c.warranty);
    ReadLn();
end;

function ReadAllComputers(count: Integer): Computers;
var i: Integer;
begin
    for i := 0 to count do
    begin
        ReadAllComputers[i] := ReadComputer();
    end;
result := ReadAllComputers;
end;

procedure WriteAllComputers(computerArray: Computers);
var i: Integer;
begin
    for i:= 0 to (length(computerArray)) do
    begin
        WriteComputer(computerArray[i]);
    end;
end;

procedure Main();
var computers: Array of Computer;
    index: Integer;
begin
    computers := ReadAllComputers(3);
    WriteAllComputers(computers);
end;

begin
Main();
end.
arrays record pascal freepascal
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.