unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls;type
  PPerson = ^TPerson;
  TPerson = record
    Code:string;
    Name:string;
    Sex:string;
    Age:String;
    Addr:String;
    end;  TForm1 = class(TForm)
    TreeView1: TTreeView;
    Splitter1: TSplitter;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    procedure FormShow(Sender: TObject);
    procedure TreeView1Click(Sender: TObject);
  private
    { Private declarations }
    procedure CreatePerson;
    procedure GetData;
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.CreatePerson;
var
  P1,P2,P3,P4:PPerson;  Node:TTreeNode;
begin
  New(p1);
  New(P2);
  New(P3);
  New(P4);  P1.Code := 'P01';
  P1.Name := '张三';
  P1.Sex := '男';
  P1.Age := '26';
  P1.Addr := '吉林市';  P2.Code := 'P02';
  P2.Name := '李四';
  P2.Sex := '男';
  P2.Age := '28';
  P2.Addr := '长春市';  P3.Code := 'P03';
  P3.Name := '王五';
  P3.Sex := '男';
  P3.Age := '20';
  P3.Addr := '吉林市';  P4.Code := 'P04';
  P4.Name := '赵六';
  P4.Sex := '男';
  P4.Age := '26';
  P4.Addr := '上海市';
  Node := TreeView1.Items.AddChild(nil,P1.Name);
  Node.Data := P1;  Node := TreeView1.Items.AddChild(nil,P2.Name);
  Node.Data := P2;  Node := TreeView1.Items.AddChild(nil,P3.Name);
  Node.Data := P3;  Node := TreeView1.Items.AddChild(nil,P4.Name);
  Node.Data := P4;end;procedure TForm1.FormShow(Sender: TObject);
begin
  CreatePerson;
end;procedure TForm1.GetData;
var
  P:PPerson;
  Node:TTreeNode;
begin
  Node := TreeView1.Selected;
  P := PPerson(Node.Data);
  Edit1.Text := p.Code;
  Edit2.Text := p.Name;
  Edit3.Text := p.Sex;
  Edit4.Text := p.Age;
  Edit5.Text := p.Addr;
end;procedure TForm1.TreeView1Click(Sender: TObject);
begin
  if Assigned(TreeView1.Selected) then
    GetData;
end;end.
请问这段代码中 P := PPerson(Node.Data);的pperson是个什么意思它不是个指针吗,指针还有这样的用法是将地址指到NOde.data吗,data这个属性有什么用啊.

解决方案 »

  1.   

    type 
      PPerson = ^TPerson; 
      TPerson = record 
    记录,不是指针
      

  2.   

    TPerson = Record
    说明TPerson是一个记录体,他里面记录了人的相关信息,是一个值类型
    PPerson = ^TPerson;
    说明PPerson是一个指针,他指向上面的那个记录体,是一个引用类型
      

  3.   

    PPerson是个结构体指针
    P是结构体对象指针
    P := PPerson(Node.Data)对象实例化,将Node.data强制转化为结构体数据,并将P指向此结构体数据(个人理解)
      

  4.   

    Node.Data就是用来存放指针的
    PPerson(Node.Data)是把无类型的指针转换为指向Person结构体的指针
      

  5.   

    这就是指针的精髓所在。delphi开发人员对指针和数据的理解可以说是所有语言中最彪悍的。