procedure ShowForm(var Pperson: PpersonRec); 
procedure ShowForm( const Pperson: PpersonRec);
procedure ShowForm(  Pperson: PpersonRec); 
这三种写法传值有何区别?那种好!欢迎大家讨论!

解决方案 »

  1.   

    第一种返回Pperson值
    第二种和第三种貌似没什么区别
      

  2.   

    PpersonRec是个指针吗?如果是指针的话
    第二种,Pperson^是可以修改的,但Pperson本身所指的对象不能修改,所以第二种更安全
      

  3.   

    第一种,Pperson在函数返回的时候,把在Showform里改变的值能够传递回来。
    第二种,在ShowForm函数里不允许改变Pperson的值。
    第三种,在ShowForm函数里允许改变Pperson的值,但是不能把改变的值传递回来。
      

  4.   

    to gzmhero :
    第二种,在ShowForm函数里不允许改变Pperson的值。  -------值是可以改变的,但是地址是不能改的
    第三种,在ShowForm函数里允许改变Pperson的值,但是不能把改变的值传递回来。-------值是可以传回来的
    你可以做的例子试试!
    我认为在传值的时候,他们三个都是可以把值传回来的!大家可以试试!
      

  5.   


    你一开始没说明Pperson是指针,所以大家误解了Pperson是integer型的话你再试试就知道了
      

  6.   


    如果是指针,那么Pperson的值在这里就应该解释成指针本身的地址,而不是Pperson^,不要单看字面的意思,理解了区别才是目的。
      

  7.   

    引用类型是否用var是没区别的
      

  8.   

    指针还是看你使用的方法,有些时候用Var还是有区别的。  a:integer;procedure sf(var P: PInteger);
    begin
        a:=3;
        p:=@a;
    end;procedure sf2(P: PInteger);
    begin
        a:=3;
        p:=@a;
    end;procedure sf3(const P: PInteger);
    begin
        a:=3;
        p:=@a;//这里编译无法通过,const,不能改变指针的地址
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
        i:integer;
        p:Pinteger;
    begin
        i:=1;
        new(p);
        p^:=2;
        sf(p);//用了Var,指针的地址改变了,变成了指向a的整数指针,值是3
        Label1.Caption:=IntToStr(p^);    new(p);
        p^:=2;
        sf2(p);//没用Var,指针的地址不变,值还是2
        Label2.Caption:=IntToStr(p^);
    end;
      

  9.   


    PpersonRec 这是指针
    在指针命名的时候一般是前边加p的例如:Pperson;我以为大家都明白这一点!
    我在把记录的声明写出来:
    type
      PpersonRec=^TpersonRec
      TpersonRec=record
      Name:string;
      Sex:string;
      Age:string;
    end;procedure ShowForm(var Pperson: PpersonRec);  
    procedure ShowForm( const Pperson: PpersonRec); 
    procedure ShowForm(  Pperson: PpersonRec);  
    这三种写法传值有何区别?to hsmserver :
      引用类型是否用var是没区别的 ------能举个例子说明一下吗?
      

  10.   


    你可以理解为用var传递的就是参数的指针
    procedure funca(aa:integer)
    begin
    aa:=10;
    end;procedure funcb(var aa:integer)
    begin
    aa:=10;
    end;procedure func()
    var
       aa:integer;
    begin
    aa:=1;
    funca(aa);
    showmessage(inttostr(aa));   //这里showmessage出来的是1
    funcb(aa);
    showmessage(inttostr(aa));   //这里showmessage出来的是10
    end;由于引用类型(指针,类)本身就是个指针,所以就算用var修饰,编译器也会一样处理.所以你给的3种情况,在ShowForm中都可以修改Pperson^,第一,三种可以修改Pperson,第二种不能修改Pperson