我无法将函数结果返回给过程

时间:2014-03-26 18:10:55

标签: function pointers return pascal

我的计划有什么问题。我无法从函数“PointerRecord”返回指针并在程序“Show”中使用他?。

type
  p = ^element;
  element = record
         age:integer;
         name:string;
 end;
var
  adr:p;
  result:p;
  w:integer;
  i:string;

end;
function RecordPointer(var w:integer;var i:string):p;
var
  person:p;
begin
  new(person);
  person^.age :=w;
  person^.name :=i;
  adr:=person;
  RecordPointer := adr;
end;
procedure show(result:p);
var
 w:integer;
 i:string;
begin
 w:=result^.age;
 i:=result^.name;
 writeln(w);
 writeln(i);
 readln;
end;

有人可以向我解释一下吗?

1 个答案:

答案 0 :(得分:0)

尝试更像这样的东西:

type
  p = ^element;
  element = record
         age:integer;
         name:string;
  end;

function RecordPointer(w: integer; i: string): p;
var
  person: p;
begin
  New(person);
  person^.age := w;
  person^.name := i;
  RecordPointer := person;
end;

procedure show(person: p);
begin
 writeln(person^.age);
 writeln(person^.name);
 readln;
end;

var
  person: p;
begin
  person := RecordPointer (24, 'Johnny');
  show(person);
  Dispose(person);
end;